Skip to content

Commit

Permalink
Check for function invocation parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Frömer <andreas.froemer@check24.de>
  • Loading branch information
Andreas Frömer committed Jan 4, 2022
1 parent 8f0608f commit ee26e38
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 4 deletions.
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
16 changes: 16 additions & 0 deletions tests/Integration/UnusedCommandTest.php
Expand Up @@ -113,4 +113,20 @@ 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');

self::assertEquals(
0,
$this->getApplication()->run(
new ArrayInput(['unused']),
new NullOutput()
)
);
}
}
@@ -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() {}
}

0 comments on commit ee26e38

Please sign in to comment.