Skip to content

Commit

Permalink
PHP 8 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Feb 10, 2021
1 parent 3651d52 commit b752772
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 26 deletions.
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
}
],
"require": {
"php": ">=7.4",
"php": "^8.0",
"nette/utils": "^3.0",
"nette/tokenizer": "^3.0",
"mathematicator-core/numbers": "^2.1"
},
"require-dev": {
"phpstan/phpstan": "^0.12.74",
"tracy/tracy": "^2.8",
"phpstan/phpstan-nette": "^0.12.14",
"spaze/phpstan-disallowed-calls": "^1.1",
"roave/security-advisories": "dev-master",
"jetbrains/phpstorm-attributes": "^1.0",
"brainmaestro/composer-git-hooks": "dev-master",
"nette/bootstrap": "^3.0.1",
"nette/tester": "^2.0",
"phpstan/phpstan": "^0.12.74",
"phpstan/phpstan-nette": "^0.12.14"
"nette/tester": "^2.0"
},
"suggest": {
"nette/di": "(^3.0) To use package in Nette Framework"
Expand Down
5 changes: 2 additions & 3 deletions src/Exceptions/TokenizerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
class TokenizerException extends InvalidArgumentException
{
/**
* @param mixed $token
* @throws TokenizerException
*/
public static function tokenMustBeIToken($token): void
public static function tokenMustBeIToken(mixed $token): void
{
throw new self(
'Token must be instance of "' . IToken::class . '", but type "'
. (is_object($token) ? get_class($token) : json_encode($token)) . '" given.',
. (is_object($token) ? get_class($token) : json_encode($token, JSON_THROW_ON_ERROR)) . '" given.',
);
}
}
9 changes: 0 additions & 9 deletions src/Token/BaseToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
namespace Mathematicator\Tokenizer\Token;


use Nette\SmartObject;

/**
* @property string $token
* @property int $position
* @property string $type
*/
abstract class BaseToken implements IToken
{
use SmartObject;

private string $token;

private int $position;
Expand Down
2 changes: 0 additions & 2 deletions src/Token/MatrixToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public function setMatrix(array $matrix): void
private function validator(array $matrix): array
{
$lastCols = null;

foreach ($matrix as $row) {
$cols = count($row);

if ($lastCols === null) {
$lastCols = $cols;
} elseif ($cols !== $lastCols) {
Expand Down
4 changes: 3 additions & 1 deletion src/Token/PolynomialToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public function __construct(NumberToken $times, ?NumberToken $power, VariableTok
$power->setType(Tokens::M_NUMBER)
->setToken('1')
->setPosition($times->getPosition() + 1);
$this->power = $power;
} else {
$this->power = $power;
}

$this->times = $times;
$this->power = $power; // in integer formar
$this->variable = $variable;

$this->setToken(
Expand Down
2 changes: 1 addition & 1 deletion src/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ final class Tokens
/** @throws Error */
public function __construct()
{
throw new Error('Class ' . static::class . ' is static and cannot be instantiated.');
throw new Error('Class ' . self::class . ' is static and cannot be instantiated.');
}
}
4 changes: 0 additions & 4 deletions src/TokensToLatex.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function __construct(FunctionManagerFacade $functionManager)

/**
* @param IToken[] $tokens
* @return string
* @throws TokenizerException
*/
public function render(array $tokens): string
Expand All @@ -86,8 +85,6 @@ public function render(array $tokens): string

/**
* @param IToken[] $tokens
* @param int $level
* @return string
* @throws TokenizerException
*/
private function iterator(array $tokens, int $level = 0): string
Expand Down Expand Up @@ -249,7 +246,6 @@ private function renderPow(TokenIterator $iterator, int $level): MathLatexBuilde
* Fix generated haystack by smart regular patterns.
*
* @param string[] $replaceTable
* @return string
*/
private function processReplaceTable(string $haystack, array $replaceTable): string
{
Expand Down
1 change: 0 additions & 1 deletion src/TokensToObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ final class TokensToObject
public function toObject(array $tokens): array
{
$objects = [];

for ($iterator = 0; isset($tokens[$iterator]); $iterator++) {
$token = $tokens[$iterator];
switch ($token->type) {
Expand Down
2 changes: 1 addition & 1 deletion src/TokensTreeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class TokensTreeRenderer
/** @throws Error */
public function __construct()
{
throw new Error('Class ' . static::class . ' is static and cannot be instantiated.');
throw new Error('Class ' . self::class . ' is static and cannot be instantiated.');
}


Expand Down

0 comments on commit b752772

Please sign in to comment.