Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 12, 2024
2 parents c98c498 + ebb81df commit 5c4fc70
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8 || ^9",
"phpstan/phpstan": "^1.11.10",
"phpstan/phpstan-strict-rules": "^1.1"
"phpstan/phpstan": "^1.12 || ^2",
"phpstan/phpstan-strict-rules": "^1 || ^2"
},
"conflict": {
"phpstan/phpstan": "<1.11.10"
Expand Down
63 changes: 42 additions & 21 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,106 +1,127 @@
parameters:
ignoreErrors:
-
message: "#^Creating new PHPStan\\\\Reflection\\\\Native\\\\NativeParameterReflection is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
message: '#^Creating new PHPStan\\Reflection\\Native\\NativeParameterReflection is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
identifier: phpstanApi.constructor
count: 1
path: src/PHPStan/PregReplaceCallbackClosureTypeExtension.php

-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, \\(callable\\(array\\<int\\|string, array\\{string\\|null, int\\<\\-1, max\\>\\}\\>\\)\\: string\\)\\|\\(callable\\(array\\<int\\|string, string\\|null\\>\\)\\: string\\) given\\.$#"
message: '#^Parameter \#2 \$callback of function preg_replace_callback expects callable\(array\<string\>\)\: string, \(callable\(array\<int\|string, array\{string\|null, int\<\-1, max\>\}\>\)\: string\)\|\(callable\(array\<int\|string, string\|null\>\)\: string\) given\.$#'
identifier: argument.type
count: 1
path: src/Preg.php

-
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAllWithOffsets\\(\\) expects array\\<int\\|string, list\\<array\\{string\\|null, int\\<\\-1, max\\>\\}\\>\\>, array given\\.$#"
message: '#^Parameter &\$matches @param\-out type of method Composer\\Pcre\\Preg\:\:matchAllWithOffsets\(\) expects array\<int\|string, list\<array\{string\|null, int\<\-1, max\>\}\>\>, array\<mixed\> given\.$#'
identifier: paramOut.type
count: 1
path: src/Preg.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/GrepTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/IsMatchAllTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/IsMatchAllWithOffsetsTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/IsMatchTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/IsMatchWithOffsetsTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/MatchAllTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/MatchTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/ReplaceCallbackArrayTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/ReplaceCallbackTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/ReplaceTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/SplitTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/PregTests/SplitWithOffsetsTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/IsMatchTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/MatchAllTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/MatchTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/ReplaceCallbackArrayTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/ReplaceCallbackTest.php

-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
identifier: regexp.pattern
count: 2
path: tests/RegexTests/ReplaceTest.php
16 changes: 16 additions & 0 deletions src/PHPStan/PregMatchTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,26 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod
$context = $context->negate();
}

// @phpstan-ignore function.alreadyNarrowedType, function.impossibleType
if (method_exists('PHPStan\Analyser\SpecifiedTypes', 'setRootExpr')) {

Check failure on line 97 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

No error with identifier function.impossibleType is reported on line 97.

Check failure on line 97 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

No error with identifier function.impossibleType is reported on line 97.
// @phpstan-ignore method.notFound
$typeSpecifier = $this->typeSpecifier->create(

Check failure on line 99 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

No error with identifier method.notFound is reported on line 99.

Check failure on line 99 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

No error with identifier method.notFound is reported on line 99.
$matchesArg->value,
$matchedType,
$context,
// @phpstan-ignore argument.type
$scope

Check failure on line 104 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

No error with identifier argument.type is reported on line 104.

Check failure on line 104 in src/PHPStan/PregMatchTypeSpecifyingExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

No error with identifier argument.type is reported on line 104.
)->setRootExpr($node);

return $overwrite ? $typeSpecifier->setAlwaysOverwriteTypes() : $typeSpecifier;
}

// @phpstan-ignore arguments.count
return $this->typeSpecifier->create(
$matchesArg->value,
$matchedType,
$context,
// @phpstan-ignore argument.type
$overwrite,
$scope,
$node
Expand Down
5 changes: 0 additions & 5 deletions src/PcreException.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ private static function pcreLastErrorMessage($code)
return preg_last_error_msg();
}

// older php versions did not set the code properly in all cases
if (PHP_VERSION_ID < 70201 && $code === 0) {
return 'UNDEFINED_ERROR';
}

$constants = get_defined_constants(true);
if (!isset($constants['pcre']) || !is_array($constants['pcre'])) {
return 'UNDEFINED_ERROR';
Expand Down
14 changes: 6 additions & 8 deletions tests/PHPStanTests/InvalidRegexPatternRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,29 @@ protected function getRule(): \PHPStan\Rules\Rule

public function testRule(): void
{
$missing = PHP_VERSION_ID < 70300 ? ')' : 'closing parenthesis';

$this->analyse([__DIR__ . '/fixtures/invalid-patterns.php'], [
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
11,
],
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
13,
],
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
15,
],
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
17,
],
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
19,
],
[
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
21,
],
]);
Expand Down

0 comments on commit 5c4fc70

Please sign in to comment.