From 502706da9a95cb8ebf07c1bea6852928a1fb9ae4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 16 Sep 2024 09:26:19 +0200 Subject: [PATCH] Fix template discovery, to include root file too (#127) --- composer.json | 6 +++--- .../PublicStaticPropertyFetchCollector.php | 4 +++- src/Finder/TemplateFilesFinder.php | 5 +++++ .../TemplateFilesFinder/Fixture/first.file.twig | 1 + .../Fixture/nested/second.file.twig | 1 + .../TemplateFilesFinderTest.php | 15 +++++++++++++++ 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/Templates/TemplateFilesFinder/Fixture/first.file.twig create mode 100644 tests/Templates/TemplateFilesFinder/Fixture/nested/second.file.twig create mode 100644 tests/Templates/TemplateFilesFinder/TemplateFilesFinderTest.php diff --git a/composer.json b/composer.json index 956d886..23b4f64 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "phpstan/extension-installer": "^1.4", "tracy/tracy": "^2.10", "symplify/easy-coding-standard": "^12.3", - "rector/rector": "^1.2.4", + "rector/rector": "^1.2.5", "phpunit/phpunit": "^10.5", "tomasvotruba/class-leak": "^0.2.11", "tomasvotruba/type-coverage": "^0.3", - "symplify/easy-ci": "^12.0", - "shipmonk/composer-dependency-analyser": "^1.5", + "symplify/easy-ci": "^12.1", + "shipmonk/composer-dependency-analyser": "^1.7", "symplify/phpstan-rules": "^13.0" }, "autoload": { diff --git a/src/Collectors/PublicStaticPropertyFetchCollector.php b/src/Collectors/PublicStaticPropertyFetchCollector.php index 34df215..3ff6b85 100644 --- a/src/Collectors/PublicStaticPropertyFetchCollector.php +++ b/src/Collectors/PublicStaticPropertyFetchCollector.php @@ -59,7 +59,9 @@ public function processNode(Node $node, Scope $scope): ?array return null; } - $classType = $node->class instanceof Name ? $scope->resolveTypeByName($node->class) : $scope->getType($node->class); + $classType = $node->class instanceof Name ? $scope->resolveTypeByName($node->class) : $scope->getType( + $node->class + ); $result = []; foreach ($classType->getObjectClassReflections() as $classReflection) { diff --git a/src/Finder/TemplateFilesFinder.php b/src/Finder/TemplateFilesFinder.php index 30229a0..6b822a7 100644 --- a/src/Finder/TemplateFilesFinder.php +++ b/src/Finder/TemplateFilesFinder.php @@ -4,6 +4,9 @@ namespace TomasVotruba\UnusedPublic\Finder; +/** + * @see \TomasVotruba\UnusedPublic\Tests\Templates\TemplateFilesFinder\TemplateFilesFinderTest + */ final class TemplateFilesFinder { /** @@ -15,10 +18,12 @@ public static function findTemplateFilePaths(array $directories, string $suffix) $templateFilePaths = []; foreach ($directories as $directory) { + $currentTemplateFilePathsL0 = glob($directory . '/*.' . $suffix); $currentTemplateFilePathsL1 = glob($directory . '/*/*.' . $suffix); $currentTemplateFilePathsL2 = glob($directory . '/**/*/*.' . $suffix); $currentTemplateFilePaths = array_merge( + $currentTemplateFilePathsL0 === false ? [] : $currentTemplateFilePathsL0, $currentTemplateFilePathsL1 === false ? [] : $currentTemplateFilePathsL1, $currentTemplateFilePathsL2 === false ? [] : $currentTemplateFilePathsL2 ); diff --git a/tests/Templates/TemplateFilesFinder/Fixture/first.file.twig b/tests/Templates/TemplateFilesFinder/Fixture/first.file.twig new file mode 100644 index 0000000..9c59e24 --- /dev/null +++ b/tests/Templates/TemplateFilesFinder/Fixture/first.file.twig @@ -0,0 +1 @@ +first diff --git a/tests/Templates/TemplateFilesFinder/Fixture/nested/second.file.twig b/tests/Templates/TemplateFilesFinder/Fixture/nested/second.file.twig new file mode 100644 index 0000000..e019be0 --- /dev/null +++ b/tests/Templates/TemplateFilesFinder/Fixture/nested/second.file.twig @@ -0,0 +1 @@ +second diff --git a/tests/Templates/TemplateFilesFinder/TemplateFilesFinderTest.php b/tests/Templates/TemplateFilesFinder/TemplateFilesFinderTest.php new file mode 100644 index 0000000..c3dc376 --- /dev/null +++ b/tests/Templates/TemplateFilesFinder/TemplateFilesFinderTest.php @@ -0,0 +1,15 @@ +assertCount(2, $twigFilePaths); + } +}