Skip to content

Commit 3d28220

Browse files
committed
Updated Rector to commit 5f6399efbb348a453bfc959c17885590155ae840
rectorphp/rector-src@5f6399e [CodeQuality] Handle crash on custom exception not autoloaded on ThrowWithPreviousExceptionRector (#8036)
1 parent 1a40588 commit 3d28220

7 files changed

Lines changed: 57 additions & 49 deletions

File tree

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ public function refactor(Node $node): ?Node
9191
if (!$node instanceof Throw_) {
9292
return null;
9393
}
94-
$isChanged = $this->refactorThrow($node, $caughtThrowableVariable);
95-
return $isChanged;
94+
$result = $this->refactorThrow($node, $caughtThrowableVariable);
95+
if ($result === null) {
96+
return null;
97+
}
98+
$isChanged = \true;
99+
return $result;
96100
});
97-
if (!(bool) $isChanged) {
101+
if (!$isChanged) {
98102
return null;
99103
}
100104
return $node;
@@ -122,6 +126,11 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
122126
/** @var Arg|null $messageArgument */
123127
$messageArgument = $new->args[0] ?? null;
124128
$shouldUseNamedArguments = $messageArgument instanceof Arg && $messageArgument->name instanceof Identifier;
129+
$hasCodeParameter = $this->hasParameter($new, 'code');
130+
$hasCodeArgument = $this->hasArgument($new, 'code');
131+
if (!isset($new->getArgs()[1]) && (!$hasCodeParameter || $hasCodeArgument)) {
132+
return null;
133+
}
125134
$hasChanged = \false;
126135
if (!isset($new->args[0])) {
127136
// get previous message
@@ -134,7 +143,7 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
134143
$hasChanged = \true;
135144
}
136145
if (!isset($new->getArgs()[1])) {
137-
if ($this->hasParameter($new, 'code') && !$this->hasArgument($new, 'code')) {
146+
if ($hasCodeParameter && !$hasCodeArgument) {
138147
// get previous code
139148
$new->args[1] = new Arg(new MethodCall($caughtThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
140149
$hasChanged = \true;
@@ -145,7 +154,7 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
145154
/** @var Arg $arg1 */
146155
$arg1 = $new->args[1];
147156
if ($arg1->name instanceof Identifier && $arg1->name->toString() === 'previous') {
148-
if ($this->hasParameter($new, 'code') && !$this->hasArgument($new, 'code')) {
157+
if ($hasCodeParameter && !$hasCodeArgument) {
149158
$new->args[1] = new Arg(new MethodCall($caughtThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
150159
$new->args[$exceptionArgumentPosition] = $arg1;
151160
$hasChanged = \true;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '5c5fd4d142902a90ac8a19ee71c4e1a5430102a4';
22+
public const PACKAGE_VERSION = '5f6399efbb348a453bfc959c17885590155ae840';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-06-11 17:04:48';
27+
public const RELEASE_DATE = '2026-06-11 23:23:23';
2828
/**
2929
* @var int
3030
*/

vendor/composer/installed.json

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,32 @@
6969
},
7070
{
7171
"name": "composer\/pcre",
72-
"version": "3.3.2",
73-
"version_normalized": "3.3.2.0",
72+
"version": "3.4.0",
73+
"version_normalized": "3.4.0.0",
7474
"source": {
7575
"type": "git",
7676
"url": "https:\/\/github.com\/composer\/pcre.git",
77-
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
77+
"reference": "d5a341b3fb61f3001970940afb1d332968a183ed"
7878
},
7979
"dist": {
8080
"type": "zip",
81-
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
82-
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
81+
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/d5a341b3fb61f3001970940afb1d332968a183ed",
82+
"reference": "d5a341b3fb61f3001970940afb1d332968a183ed",
8383
"shasum": ""
8484
},
8585
"require": {
8686
"php": "^7.4 || ^8.0"
8787
},
8888
"conflict": {
89-
"phpstan\/phpstan": "<1.11.10"
89+
"phpstan\/phpstan": "<2.2.2"
9090
},
9191
"require-dev": {
92-
"phpstan\/phpstan": "^1.12 || ^2",
93-
"phpstan\/phpstan-strict-rules": "^1 || ^2",
94-
"phpunit\/phpunit": "^8 || ^9"
92+
"phpstan\/phpstan": "^2",
93+
"phpstan\/phpstan-deprecation-rules": "^2",
94+
"phpstan\/phpstan-strict-rules": "^2",
95+
"phpunit\/phpunit": "^9"
9596
},
96-
"time": "2024-11-12T16:29:46+00:00",
97+
"time": "2026-06-07T11:47:49+00:00",
9798
"type": "library",
9899
"extra": {
99100
"phpstan": {
@@ -131,7 +132,7 @@
131132
],
132133
"support": {
133134
"issues": "https:\/\/github.com\/composer\/pcre\/issues",
134-
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.3.2"
135+
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.4.0"
135136
},
136137
"funding": [
137138
{
@@ -141,10 +142,6 @@
141142
{
142143
"url": "https:\/\/github.com\/composer",
143144
"type": "github"
144-
},
145-
{
146-
"url": "https:\/\/tidelift.com\/funding\/github\/packagist\/composer\/composer",
147-
"type": "tidelift"
148145
}
149146
],
150147
"install-path": ".\/pcre"

vendor/composer/installed.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

vendor/composer/pcre/composer.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
"php": "^7.4 || ^8.0"
2121
},
2222
"require-dev": {
23-
"phpunit\/phpunit": "^8 || ^9",
24-
"phpstan\/phpstan": "^1.12 || ^2",
25-
"phpstan\/phpstan-strict-rules": "^1 || ^2"
23+
"phpunit\/phpunit": "^9",
24+
"phpstan\/phpstan": "^2",
25+
"phpstan\/phpstan-strict-rules": "^2",
26+
"phpstan\/phpstan-deprecation-rules": "^2"
2627
},
2728
"conflict": {
28-
"phpstan\/phpstan": "<1.11.10"
29+
"phpstan\/phpstan": "<2.2.2"
2930
},
3031
"autoload": {
3132
"psr-4": {
@@ -48,7 +49,10 @@
4849
}
4950
},
5051
"scripts": {
51-
"test": "@php vendor\/bin\/phpunit",
52+
"test": [
53+
"@php vendor\/bin\/phpunit",
54+
"@php vendor\/bin\/phpunit --testsuite phpstan"
55+
],
5256
"phpstan": "@php phpstan analyse"
5357
}
5458
}

vendor/composer/pcre/src/PHPStan/PregMatchTypeSpecifyingExtension.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,33 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod
4747
{
4848
$args = $node->getArgs();
4949
$patternArg = $args[0] ?? null;
50+
$subjectArg = $args[1] ?? null;
5051
$matchesArg = $args[2] ?? null;
5152
$flagsArg = $args[3] ?? null;
52-
if ($patternArg === null || $matchesArg === null) {
53-
return new SpecifiedTypes();
53+
$subjectTypes = new SpecifiedTypes();
54+
if ($patternArg === null) {
55+
return $subjectTypes;
56+
}
57+
if ($subjectArg !== null && $context->true() && $scope->getType($subjectArg->value)->isString()->yes()) {
58+
$subjectType = $this->regexShapeMatcher->matchSubjectExpr($patternArg->value, $scope);
59+
if ($subjectType !== null) {
60+
$subjectTypes = $this->typeSpecifier->create($subjectArg->value, $subjectType, $context, $scope)->setRootExpr($node);
61+
}
62+
}
63+
if ($matchesArg === null) {
64+
return $subjectTypes;
5465
}
5566
$flagsType = PregMatchFlags::getType($flagsArg, $scope);
5667
if ($flagsType === null) {
57-
return new SpecifiedTypes();
68+
return $subjectTypes;
5869
}
5970
if (stripos($methodReflection->getName(), 'matchAll') !== \false) {
6071
$matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
6172
} else {
6273
$matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
6374
}
6475
if ($matchedType === null) {
65-
return new SpecifiedTypes();
76+
return $subjectTypes;
6677
}
6778
if (in_array($methodReflection->getName(), ['matchStrictGroups', 'isMatchStrictGroups', 'matchAllStrictGroups', 'isMatchAllStrictGroups'], \true)) {
6879
$matchedType = PregMatchFlags::removeNullFromMatches($matchedType);
@@ -72,20 +83,7 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod
7283
$overwrite = \true;
7384
$context = $context->negate();
7485
}
75-
// @phpstan-ignore function.alreadyNarrowedType
76-
if (method_exists('PHPStan\Analyser\SpecifiedTypes', 'setRootExpr')) {
77-
$typeSpecifier = $this->typeSpecifier->create($matchesArg->value, $matchedType, $context, $scope)->setRootExpr($node);
78-
return $overwrite ? $typeSpecifier->setAlwaysOverwriteTypes() : $typeSpecifier;
79-
}
80-
// @phpstan-ignore arguments.count
81-
return $this->typeSpecifier->create(
82-
$matchesArg->value,
83-
$matchedType,
84-
$context,
85-
// @phpstan-ignore argument.type
86-
$overwrite,
87-
$scope,
88-
$node
89-
);
86+
$specifiedTypes = $this->typeSpecifier->create($matchesArg->value, $matchedType, $context, $scope)->setRootExpr($node);
87+
return $subjectTypes->unionWith($overwrite ? $specifiedTypes->setAlwaysOverwriteTypes() : $specifiedTypes);
9088
}
9189
}

vendor/composer/pcre/src/Preg.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private static function checkSetOrder(int $flags): void
352352
* @return array<int|string, string>
353353
* @throws UnexpectedNullMatchException
354354
*/
355-
private static function enforceNonNullMatches(string $pattern, array $matches, string $variantMethod)
355+
private static function enforceNonNullMatches(string $pattern, array $matches, string $variantMethod): array
356356
{
357357
foreach ($matches as $group => $match) {
358358
if (is_string($match) || is_array($match) && is_string($match[0])) {
@@ -368,7 +368,7 @@ private static function enforceNonNullMatches(string $pattern, array $matches, s
368368
* @return array<int|string, list<string>>
369369
* @throws UnexpectedNullMatchException
370370
*/
371-
private static function enforceNonNullMatchAll(string $pattern, array $matches, string $variantMethod)
371+
private static function enforceNonNullMatchAll(string $pattern, array $matches, string $variantMethod): array
372372
{
373373
foreach ($matches as $group => $groupMatches) {
374374
foreach ($groupMatches as $match) {

0 commit comments

Comments
 (0)