From d629cd4a22fa0cc25e77f378ed19981110824b62 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 22:41:49 +0000 Subject: [PATCH 1/3] Collect dependencies defined in property hooks Add support for collecting dependencies from PHP 8.4 property hooks: - Handle typed parameters in set hooks (e.g., set(MyClass $value)) - Dependencies from expressions within hook bodies (new, static calls, etc.) are already collected by the AST traverser Fixes #515 --- src/Analyzer/FileVisitor.php | 15 ++++ .../FileParser/CanParsePropertyHooksTest.php | 71 +++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php index 7ffedda9..0dbc605f 100644 --- a/src/Analyzer/FileVisitor.php +++ b/src/Analyzer/FileVisitor.php @@ -67,6 +67,9 @@ public function enterNode(Node $node): void // handles attribute definition like #[MyAttribute] $this->handleAttributeNode($node); + + // handles property hooks like public string $name { get => ...; set { ... } } + $this->handlePropertyHookNode($node); } public function getClassDescriptions(): array @@ -349,4 +352,16 @@ private function addParamDependency(Node\Param $node): void $this->classDescriptionBuilder ->addDependency(new ClassDependency($type->toString(), $node->getLine())); } + + private function handlePropertyHookNode(Node $node): void + { + if (!($node instanceof Node\PropertyHook)) { + return; + } + + // Handle parameters in set hooks (e.g., set(MyClass $value) { ... }) + foreach ($node->params as $param) { + $this->addParamDependency($param); + } + } } diff --git a/tests/Unit/Analyzer/FileParser/CanParsePropertyHooksTest.php b/tests/Unit/Analyzer/FileParser/CanParsePropertyHooksTest.php index 9e71b636..01a548ae 100644 --- a/tests/Unit/Analyzer/FileParser/CanParsePropertyHooksTest.php +++ b/tests/Unit/Analyzer/FileParser/CanParsePropertyHooksTest.php @@ -40,4 +40,75 @@ public function __construct(string $firstName, string $lastName) { self::assertInstanceOf(ClassDescription::class, $cd[0]); } + + public function test_it_collects_dependencies_from_property_hooks(): void + { + $code = <<< 'EOF' + format($this->name); + } + set { + $validator = new Validator(); + $validator->validate($value); + $this->name = $value; + Logger::log('Name set'); + } + } + } + EOF; + + $fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_4); + $fp->parse($code, 'relativePathName'); + + $cd = $fp->getClassDescriptions(); + + self::assertInstanceOf(ClassDescription::class, $cd[0]); + + $dependencies = $cd[0]->getDependencies(); + $dependencyNames = array_map(fn ($dep) => $dep->getFQCN()->toString(), $dependencies); + + self::assertContains('App\Services\Formatter', $dependencyNames); + self::assertContains('App\Services\Validator', $dependencyNames); + self::assertContains('App\Services\Logger', $dependencyNames); + } + + public function test_it_collects_dependencies_from_property_hook_parameters(): void + { + $code = <<< 'EOF' + name = $name->toString(); + } + } + } + EOF; + + $fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_4); + $fp->parse($code, 'relativePathName'); + + $cd = $fp->getClassDescriptions(); + + self::assertInstanceOf(ClassDescription::class, $cd[0]); + + $dependencies = $cd[0]->getDependencies(); + $dependencyNames = array_map(fn ($dep) => $dep->getFQCN()->toString(), $dependencies); + + self::assertContains('App\ValueObjects\Name', $dependencyNames); + } } From 48c494c2b203d4b0ba2161178094f06d7dd3cb40 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 1 Jan 2026 20:12:15 +0000 Subject: [PATCH 2/3] Add PHP 8.4 to supported versions list in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 882dc41a..619b0c80 100644 --- a/README.md +++ b/README.md @@ -473,7 +473,7 @@ You can add parameters when you launch the tool. At the moment you can add these phparkitect check --config=/project/yourConfigFile.php ``` * `--target-php-version`: With this parameter, you can specify which PHP version should use the parser. This can be useful to debug problems and to understand if there are problems with a different PHP version. -Supported PHP versions are: 7.4, 8.0, 8.1, 8.2 8.3 +Supported PHP versions are: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 * `--stop-on-failure`: With this option the process will end immediately after the first violation. * `--autoload`: specify the path of an autoload file to be loaded when running phparkitect. From 43c9270fd1591f2b9876850ee232343f06b4b581 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 1 Jan 2026 21:14:58 +0000 Subject: [PATCH 3/3] Add PHP 8.5 to supported versions list in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b35e288..19995df8 100644 --- a/README.md +++ b/README.md @@ -473,7 +473,7 @@ You can add parameters when you launch the tool. At the moment you can add these phparkitect check --config=/project/yourConfigFile.php ``` * `--target-php-version`: With this parameter, you can specify which PHP version should use the parser. This can be useful to debug problems and to understand if there are problems with a different PHP version. -Supported PHP versions are: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 +Supported PHP versions are: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5 * `--stop-on-failure`: With this option the process will end immediately after the first violation. * `--autoload`: specify the path of an autoload file to be loaded when running phparkitect.