diff --git a/CHANGELOG.md b/CHANGELOG.md index b974be59..998607c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php b/src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php index e80e3937..8464cecf 100644 --- a/src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php +++ b/src/Compiler/NodeVisitor/AddParametersForBlockNodeVisitor.php @@ -56,12 +56,12 @@ public function leaveNode(Node $node): ?array } $parameters = []; - $pattern = '/(?{define (?.*?),? (?.*)}) on line (?\d+)/'; + $pattern = '/(?{define\s+(?.*?)\s*,?\s+(?.*)})\s+on line (?\d+)/s'; preg_match($pattern, $comment->getText(), $match); if (isset($match['parameters'])) { $define = $match['define']; - $typesAndVariablesPattern = '/(?[\?\\\[\]\<\>[:alnum:]]*)[ ]*\$(?[[:alnum:]]+)/'; + $typesAndVariablesPattern = '/(?[\?\\\[\]\<\>[:alnum:]]*)[ ]*\$(?[[:alnum:]]+)/s'; preg_match_all($typesAndVariablesPattern, $match['parameters'], $typesAndVariables); $variableTypes = array_combine($typesAndVariables['variable'], $typesAndVariables['type']) ?: []; @@ -102,7 +102,7 @@ public function leaveNode(Node $node): ?array } } else { // process default blocks content etc. - $pattern = '/{block (?.*?)} on line (?\d+)/'; + $pattern = '/{block\s+(?.*?)}\s+on line (?\d+)/s'; preg_match($pattern, $comment->getText(), $match); } diff --git a/tests/Rule/LatteTemplatesRule/SimpleControl/Fixtures/Blocks/define.latte b/tests/Rule/LatteTemplatesRule/SimpleControl/Fixtures/Blocks/define.latte index a93fb10d..f303caea 100644 --- a/tests/Rule/LatteTemplatesRule/SimpleControl/Fixtures/Blocks/define.latte +++ b/tests/Rule/LatteTemplatesRule/SimpleControl/Fixtures/Blocks/define.latte @@ -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)} diff --git a/tests/Rule/LatteTemplatesRule/SimpleControl/LatteTemplatesRuleForSimpleControlTest.php b/tests/Rule/LatteTemplatesRule/SimpleControl/LatteTemplatesRuleForSimpleControlTest.php index 19974676..3645d96a 100644 --- a/tests/Rule/LatteTemplatesRule/SimpleControl/LatteTemplatesRuleForSimpleControlTest.php +++ b/tests/Rule/LatteTemplatesRule/SimpleControl/LatteTemplatesRuleForSimpleControlTest.php @@ -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', ], ]);