Skip to content

Commit 17083ad

Browse files
Support for multiline {define} block
1 parent 59701ae commit 17083ad

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function leaveNode(Node $node): ?array
5656
}
5757

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

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

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

tests/Rule/LatteTemplatesRule/SimpleControl/Fixtures/Blocks/define.latte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@
2929
{include no-comma-block, $knownInteger}
3030
{include no-comma-block}
3131

32+
{define multiline-block,
33+
int $count,
34+
string $name}
35+
{php \PHPStan\dumpType($count)}
36+
{php \PHPStan\dumpType($name)}
37+
{/define}
38+
3239
{php \PHPStan\dumpType($paramString)}

tests/Rule/LatteTemplatesRule/SimpleControl/LatteTemplatesRuleForSimpleControlTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,19 @@ public function testBlocks(): void
378378
30,
379379
'define.latte',
380380
],
381+
[
382+
'Dumped type: int',
383+
35,
384+
'define.latte',
385+
],
386+
[
387+
'Dumped type: string',
388+
36,
389+
'define.latte',
390+
],
381391
[
382392
'Dumped type: \'some string\'',
383-
32,
393+
39,
384394
'define.latte',
385395
],
386396
]);

0 commit comments

Comments
 (0)