Skip to content
Snippets Groups Projects
Commit 50327d94 authored by David Prévot's avatar David Prévot
Browse files

New upstream version 3.3.2

parents 917a6ed9 b2bed473
No related branches found
No related tags found
No related merge requests found
Pipeline #764163 failed
......@@ -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"
......
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
......@@ -93,10 +93,24 @@ final class PregMatchTypeSpecifyingExtension implements StaticMethodTypeSpecifyi
$context = $context->negate();
}
// @phpstan-ignore function.alreadyNarrowedType
if (method_exists('PHPStan\Analyser\SpecifiedTypes', 'setRootExpr')) {
$typeSpecifier = $this->typeSpecifier->create(
$matchesArg->value,
$matchedType,
$context,
$scope
)->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
......
......@@ -39,13 +39,8 @@ class PcreException extends \RuntimeException
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'])) {
if (!isset($constants['pcre']) || !is_array($constants['pcre'])) {
return 'UNDEFINED_ERROR';
}
......
......@@ -31,31 +31,29 @@ class InvalidRegexPatternRuleTest extends RuleTestCase
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,
],
]);
......
......@@ -16,33 +16,33 @@ function doMatch(string $s): void
assertType('array{}|array{string}', $matches);
if (Preg::match('/Price: (£|€)\d+/', $s, $matches)) {
assertType('array{string, non-empty-string}', $matches);
assertType('array{string, \'£\'|\'€\'}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, non-empty-string}', $matches);
assertType('array{}|array{string, \'£\'|\'€\'}', $matches);
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) {
assertType('array{string, non-empty-string|null}', $matches);
assertType('array{string, \'£\'|\'€\'|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, non-empty-string|null}', $matches);
assertType('array{}|array{string, \'£\'|\'€\'|null}', $matches);
// passing the PREG_UNMATCHED_AS_NULL should change nothing compared to above as it is always set
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
assertType('array{string, non-empty-string|null}', $matches);
assertType('array{string, \'£\'|\'€\'|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, non-empty-string|null}', $matches);
assertType('array{}|array{string, \'£\'|\'€\'|null}', $matches);
if (Preg::isMatch('/Price: (?<currency>£|€)\d+/', $s, $matches)) {
assertType('array{0: string, currency: non-empty-string, 1: non-empty-string}', $matches);
assertType('array{0: string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{0: string, currency: non-empty-string, 1: non-empty-string}', $matches);
assertType('array{}|array{0: string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches);
}
function doMatchStrictGroups(string $s): void
......@@ -55,18 +55,18 @@ function doMatchStrictGroups(string $s): void
assertType('array{}|array{string}', $matches);
if (Preg::matchStrictGroups('/Price: (£|€)\d+/', $s, $matches)) {
assertType('array{string, non-empty-string}', $matches);
assertType('array{string, \'£\'|\'€\'}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, non-empty-string}', $matches);
assertType('array{}|array{string, \'£\'|\'€\'}', $matches);
if (Preg::isMatchStrictGroups('/Price: (?<test>£|€)\d+/', $s, $matches)) {
assertType('array{0: string, test: non-empty-string, 1: non-empty-string}', $matches);
assertType('array{0: string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{0: string, test: non-empty-string, 1: non-empty-string}', $matches);
assertType('array{}|array{0: string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches);
}
function doMatchStrictGroupsUnsafe(string $s): void
......@@ -98,21 +98,21 @@ function doMatchAllStrictGroups(string $s): void
assertType('array{}|array{list<string>}', $matches);
if (Preg::matchAllStrictGroups('/Price: (£|€)\d+/', $s, $matches)) {
assertType('array{list<string>, list<non-empty-string>}', $matches);
assertType('array{list<string>, list<\'£\'|\'€\'>}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{list<string>, list<non-empty-string>}', $matches);
assertType('array{}|array{list<string>, list<\'£\'|\'€\'>}', $matches);
if (Preg::isMatchAllStrictGroups('/Price: (?<test>£|€)\d+/', $s, $matches)) {
assertType('array{0: list<string>, test: list<non-empty-string>, 1: list<non-empty-string>}', $matches);
assertType('array{0: list<string>, test: list<\'£\'|\'€\'>, 1: list<\'£\'|\'€\'>}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{0: list<string>, test: list<non-empty-string>, 1: list<non-empty-string>}', $matches);
assertType('array{}|array{0: list<string>, test: list<\'£\'|\'€\'>, 1: list<\'£\'|\'€\'>}', $matches);
if (Preg::isMatchAllStrictGroups('/Price: (?<test>£|€)?\d+/', $s, $matches)) {
assertType('array{0: list<string>, test: list<non-empty-string>, 1: list<non-empty-string>}', $matches);
assertType('array{0: list<string>, test: list<\'£\'|\'€\'>, 1: list<\'£\'|\'€\'>}', $matches);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment