Skip to content

Commit b474c7a

Browse files
committed
fix php 7.2
1 parent dd036c1 commit b474c7a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Rules/Regexp/RegularExpressionPatternRule.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use PHPStan\Type\Regex\RegexExpressionHelper;
1414
use function in_array;
1515
use function sprintf;
16-
use function str_contains;
1716
use function str_starts_with;
17+
use function stripos;
1818
use function strlen;
1919
use function strpos;
2020
use function strtolower;
@@ -128,7 +128,10 @@ private function validatePattern(string $pattern): ?string
128128
try {
129129
Strings::match('', $pattern);
130130
} catch (RegexpException $e) {
131-
if (str_contains($e->getMessage(), 'UTF-8 error')) {
131+
if (
132+
stripos($e->getMessage(), 'Compilation failed') !== false
133+
&& stripos($e->getMessage(), 'UTF-8') !== false
134+
) {
132135
$patternPos = strpos($e->getMessage(), 'pattern:');
133136
if ($patternPos === false) {
134137
throw new ShouldNotHappenException();

tests/PHPStan/Rules/Regexp/RegularExpressionPatternRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ public function dataArrayShapePatterns(): iterable
334334

335335
public function testBug12629(): void
336336
{
337+
if (PHP_VERSION_ID < 70300) {
338+
$this->markTestSkipped('This test requires PHP >= 7.3.0');
339+
}
340+
337341
$this->analyse(
338342
[__DIR__ . '/data/bug-12629.php'],
339343
[

0 commit comments

Comments
 (0)