Skip to content

Commit 1d400f4

Browse files
authored
skip wildcards in StringFileAbsolutePathExistsRule (#194)
1 parent 0ccb0c5 commit 1d400f4

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/Rules/StringFileAbsolutePathExistsRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function processNode(Node $node, Scope $scope): array
6060
return [];
6161
}
6262

63+
// probably glob or wildcard, cannot be checked
64+
if (str_contains($stringValue, '*')) {
65+
return [];
66+
}
67+
6368
$absoluteFilePath = $this->getAbsoluteFilePath($scope, $stringValue);
6469
if (file_exists($absoluteFilePath)) {
6570
return [];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\StringFileAbsolutePathExistsRule\Fixture;
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
7+
return function (ContainerConfigurator $containerConfigurator): void {
8+
$services = $containerConfigurator->services();
9+
10+
$services->load('App\\', __DIR__ . '/../src/*Repository.php');
11+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\StringFileAbsolutePathExistsRule\Fixture;
4+
5+
final class SkipMasks
6+
{
7+
public function go()
8+
{
9+
return glob(__DIR__ . '/some_file/*');
10+
}
11+
}

tests/Rules/StringFileAbsolutePathExistsRule/StringFileAbsolutePathExistsRuleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static function provideData(): Iterator
2828

2929
yield [__DIR__ . '/Fixture/SkipReferenceToExistingFile.php', []];
3030
yield [__DIR__ . '/Fixture/SkipNestedConcats.php', []];
31+
yield [__DIR__ . '/Fixture/SkipMasks.php', []];
32+
yield [__DIR__ . '/Fixture/SkipClosure.php', []];
3133
}
3234

3335
protected function getRule(): Rule

0 commit comments

Comments
 (0)