Skip to content

Commit bf442d5

Browse files
committed
Apply PER2.0 phpcs (part 1)
1 parent a45a19e commit bf442d5

File tree

12 files changed

+65
-66
lines changed

12 files changed

+65
-66
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "^9.6|^10.0",
34-
"vimeo/psalm": "^5.22"
34+
"phpstan/extension-installer": "^1.4",
35+
"phpstan/phpstan": "^1.11",
36+
"phpstan/phpstan-strict-rules": "^1.6"
3537
},
3638
"autoload-dev": {
3739
"psr-4": {

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- phar://phpstan.phar/conf/bleedingEdge.neon
3+
parameters:
4+
level: 1
5+
strictRules:
6+
allRules: true
7+
fileExtensions:
8+
- php
9+
paths:
10+
- src
11+
tmpDir: vendor/.cache.phpstan
12+
reportUnmatchedIgnoredErrors: false

psalm.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Ast/Def/TokenDef.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TokenDef extends Definition
2323

2424
public function __construct(string $name, string $value, bool $keep = true)
2525
{
26-
$this->name = $name;
26+
$this->name = $name;
2727
$this->value = $value;
28-
$this->keep = $keep;
28+
$this->keep = $keep;
2929
}
3030
}

src/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function parse($source): iterable
9090

9191
$parser = new Parser($lexer, $this->analyzer->rules, [
9292
ParserConfigsInterface::CONFIG_INITIAL_RULE => $this->analyzer->initial,
93-
ParserConfigsInterface::CONFIG_AST_BUILDER => new PrintableNodeBuilder(),
93+
ParserConfigsInterface::CONFIG_AST_BUILDER => new PrintableNodeBuilder(),
9494
]);
9595

9696
return $parser->parse($source);

src/Context/CompilerContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct(IdCollection $ids)
9999
public function enter(NodeInterface $node): void
100100
{
101101
if ($node instanceof TokenDef) {
102-
$state = $node->state ?: self::STATE_DEFAULT;
102+
$state = $node->state ?? self::STATE_DEFAULT;
103103

104104
if (!\array_key_exists($state, $this->tokens)) {
105105
$this->tokens[$state] = [];

src/Generator/PhpCodeGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ public function withClassUsage(string $class, string $alias = null): self
7272
public function generate(): string
7373
{
7474
$style = $this->printer->getStyle();
75+
$filter = static fn(string $line): bool => \trim($line) !== '';
7576

7677
return \implode($style->lineDelimiter, \array_filter([
7778
'<?php',
7879
$this->getStrictTypesResult(),
7980
$this->getReferencesResult(),
8081
$this->getBodyResult(),
81-
]));
82+
], $filter));
8283
}
8384

8485
private function getStrictTypesResult(): string

src/Grammar/PP2Grammar.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private function reducers(): array
181181
private function grammar(): array
182182
{
183183
return [
184-
0 => new Repetition(11, 0),
184+
0 => new Repetition(11, 0),
185185
11 => new Alternation([15, 16, 13, 14, 17]),
186186
13 => new Lexeme('T_PRAGMA'),
187187
14 => new Lexeme('T_INCLUDE'),
@@ -197,27 +197,27 @@ private function grammar(): array
197197
26 => new Lexeme('T_KEPT_NAME', false),
198198
27 => new Lexeme('T_NAME'),
199199
28 => new Lexeme('T_EQ', false),
200-
8 => new Alternation([21, 22, 24, 5]),
201-
9 => new Optional(29),
200+
8 => new Alternation([21, 22, 24, 5]),
201+
9 => new Optional(29),
202202
29 => new Lexeme('T_END_OF_RULE', false),
203203
21 => new Concatenation([2, 4]),
204-
4 => new Repetition(1, 1),
205-
1 => new Concatenation([30, 2]),
204+
4 => new Repetition(1, 1),
205+
1 => new Concatenation([30, 2]),
206206
30 => new Lexeme('T_OR', false),
207-
2 => new Alternation([22, 24, 5]),
207+
2 => new Alternation([22, 24, 5]),
208208
22 => new Repetition(3, 2),
209-
3 => new Alternation([24, 5]),
210-
5 => new Alternation([23, 31, 32, 33, 34]),
209+
3 => new Alternation([24, 5]),
210+
5 => new Alternation([23, 31, 32, 33, 34]),
211211
31 => new Lexeme('T_TOKEN_SKIPPED'),
212212
32 => new Lexeme('T_TOKEN_KEPT'),
213213
33 => new Lexeme('T_TOKEN_STRING'),
214214
34 => new Lexeme('T_INVOKE'),
215215
23 => new Concatenation([35, 7, 36]),
216216
35 => new Lexeme('T_GROUP_OPEN', false),
217217
36 => new Lexeme('T_GROUP_CLOSE', false),
218-
7 => new Alternation([21, 22, 24, 5]),
218+
7 => new Alternation([21, 22, 24, 5]),
219219
24 => new Concatenation([5, 6]),
220-
6 => new Alternation([37, 38, 39, 40, 41, 42, 43]),
220+
6 => new Alternation([37, 38, 39, 40, 41, 42, 43]),
221221
37 => new Lexeme('T_REPEAT_ZERO_OR_ONE'),
222222
38 => new Lexeme('T_REPEAT_ONE_OR_MORE'),
223223
39 => new Lexeme('T_REPEAT_ZERO_OR_MORE'),

src/Grammar/PP2Lexer.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,34 @@ final class PP2Lexer implements PositionalLexerInterface
155155
* @var non-empty-array<non-empty-string, non-empty-string>
156156
*/
157157
private const LEXER_TOKENS = [
158-
self::T_PRAGMA => '%pragma\\h+([\\w\\.]+)\\h+([^\\s]+)',
159-
self::T_INCLUDE => '%include\\h+([^\\s]+)',
160-
self::T_TOKEN_DEF => '%token\\h+(?:(\\w+):)?(\\w+)\\h+([^\\s]+)(?:\\h*\\->\\h*([^\\s]+))?',
161-
self::T_SKIP_DEF => '%skip\\h+(\\w+)\\h+([^\\s]+)',
162-
self::T_OR => '\\|',
163-
self::T_TOKEN_SKIPPED => '::(\\w+)::',
164-
self::T_TOKEN_KEPT => '<(\\w+)>',
165-
self::T_TOKEN_STRING => '"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"',
166-
self::T_INVOKE => '([a-zA-Z0-9_]+)\\(\\)',
167-
self::T_GROUP_OPEN => '\\(',
168-
self::T_GROUP_CLOSE => '\\)',
169-
self::T_REPEAT_ZERO_OR_ONE => '\\?',
170-
self::T_REPEAT_ONE_OR_MORE => '\\+',
158+
self::T_PRAGMA => '%pragma\\h+([\\w\\.]+)\\h+([^\\s]+)',
159+
self::T_INCLUDE => '%include\\h+([^\\s]+)',
160+
self::T_TOKEN_DEF => '%token\\h+(?:(\\w+):)?(\\w+)\\h+([^\\s]+)(?:\\h*\\->\\h*([^\\s]+))?',
161+
self::T_SKIP_DEF => '%skip\\h+(\\w+)\\h+([^\\s]+)',
162+
self::T_OR => '\\|',
163+
self::T_TOKEN_SKIPPED => '::(\\w+)::',
164+
self::T_TOKEN_KEPT => '<(\\w+)>',
165+
self::T_TOKEN_STRING => '"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"',
166+
self::T_INVOKE => '([a-zA-Z0-9_]+)\\(\\)',
167+
self::T_GROUP_OPEN => '\\(',
168+
self::T_GROUP_CLOSE => '\\)',
169+
self::T_REPEAT_ZERO_OR_ONE => '\\?',
170+
self::T_REPEAT_ONE_OR_MORE => '\\+',
171171
self::T_REPEAT_ZERO_OR_MORE => '\\*',
172-
self::T_REPEAT_N_TO_M => '{\\h*(\\-?\\d+)\\h*,\\h*(\\-?\\d+)\\h*}',
173-
self::T_REPEAT_N_OR_MORE => '{\\h*(\\-?\\d+)\\h*,\\h*}',
174-
self::T_REPEAT_ZERO_TO_M => '{\\h*,\\h*(\\-?\\d+)\\h*}',
175-
self::T_REPEAT_EXACTLY_N => '{\\h*(\\-?\\d+)\\h*}',
176-
self::T_KEPT_NAME => '#',
177-
self::T_NAME => '\\\\?[a-zA-Z0-9_]+(?:\\\\[a-zA-Z0-9_]+)*',
178-
self::T_EQ => '(?:\\:\\:=|\\:|=)',
179-
self::T_END_OF_RULE => ';',
180-
self::T_PHP_OPEN => '\->\h*{',
181-
self::T_ARROW_RIGHT => '\->',
182-
self::T_PHP_CLOSE => '}',
183-
self::T_WHITESPACE => '(\\xfe\\xff|\\x20|\\x09|\\x0a|\\x0d)+',
184-
self::T_COMMENT => '//[^\\n]*',
185-
self::T_BLOCK_COMMENT => '/\\*.*?\\*/',
172+
self::T_REPEAT_N_TO_M => '{\\h*(\\-?\\d+)\\h*,\\h*(\\-?\\d+)\\h*}',
173+
self::T_REPEAT_N_OR_MORE => '{\\h*(\\-?\\d+)\\h*,\\h*}',
174+
self::T_REPEAT_ZERO_TO_M => '{\\h*,\\h*(\\-?\\d+)\\h*}',
175+
self::T_REPEAT_EXACTLY_N => '{\\h*(\\-?\\d+)\\h*}',
176+
self::T_KEPT_NAME => '#',
177+
self::T_NAME => '\\\\?[a-zA-Z0-9_]+(?:\\\\[a-zA-Z0-9_]+)*',
178+
self::T_EQ => '(?:\\:\\:=|\\:|=)',
179+
self::T_END_OF_RULE => ';',
180+
self::T_PHP_OPEN => '\->\h*{',
181+
self::T_ARROW_RIGHT => '\->',
182+
self::T_PHP_CLOSE => '}',
183+
self::T_WHITESPACE => '(\\xfe\\xff|\\x20|\\x09|\\x0a|\\x0d)+',
184+
self::T_COMMENT => '//[^\\n]*',
185+
self::T_BLOCK_COMMENT => '/\\*.*?\\*/',
186186
];
187187

188188
/**

src/Grammar/PP2PHPLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function lex($source, int $offset = 0): iterable
2121
$depth = 0;
2222

2323
$children = [];
24-
$value = '';
24+
$value = '';
2525

2626
foreach ($this->lexer->lex($source, $offset) as $inner) {
2727
if ($inner->getName() === '{') {

0 commit comments

Comments
 (0)