Skip to content

Commit

Permalink
Support for multiline {define} block (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMystikJonas authored Sep 27, 2024
2 parents 81d2fe1 + 3533521 commit 280e5cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Fixed
- Updated coding standard (Possible **BC break** - added `final` or `abstract` to (almost) all classes)
- Bleeding edge changes - updated typehints
- Fixed parameters parsing for multiline {define}
- Functions handling with FunctionExecutor in new Latte
- Removed unformatPresenterClass of new PresenterFactory

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function leaveNode(Node $node): ?array
}

$parameters = [];
$pattern = '/(?<define>{define (?<block_name>.*?),? (?<parameters>.*)}) on line (?<line>\d+)/';
$pattern = '/(?<define>{define\s+(?<block_name>.*?)\s*,?\s+(?<parameters>.*)})\s+on line (?<line>\d+)/s';
preg_match($pattern, $comment->getText(), $match);
if (isset($match['parameters'])) {
$define = $match['define'];

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.3

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.1

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.2

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 8.0

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

Check failure on line 62 in src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan - PHP 7.4

Offset 'define' might not exist on array{0?: string, define?: non-falsy-string, 1?: non-falsy-string, block_name?: string, 2?: string, parameters: string, 3?: string, line?: numeric-string, ...}.

$typesAndVariablesPattern = '/(?<type>[\?\\\[\]\<\>[:alnum:]]*)[ ]*\$(?<variable>[[:alnum:]]+)/';
$typesAndVariablesPattern = '/(?<type>[\?\\\[\]\<\>[:alnum:]]*)[ ]*\$(?<variable>[[:alnum:]]+)/s';
preg_match_all($typesAndVariablesPattern, $match['parameters'], $typesAndVariables);

$variableTypes = array_combine($typesAndVariables['variable'], $typesAndVariables['type']) ?: [];
Expand Down Expand Up @@ -102,7 +102,7 @@ public function leaveNode(Node $node): ?array
}
} else {
// process default blocks content etc.
$pattern = '/{block (?<block_name>.*?)} on line (?<line>\d+)/';
$pattern = '/{block\s+(?<block_name>.*?)}\s+on line (?<line>\d+)/s';
preg_match($pattern, $comment->getText(), $match);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
{include no-comma-block, $knownInteger}
{include no-comma-block}

{define multiline-block,
int $count,
string $name}
{php \PHPStan\dumpType($count)}
{php \PHPStan\dumpType($name)}
{/define}

{php \PHPStan\dumpType($paramString)}
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,19 @@ public function testBlocks(): void
30,
'define.latte',
],
[
'Dumped type: int',
35,
'define.latte',
],
[
'Dumped type: string',
36,
'define.latte',
],
[
'Dumped type: \'some string\'',
32,
39,
'define.latte',
],
]);
Expand Down

0 comments on commit 280e5cb

Please sign in to comment.