Skip to content

Commit b752772

Browse files
committed
PHP 8 compatibility.
1 parent 3651d52 commit b752772

File tree

9 files changed

+15
-26
lines changed

9 files changed

+15
-26
lines changed

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.4",
20+
"php": "^8.0",
2121
"nette/utils": "^3.0",
2222
"nette/tokenizer": "^3.0",
2323
"mathematicator-core/numbers": "^2.1"
2424
},
2525
"require-dev": {
26+
"phpstan/phpstan": "^0.12.74",
27+
"tracy/tracy": "^2.8",
28+
"phpstan/phpstan-nette": "^0.12.14",
29+
"spaze/phpstan-disallowed-calls": "^1.1",
30+
"roave/security-advisories": "dev-master",
31+
"jetbrains/phpstorm-attributes": "^1.0",
2632
"brainmaestro/composer-git-hooks": "dev-master",
2733
"nette/bootstrap": "^3.0.1",
28-
"nette/tester": "^2.0",
29-
"phpstan/phpstan": "^0.12.74",
30-
"phpstan/phpstan-nette": "^0.12.14"
34+
"nette/tester": "^2.0"
3135
},
3236
"suggest": {
3337
"nette/di": "(^3.0) To use package in Nette Framework"

src/Exceptions/TokenizerException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
class TokenizerException extends InvalidArgumentException
1212
{
1313
/**
14-
* @param mixed $token
1514
* @throws TokenizerException
1615
*/
17-
public static function tokenMustBeIToken($token): void
16+
public static function tokenMustBeIToken(mixed $token): void
1817
{
1918
throw new self(
2019
'Token must be instance of "' . IToken::class . '", but type "'
21-
. (is_object($token) ? get_class($token) : json_encode($token)) . '" given.',
20+
. (is_object($token) ? get_class($token) : json_encode($token, JSON_THROW_ON_ERROR)) . '" given.',
2221
);
2322
}
2423
}

src/Token/BaseToken.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@
55
namespace Mathematicator\Tokenizer\Token;
66

77

8-
use Nette\SmartObject;
9-
10-
/**
11-
* @property string $token
12-
* @property int $position
13-
* @property string $type
14-
*/
158
abstract class BaseToken implements IToken
169
{
17-
use SmartObject;
18-
1910
private string $token;
2011

2112
private int $position;

src/Token/MatrixToken.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ public function setMatrix(array $matrix): void
5353
private function validator(array $matrix): array
5454
{
5555
$lastCols = null;
56-
5756
foreach ($matrix as $row) {
5857
$cols = count($row);
59-
6058
if ($lastCols === null) {
6159
$lastCols = $cols;
6260
} elseif ($cols !== $lastCols) {

src/Token/PolynomialToken.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public function __construct(NumberToken $times, ?NumberToken $power, VariableTok
3333
$power->setType(Tokens::M_NUMBER)
3434
->setToken('1')
3535
->setPosition($times->getPosition() + 1);
36+
$this->power = $power;
37+
} else {
38+
$this->power = $power;
3639
}
3740

3841
$this->times = $times;
39-
$this->power = $power; // in integer formar
4042
$this->variable = $variable;
4143

4244
$this->setToken(

src/Tokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ final class Tokens
4949
/** @throws Error */
5050
public function __construct()
5151
{
52-
throw new Error('Class ' . static::class . ' is static and cannot be instantiated.');
52+
throw new Error('Class ' . self::class . ' is static and cannot be instantiated.');
5353
}
5454
}

src/TokensToLatex.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function __construct(FunctionManagerFacade $functionManager)
7575

7676
/**
7777
* @param IToken[] $tokens
78-
* @return string
7978
* @throws TokenizerException
8079
*/
8180
public function render(array $tokens): string
@@ -86,8 +85,6 @@ public function render(array $tokens): string
8685

8786
/**
8887
* @param IToken[] $tokens
89-
* @param int $level
90-
* @return string
9188
* @throws TokenizerException
9289
*/
9390
private function iterator(array $tokens, int $level = 0): string
@@ -249,7 +246,6 @@ private function renderPow(TokenIterator $iterator, int $level): MathLatexBuilde
249246
* Fix generated haystack by smart regular patterns.
250247
*
251248
* @param string[] $replaceTable
252-
* @return string
253249
*/
254250
private function processReplaceTable(string $haystack, array $replaceTable): string
255251
{

src/TokensToObject.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ final class TokensToObject
3333
public function toObject(array $tokens): array
3434
{
3535
$objects = [];
36-
3736
for ($iterator = 0; isset($tokens[$iterator]); $iterator++) {
3837
$token = $tokens[$iterator];
3938
switch ($token->type) {

src/TokensTreeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class TokensTreeRenderer
1414
/** @throws Error */
1515
public function __construct()
1616
{
17-
throw new Error('Class ' . static::class . ' is static and cannot be instantiated.');
17+
throw new Error('Class ' . self::class . ' is static and cannot be instantiated.');
1818
}
1919

2020

0 commit comments

Comments
 (0)