Skip to content

Commit 041922b

Browse files
committed
[BE] No implicit wildcard in FileExcluder
1 parent f2bb4ca commit 041922b

File tree

11 files changed

+51
-60
lines changed

11 files changed

+51
-60
lines changed

UPGRADING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ Don't forget to update [3rd party PHPStan extensions](https://phpstan.org/user-g
3232

3333
After changing your `composer.json`, run `composer update 'phpstan/*' -W`.
3434

35+
### Paths in `excludePaths` and `ignoreErrors` have to be a valid file path or a fnmatch pattern
36+
37+
If you are excluding a file path that might not exist but you still want to have it in `excludePaths`, append `(?)`:
38+
39+
```neon
40+
parameters:
41+
excludePaths:
42+
- tests/*/data/*
43+
- src/broken
44+
- node_modules (?) # optional path, might not exist
45+
```
46+
47+
If you have the same situation in `ignoreErrors` (ignoring an error in a path that might not exist), use `reportUnmatchedIgnoredErrors: false`.
48+
49+
```neon
50+
parameters:
51+
reportUnmatchedIgnoredErrors: false
52+
```
53+
54+
Appending `(?)` in `ignoreErrors` is not supported.
55+
3556
## Upgrading guide for extension developers
3657

3758
### PHPStan now uses nikic/php-parser v5

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ Bleeding edge (TODO move to other sections)
120120
* Check types in `@property` tags (https://github.com/phpstan/phpstan-src/commit/55ea2ae516df22a071ab873fdd6f748a3af0520e), #10752, #9356
121121
* Check types in `@method` tags (https://github.com/phpstan/phpstan-src/commit/5b7e474680eaf33874b7ed6a227677adcbed9ca5)
122122
* Check `@extends`, `@implements`, `@use` for unresolvable types (https://github.com/phpstan/phpstan-src/commit/2bb528233edb75312614166e282776f279cf2018), #11552
123-
* Report invalid exclude paths in PHP config (https://github.com/phpstan/phpstan-src/commit/9718c14f1ffac81ba3d2bf331b4e8b4041a4d004)
124123
* RegularExpressionPatternRule: validate preg_quote'd patterns ([#3270](https://github.com/phpstan/phpstan-src/pull/3270)), thanks @staabm!
125-
* No implicit wildcard in FileExcluder (https://github.com/phpstan/phpstan-src/commit/e19e6e5f8cfa706cc30e44a17276a6bc269f995c), #10299
126124
* Report useless return values of function calls like `var_export` without `$return=true` ([#3225](https://github.com/phpstan/phpstan-src/pull/3225)), #11320, thanks @staabm!
127125
* Check mixed in binary operator ([#3231](https://github.com/phpstan/phpstan-src/pull/3231)), #7538, #10440, thanks @schlndh!
128126
* Check vprintf/vsprintf arguments against placeholder count ([#3126](https://github.com/phpstan/phpstan-src/pull/3126)), thanks @staabm!
@@ -140,6 +138,8 @@ Improvements 🔧
140138
* Unescape strings in PHPDoc parser (https://github.com/phpstan/phpstan-src/commit/97786ed8376b478ec541ea9df1c450c1fbfe7461)
141139
* PHPDoc parser: add config for lines in its AST & enable ignoring errors within PHPDocs ([#2807](https://github.com/phpstan/phpstan-src/pull/2807)), thanks @janedbal!
142140
* InvalidPhpDocTagValueRule: include PHPDoc line number in the error message (https://github.com/phpstan/phpstan-src/commit/a04e0be832900749b5b4ba22e2de21db8bfa09a0)
141+
* No implicit wildcard in FileExcluder (https://github.com/phpstan/phpstan-src/commit/e19e6e5f8cfa706cc30e44a17276a6bc269f995c), #10299
142+
* Report invalid exclude paths in PHP config (https://github.com/phpstan/phpstan-src/commit/9718c14f1ffac81ba3d2bf331b4e8b4041a4d004)
143143

144144
Bugfixes 🐛
145145
=====================

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ parameters:
5353
printfArrayParameters: true
5454
preciseMissingReturn: true
5555
validatePregQuote: true
56-
noImplicitWildcard: true
5756
tooWidePropertyType: true
5857
explicitThrow: true
5958
absentTypeChecks: true

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ parameters:
8989
printfArrayParameters: false
9090
preciseMissingReturn: false
9191
validatePregQuote: false
92-
noImplicitWildcard: false
9392
requireFileExists: false
9493
narrowPregMatches: true
9594
tooWidePropertyType: false
@@ -682,8 +681,6 @@ services:
682681

683682
-
684683
implement: PHPStan\File\FileExcluderRawFactory
685-
arguments:
686-
noImplicitWildcard: %featureToggles.noImplicitWildcard%
687684

688685
fileExcluderAnalyse:
689686
class: PHPStan\File\FileExcluder

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ parametersSchema:
8383
printfArrayParameters: bool()
8484
preciseMissingReturn: bool()
8585
validatePregQuote: bool()
86-
noImplicitWildcard: bool()
8786
narrowPregMatches: bool()
8887
tooWidePropertyType: bool()
8988
explicitThrow: bool()

src/Analyser/Ignore/IgnoredError.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Nette\Utils\Strings;
66
use PHPStan\Analyser\Error;
7-
use PHPStan\DependencyInjection\BleedingEdgeToggle;
87
use PHPStan\File\FileExcluder;
98
use PHPStan\File\FileHelper;
109
use PHPStan\ShouldNotHappenException;
@@ -86,7 +85,7 @@ public static function shouldIgnore(
8685
}
8786

8887
if ($path !== null) {
89-
$fileExcluder = new FileExcluder($fileHelper, [$path], BleedingEdgeToggle::isBleedingEdge());
88+
$fileExcluder = new FileExcluder($fileHelper, [$path]);
9089
$isExcluded = $fileExcluder->isExcludedFromAnalysing($error->getFilePath());
9190
if (!$isExcluded && $error->getTraitFilePath() !== null) {
9291
return $fileExcluder->isExcludedFromAnalysing($error->getTraitFilePath());

src/Command/CommandHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public static function begin(
609609

610610
$pathRoutingParser->setAnalysedFiles($files);
611611

612-
$stubFilesExcluder = new FileExcluder($currentWorkingDirectoryFileHelper, $stubFilesProvider->getProjectStubFiles(), true);
612+
$stubFilesExcluder = new FileExcluder($currentWorkingDirectoryFileHelper, $stubFilesProvider->getProjectStubFiles());
613613

614614
$files = array_values(array_filter($files, static fn (string $file) => !$stubFilesExcluder->isExcludedFromAnalysing($file)));
615615

src/DependencyInjection/ValidateExcludePathsExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public function loadConfiguration(): void
2828
}
2929

3030
$errors = [];
31-
$noImplicitWildcard = $builder->parameters['featureToggles']['noImplicitWildcard'];
32-
if ($builder->parameters['__validate'] && $noImplicitWildcard) {
31+
if ($builder->parameters['__validate']) {
3332
$paths = [];
3433
if (array_key_exists('analyse', $excludePaths)) {
3534
$paths = $excludePaths['analyse'];

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public function loadConfiguration(): void
5959
return;
6060
}
6161

62-
$noImplicitWildcard = $builder->parameters['featureToggles']['noImplicitWildcard'];
63-
6462
/** @throws void */
6563
$parser = Llk::load(new Read(__DIR__ . '/../../resources/RegexGrammar.pp'));
6664
$reflectionProvider = new DummyReflectionProvider();
@@ -141,7 +139,7 @@ public function getRegistry(): OperatorTypeSpecifyingExtensionRegistry
141139

142140
$reportUnmatched = (bool) $builder->parameters['reportUnmatchedIgnoredErrors'];
143141

144-
if ($noImplicitWildcard && $reportUnmatched) {
142+
if ($reportUnmatched) {
145143
foreach ($ignoreErrors as $ignoreError) {
146144
if (!is_array($ignoreError)) {
147145
continue;

src/File/FileExcluder.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ final class FileExcluder
5252
public function __construct(
5353
FileHelper $fileHelper,
5454
array $analyseExcludes,
55-
private bool $noImplicitWildcard,
5655
)
5756
{
5857
foreach ($analyseExcludes as $exclude) {
@@ -68,18 +67,14 @@ public function __construct(
6867
if (self::isFnmatchPattern($normalized)) {
6968
$this->fnmatchAnalyseExcludes[] = $normalized;
7069
} else {
71-
if ($this->noImplicitWildcard) {
72-
if (is_file($normalized)) {
73-
$this->literalAnalyseFilesExcludes[] = $normalized;
74-
} elseif (is_dir($normalized)) {
75-
if (!$trailingDirSeparator) {
76-
$normalized .= DIRECTORY_SEPARATOR;
77-
}
78-
79-
$this->literalAnalyseDirectoryExcludes[] = $normalized;
70+
if (is_file($normalized)) {
71+
$this->literalAnalyseFilesExcludes[] = $normalized;
72+
} elseif (is_dir($normalized)) {
73+
if (!$trailingDirSeparator) {
74+
$normalized .= DIRECTORY_SEPARATOR;
8075
}
81-
} else {
82-
$this->literalAnalyseExcludes[] = $fileHelper->absolutizePath($normalized);
76+
77+
$this->literalAnalyseDirectoryExcludes[] = $normalized;
8378
}
8479
}
8580
}
@@ -99,16 +94,14 @@ public function isExcludedFromAnalysing(string $file): bool
9994
return true;
10095
}
10196
}
102-
if ($this->noImplicitWildcard) {
103-
foreach ($this->literalAnalyseDirectoryExcludes as $exclude) {
104-
if (str_starts_with($file, $exclude)) {
105-
return true;
106-
}
97+
foreach ($this->literalAnalyseDirectoryExcludes as $exclude) {
98+
if (str_starts_with($file, $exclude)) {
99+
return true;
107100
}
108-
foreach ($this->literalAnalyseFilesExcludes as $exclude) {
109-
if ($file === $exclude) {
110-
return true;
111-
}
101+
}
102+
foreach ($this->literalAnalyseFilesExcludes as $exclude) {
103+
if ($file === $exclude) {
104+
return true;
112105
}
113106
}
114107
foreach ($this->fnmatchAnalyseExcludes as $exclude) {

0 commit comments

Comments
 (0)