diff --git a/composer.json b/composer.json index 42e2e1b..31ac2d0 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,9 @@ "phplrt/visitor": "^3.6", "phplrt/lexer": "^3.6", "phpunit/phpunit": "^9.6|^10.0", - "vimeo/psalm": "^5.22", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.11", + "phpstan/phpstan-strict-rules": "^1.6", "jetbrains/phpstorm-attributes": "^1.0" }, "autoload-dev": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..f913176 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon +parameters: + level: 1 + strictRules: + allRules: true + fileExtensions: + - php + paths: + - src + tmpDir: vendor/.cache.phpstan + reportUnmatchedIgnoredErrors: false diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 7d47ed8..0000000 --- a/psalm.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/src/Grammar/Repetition.php b/src/Grammar/Repetition.php index 88be291..4032faf 100644 --- a/src/Grammar/Repetition.php +++ b/src/Grammar/Repetition.php @@ -45,8 +45,8 @@ public function __construct($rule, int $gte = 0, $lte = \INF) \assert($lte >= $gte, 'Min repetitions count must be greater or equal than max repetitions'); $this->rule = $rule; - $this->gte = $gte; - $this->lte = \is_infinite($lte) ? \INF : (int) $lte; + $this->gte = $gte; + $this->lte = \is_infinite($lte) ? \INF : (int) $lte; } public function getTerminals(array $rules): iterable diff --git a/src/Grammar/Terminal.php b/src/Grammar/Terminal.php index 2dd4914..91a4d48 100644 --- a/src/Grammar/Terminal.php +++ b/src/Grammar/Terminal.php @@ -9,9 +9,9 @@ abstract class Terminal extends Rule implements TerminalInterface /** * @readonly Should not be modified in runtime. */ - public bool $keep = true; + public bool $keep; - public function __construct(bool $keep) + public function __construct(bool $keep = true) { $this->keep = $keep; } diff --git a/tests/Functional/GrammarGeneratorTest.php b/tests/Functional/GrammarGeneratorTest.php index 0127fab..d3efb49 100644 --- a/tests/Functional/GrammarGeneratorTest.php +++ b/tests/Functional/GrammarGeneratorTest.php @@ -48,10 +48,10 @@ public function testHelpers(): void }); $expected = [ - 0 => new Lexeme('digit'), - 1 => new Lexeme('plus'), - 2 => new Concatenation([1, 0]), - 3 => new Repetition(2), + 0 => new Lexeme('digit'), + 1 => new Lexeme('plus'), + 2 => new Concatenation([1, 0]), + 3 => new Repetition(2), 'sum' => new Concatenation([0, 3]), ]; diff --git a/tests/Functional/SimpleSumParserTest.php b/tests/Functional/SimpleSumParserTest.php index 4085074..586d3a3 100644 --- a/tests/Functional/SimpleSumParserTest.php +++ b/tests/Functional/SimpleSumParserTest.php @@ -55,21 +55,21 @@ private function parseSum(string $expr): iterable { $lexer = new Lexer([ 'T_WHITESPACE' => '\s+', - 'T_DIGIT' => '\d+', - 'T_PLUS' => '\+', + 'T_DIGIT' => '\d+', + 'T_PLUS' => '\+', ], ['T_WHITESPACE']); $grammar = [ - 0 => new Lexeme('T_DIGIT'), - 1 => new Lexeme('T_PLUS'), - 2 => new Repetition('suffix'), - 'sum' => new Concatenation([0, 2]), + 0 => new Lexeme('T_DIGIT'), + 1 => new Lexeme('T_PLUS'), + 2 => new Repetition('suffix'), + 'sum' => new Concatenation([0, 2]), 'suffix' => new Concatenation([1, 0]), ]; $parser = new Parser($lexer, $grammar, [ Parser::CONFIG_INITIAL_RULE => 'sum', - Parser::CONFIG_AST_BUILDER => $this, + Parser::CONFIG_AST_BUILDER => $this, ]); return $parser->parse($expr);