Skip to content

Commit 6a7f7a3

Browse files
committed
keep || and () exceptions for ignore rules validations
1 parent e10c993 commit 6a7f7a3

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/Command/IgnoredRegexValidator.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PHPStan\Type\VerbosityLevel;
1414
use function count;
1515
use function str_contains;
16-
use function str_starts_with;
1716
use function strrpos;
1817
use function substr;
1918

@@ -34,19 +33,17 @@ public function validate(string $regex): IgnoredRegexValidatorResult
3433
try {
3534
/** @var TreeNode $ast */
3635
$ast = $this->parser->parse($regex);
37-
} catch (Exception $e) {
38-
if (str_starts_with($e->getMessage(), 'Unexpected token "|" (alternation) at line 1')) {
39-
return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|');
40-
}
41-
if (
42-
str_contains($regex, '()')
43-
&& str_starts_with($e->getMessage(), 'Unexpected token ")" (_capturing) at line 1')
44-
) {
45-
return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)');
46-
}
36+
} catch (Exception) {
4737
return new IgnoredRegexValidatorResult([], false, false);
4838
}
4939

40+
if (str_contains($regex, '||')) {
41+
return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|');
42+
}
43+
if (str_contains($regex, '()')) {
44+
return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)');
45+
}
46+
5047
return new IgnoredRegexValidatorResult(
5148
$this->getIgnoredTypes($ast),
5249
$this->hasAnchorsInTheMiddle($ast),

tests/PHPStan/Command/IgnoredRegexValidatorTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ public function dataValidate(): array
104104
'~Result of || is always true.~',
105105
[],
106106
false,
107-
false,
107+
true,
108108
],
109109
[
110110
'#Method PragmaRX\Notified\Data\Repositories\Notified::firstOrCreateByEvent() should return PragmaRX\Notified\Data\Models\Notified but returns Illuminate\Database\Eloquent\Model|null#',
111-
[
112-
'null' => 'null',
113-
],
114-
false,
111+
[],
115112
false,
113+
true,
116114
],
117115
];
118116
}

0 commit comments

Comments
 (0)