diff --git a/Makefile b/Makefile index 63591f8b..161e5865 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ csfix: ## Run phpcs fixer docker compose run php$(PHP_VERSION) vendor/bin/phpcbf box: ## Compile /build/composer-unused.phar - docker compose run php$(PHP_VERSION) php box.phar compile + docker compose run php$(PHP_VERSION) php .phive/box.phar compile ssh: ## SSH into container docker compose run php$(PHP_VERSION) /bin/sh diff --git a/phpstan.neon b/phpstan.neon index ac12398b..dd3ff797 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,7 @@ parameters: - phpunit.bootstrap.php excludes_analyse: - %currentWorkingDirectory%/tests/assets - level: max + level: 8 inferPrivatePropertyTypeFromConstructor: true paths: - bin/ diff --git a/src/Symbol/ConsumedSymbolLoaderBuilder.php b/src/Symbol/ConsumedSymbolLoaderBuilder.php index 3acccb9b..4bcb13d8 100644 --- a/src/Symbol/ConsumedSymbolLoaderBuilder.php +++ b/src/Symbol/ConsumedSymbolLoaderBuilder.php @@ -8,6 +8,11 @@ use ComposerUnused\SymbolParser\Parser\PHP\AutoloadType; use ComposerUnused\SymbolParser\Parser\PHP\ConsumedSymbolCollector; use ComposerUnused\SymbolParser\Parser\PHP\Strategy\ClassConstStrategy; +use ComposerUnused\SymbolParser\Parser\PHP\Strategy\ConstStrategy; +use ComposerUnused\SymbolParser\Parser\PHP\Strategy\ExtendsParseStrategy; +use ComposerUnused\SymbolParser\Parser\PHP\Strategy\FunctionInvocationStrategy; +use ComposerUnused\SymbolParser\Parser\PHP\Strategy\ImplementsParseStrategy; +use ComposerUnused\SymbolParser\Parser\PHP\Strategy\InstanceofStrategy; use ComposerUnused\SymbolParser\Parser\PHP\Strategy\NewStrategy; use ComposerUnused\SymbolParser\Parser\PHP\Strategy\StaticStrategy; use ComposerUnused\SymbolParser\Parser\PHP\Strategy\UsedExtensionSymbolStrategy; @@ -27,15 +32,20 @@ public function build(): SymbolLoaderInterface { $usedSymbolCollector = new ConsumedSymbolCollector( [ + new ClassConstStrategy(), + new ConstStrategy(), + new ExtendsParseStrategy(), + new FunctionInvocationStrategy(), + new ImplementsParseStrategy(), + new InstanceofStrategy(), new NewStrategy(), new StaticStrategy(), - new UseStrategy(), - new ClassConstStrategy(), new UsedExtensionSymbolStrategy( get_loaded_extensions(), // TODO logger new NullLogger() - ) + ), + new UseStrategy(), ] ); diff --git a/tests/Integration/UnusedCommandTest.php b/tests/Integration/UnusedCommandTest.php index 7a7047bc..22a00716 100644 --- a/tests/Integration/UnusedCommandTest.php +++ b/tests/Integration/UnusedCommandTest.php @@ -113,4 +113,17 @@ public function itShouldNotReportPatternExcludedPackages(): void self::assertStringContainsString('dummy/test-package', $commandTester->getDisplay()); self::assertStringContainsString('Found 0 used, 1 unused and 0 ignored packages', $commandTester->getDisplay()); } + + /** + * @test + */ + public function itShouldNotReportFileDependencyWithFunctionGuard(): void + { + chdir(__DIR__ . '/../assets/TestProjects/FileDependencyFunctionWithGuard'); + $commandTester = new CommandTester($this->container->get(UnusedCommand::class)); + $exitCode = $commandTester->execute([]); + + self::assertSame(0, $exitCode); + self::assertStringContainsString('Found 1 used, 0 unused and 0 ignored packages', $commandTester->getDisplay()); + } } diff --git a/tests/assets/TestProjects/FileDependencyFunctionWithGuard/composer.json b/tests/assets/TestProjects/FileDependencyFunctionWithGuard/composer.json new file mode 100644 index 00000000..29232cfd --- /dev/null +++ b/tests/assets/TestProjects/FileDependencyFunctionWithGuard/composer.json @@ -0,0 +1,16 @@ +{ + "name": "foo/bar", + "description": "foobar", + "type": "library", + "minimum-stability": "stable", + "require": { + "test/file-dependency": "*" + }, + "autoload": { + "psr-4": { + "FileDependencyFunctionWithGuard\\": "src/" + } + }, + "require-dev": { + } +} diff --git a/tests/assets/TestProjects/FileDependencyFunctionWithGuard/src/TestClass.php b/tests/assets/TestProjects/FileDependencyFunctionWithGuard/src/TestClass.php new file mode 100644 index 00000000..3a6f0d8d --- /dev/null +++ b/tests/assets/TestProjects/FileDependencyFunctionWithGuard/src/TestClass.php @@ -0,0 +1,13 @@ +