Skip to content

Commit

Permalink
Bugfix in source context logic
Browse files Browse the repository at this point in the history
  • Loading branch information
drjayvee committed Mar 10, 2024
1 parent ee61658 commit 9de0537
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Inspection/BadArgumentCountInMacroCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ protected function doEnterNode(Node $node, Environment $env): Node
} elseif ($node instanceof MethodCallExpression) {
// when visiting a function call, log call
$macroName = substr($node->getAttribute('method'), strlen('macro_'));
$location = ($node->getSourceContext()?->getPath() ?? 'local') . ':' . $node->getTemplateLine();

$sourcePath = ($node->getSourceContext() ?? $node->getNode('node')->getSourceContext())?->getPath()
?? 'unknown';
$location = "$sourcePath:{$node->getTemplateLine()}";

$argumentCount = count($node->getNode('arguments')->getKeyValuePairs());

$this->macroCalls[$macroName][] = [$argumentCount, $location];
Expand Down
2 changes: 2 additions & 0 deletions tests/BadArgumentCountInMacroCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ public function test_importedMacro(): void

self::assertCount(2, $this->errors);

self::assertStringContainsString('importedMacro', $this->errors[0]);
self::assertStringContainsString('local', $this->errors[0]);
self::assertStringContainsStringIgnoringCase('too many', $this->errors[0]);

self::assertStringContainsString('importedMacro', $this->errors[1]);
self::assertStringContainsString('marco', $this->errors[1]);
self::assertStringContainsStringIgnoringCase('too many', $this->errors[1]);
}
Expand Down

0 comments on commit 9de0537

Please sign in to comment.