Skip to content

Commit d6c4b66

Browse files
committed
Fix deprecated model namespaces + code style
1 parent 434cf9c commit d6c4b66

File tree

10 files changed

+48
-34
lines changed

10 files changed

+48
-34
lines changed

config.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ services:
22
- Mathematicator\Engine\Engine
33
- Mathematicator\Engine\QueryNormalizer
44
- Mathematicator\Engine\Translator
5-
- Model\Math\NumberRewriter
5+
- Mathematicator\NumberRewriter
6+
- Mathematicator\NaturalTextFormatter
67

78
orm.annotations:
89
paths:

src/Entity/EngineMultiResult.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mathematicator\Engine;
46

57

@@ -27,7 +29,7 @@ public function getResults(): array
2729
public function getResult(string $name = null): EngineResult
2830
{
2931
if (!isset($this->results[$name])) {
30-
throw new NoResultsException('Result "' . $name . '" does not exists.');
32+
throw new NoResultsException('Result "' . $name . '" does not exist.');
3133
}
3234

3335
return $this->results[$name];

src/Entity/EngineSingleResult.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mathematicator\Engine;
46

57

@@ -21,7 +23,7 @@ class EngineSingleResult extends EngineResult
2123
/**
2224
* @var Source[]
2325
*/
24-
private $sources = [];
26+
private $sources;
2527

2628
/**
2729
* @param string $query

src/Exception/DivisionByZero.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Mathematicator\Engine;
46

57

@@ -12,15 +14,13 @@ class DivisionByZero extends MathErrorException
1214
private $fraction;
1315

1416
/**
15-
* DivisionByZero constructor.
16-
*
1717
* @param string $message
1818
* @param int $code
19-
* @param null $previous
20-
* @param string[] $fraction
21-
* @throws \Exception
19+
* @param \Exception|null $previous
20+
* @param array $fraction
21+
* @throws MathematicatorException
2222
*/
23-
public function __construct($message, $code = 0, $previous = null, array $fraction)
23+
public function __construct(string $message, int $code = 0, \Exception $previous = null, array $fraction = [])
2424
{
2525
parent::__construct($message, $code, $previous);
2626

src/Formatter/FixSpaces.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
namespace Model\Math;
3+
declare(strict_types=1);
4+
5+
namespace Mathematicator;
6+
47

58
class FixSpaces
69
{

src/Formatter/NaturalTextFormatter.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
<?php
22

3-
namespace Model\Math;
3+
declare(strict_types=1);
4+
5+
namespace Mathematicator;
6+
47

58
use Mathematicator\Engine\QueryNormalizer;
9+
use Mathematicator\Search\TextRenderer;
610
use Mathematicator\Tokenizer\Tokenizer;
711
use Nette\Utils\Strings;
8-
use Texy\Texy;
912

1013
class NaturalTextFormatter
1114
{
1215

1316
/**
14-
* @var Texy
17+
* @var string[]
1518
*/
16-
private $texy;
19+
private static $allowedFunctions = [
20+
'sin',
21+
'cos',
22+
'tan',
23+
'cotan',
24+
'tg',
25+
'log\d*',
26+
'sqrt',
27+
];
1728

1829
/**
1930
* @var QueryNormalizer
@@ -26,21 +37,11 @@ class NaturalTextFormatter
2637
private $tokenizer;
2738

2839
/**
29-
* @var string[]
40+
* @param QueryNormalizer $queryNormalizer
41+
* @param Tokenizer $tokenizer
3042
*/
31-
private $allowedFunctions = [
32-
'sin',
33-
'cos',
34-
'tan',
35-
'cotan',
36-
'tg',
37-
'log\d*',
38-
'sqrt',
39-
];
40-
41-
public function __construct(Texy $texy, QueryNormalizer $queryNormalizer, Tokenizer $tokenizer)
43+
public function __construct(QueryNormalizer $queryNormalizer, Tokenizer $tokenizer)
4244
{
43-
$this->texy = $texy;
4445
$this->queryNormalizer = $queryNormalizer;
4546
$this->tokenizer = $tokenizer;
4647
}
@@ -63,7 +64,7 @@ public function formatNaturalText(string $text): string
6364

6465
$return .= '<div class="latex"><p>\(' . $latex . '\)</p><code>' . $line . '</code></div>';
6566
} else {
66-
$return .= $this->texy->process($line) . "\n\n";
67+
$return .= TextRenderer::process($line) . "\n\n";
6768
}
6869
}
6970
}
@@ -79,10 +80,10 @@ private function containsWords(string $text): bool
7980
{
8081
$words = 0;
8182

82-
$text = preg_replace('/\s+/', ' ', Strings::toAscii(Strings::lower($text)));
83+
$text = (string) preg_replace('/\s+/', ' ', Strings::toAscii(Strings::lower($text)));
8384

8485
while (true) {
85-
$newText = preg_replace('/([a-z0-9]{2,})\s+([a-z0-9]{1,})(\s+|[:.!?,]|$)/', '$1$2', $text);
86+
$newText = (string) preg_replace('/([a-z0-9]{2,})\s+([a-z0-9]{1,})(\s+|[:.!?,]|$)/', '$1$2', $text);
8687
if ($newText === $text) {
8788
break;
8889
}
@@ -110,7 +111,7 @@ private function containsWords(string $text): bool
110111
*/
111112
private function wordInAllowedFunctions(string $word): bool
112113
{
113-
foreach ($this->allowedFunctions as $allowedFunction) {
114+
foreach (self::$allowedFunctions as $allowedFunction) {
114115
if (preg_match('/^' . $allowedFunction . '$/', $word)) {
115116
return true;
116117
}

src/NumberRewriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Model\Math;
5+
namespace Mathematicator;
66

77

88
use Mathematicator\Engine\MathematicatorException;

src/QueryNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Mathematicator\Engine;
66

77

8-
use Model\Math\NumberRewriter;
8+
use Mathematicator\NumberRewriter;
99
use Nette\Utils\Strings;
1010

1111
class QueryNormalizer

src/Translator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
class Translator implements ITranslator
1111
{
1212

13+
/**
14+
* @param mixed $message
15+
* @param mixed[] $parameters
16+
* @return string
17+
*/
1318
public function translate($message, ...$parameters): string
1419
{
1520
return (string) $message;

tests/QueryNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
use Mathematicator\Engine\QueryNormalizer;
9-
use Model\Math\NumberRewriter;
9+
use Mathematicator\NumberRewriter;
1010
use Tester\Assert;
1111
use Tester\TestCase;
1212

0 commit comments

Comments
 (0)