From 9ce26851ef2f77141f3e0a882069c125455ddf5c Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Fri, 27 Dec 2024 13:29:18 +0100 Subject: [PATCH 1/2] Failing test: rule hooked to PhpParser\Name node --- tests/PHPStan/Rules/NameHookedRuleTest.php | 51 ++++++++++++++++++++++ tests/PHPStan/Rules/data/name-hooked.php | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 tests/PHPStan/Rules/NameHookedRuleTest.php create mode 100644 tests/PHPStan/Rules/data/name-hooked.php diff --git a/tests/PHPStan/Rules/NameHookedRuleTest.php b/tests/PHPStan/Rules/NameHookedRuleTest.php new file mode 100644 index 0000000000..483de8b4b6 --- /dev/null +++ b/tests/PHPStan/Rules/NameHookedRuleTest.php @@ -0,0 +1,51 @@ + + */ +class NameHookedRuleTest extends RuleTestCase +{ + + /** + * @return Rule + */ + protected function getRule(): Rule + { + return new class implements Rule { + + public function getNodeType(): string + { + return Name::class; + } + + /** + * @param Name $node + */ + public function processNode(Node $node, Scope $scope): array + { + return RuleErrorBuilder::message('Found a name: ' . $node->toString()) + ->identifier('test.name.hooked') + ->build(); + } + + }; + } + + public function testRule(): void + { + $this->analyse([__DIR__ . '/data/name-hooked.php'], [ + [ + 'Found a name: NameHooked', + 3, + ], + ]); + } + +} diff --git a/tests/PHPStan/Rules/data/name-hooked.php b/tests/PHPStan/Rules/data/name-hooked.php new file mode 100644 index 0000000000..c6d1f183bc --- /dev/null +++ b/tests/PHPStan/Rules/data/name-hooked.php @@ -0,0 +1,3 @@ + Date: Fri, 27 Dec 2024 13:35:25 +0100 Subject: [PATCH 2/2] fix --- tests/PHPStan/Rules/NameHookedRuleTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/NameHookedRuleTest.php b/tests/PHPStan/Rules/NameHookedRuleTest.php index 483de8b4b6..80419b3ab0 100644 --- a/tests/PHPStan/Rules/NameHookedRuleTest.php +++ b/tests/PHPStan/Rules/NameHookedRuleTest.php @@ -30,9 +30,11 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): array { - return RuleErrorBuilder::message('Found a name: ' . $node->toString()) + $error = RuleErrorBuilder::message('Found a name: ' . $node->toString()) ->identifier('test.name.hooked') ->build(); + + return [$error]; } };