Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for function invocation parsing #249

Merged
merged 3 commits into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Expand Up @@ -6,7 +6,7 @@ parameters:
- phpunit.bootstrap.php
excludes_analyse:
- %currentWorkingDirectory%/tests/assets
level: max
level: 8
inferPrivatePropertyTypeFromConstructor: true
paths:
- bin/
Expand Down
16 changes: 13 additions & 3 deletions src/Symbol/ConsumedSymbolLoaderBuilder.php
Expand Up @@ -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;
Expand All @@ -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(),
]
);

Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/UnusedCommandTest.php
Expand Up @@ -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());
}
}
@@ -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": {
}
}
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace FileDependencyFunctionWithGuard;

class TestClass
{
public function testMethod(): void
{
$b = testfunction2();
}
}
@@ -0,0 +1,17 @@
[
{
"name": "test/file-dependency",
"type": "library",
"version": "1.0",
"description": "test dependency",
"autoload": {
"files": [
"src/file.php"
]
},
"require": {
},
"require-dev": {
}
}
]
@@ -0,0 +1,14 @@
{
"name": "test/file-dependency",
"type": "library",
"description": "test dependency",
"autoload": {
"files": [
"src/file.php"
]
},
"require": {
},
"require-dev": {
}
}
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

if (!function_exists('testfunction2')) {
function testfunction2() {}
}