diff --git a/src/Command/IgnoredRegexValidator.php b/src/Command/IgnoredRegexValidator.php index 613779b2e64..e54489bc132 100644 --- a/src/Command/IgnoredRegexValidator.php +++ b/src/Command/IgnoredRegexValidator.php @@ -35,18 +35,16 @@ public function validate(string $regex): IgnoredRegexValidatorResult /** @var TreeNode $ast */ $ast = $this->parser->parse($regex); } catch (Exception $e) { - if (str_starts_with($e->getMessage(), 'Unexpected token "|" (alternation) at line 1')) { - return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|'); - } - if ( - str_contains($regex, '()') - && str_starts_with($e->getMessage(), 'Unexpected token ")" (_capturing) at line 1') - ) { - return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)'); - } return new IgnoredRegexValidatorResult([], false, false); } + if (str_contains($regex, '||')) { + return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|'); + } + if (str_contains($regex, '()')) { + return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)'); + } + return new IgnoredRegexValidatorResult( $this->getIgnoredTypes($ast), $this->hasAnchorsInTheMiddle($ast), diff --git a/tests/PHPStan/Command/IgnoredRegexValidatorTest.php b/tests/PHPStan/Command/IgnoredRegexValidatorTest.php index 4dd4a784355..98a6dc58cb7 100644 --- a/tests/PHPStan/Command/IgnoredRegexValidatorTest.php +++ b/tests/PHPStan/Command/IgnoredRegexValidatorTest.php @@ -104,15 +104,13 @@ public function dataValidate(): array '~Result of || is always true.~', [], false, - false, + true, ], [ '#Method PragmaRX\Notified\Data\Repositories\Notified::firstOrCreateByEvent() should return PragmaRX\Notified\Data\Models\Notified but returns Illuminate\Database\Eloquent\Model|null#', - [ - 'null' => 'null', - ], - false, + [], false, + true, ], ]; }