Skip to content

Commit

Permalink
Apply PER2.0 phpcs (part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Aug 1, 2024
1 parent 80e6472 commit 0e28bf3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions psalm.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/Grammar/Repetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Grammar/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/GrammarGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
];

Expand Down
14 changes: 7 additions & 7 deletions tests/Functional/SimpleSumParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0e28bf3

Please sign in to comment.