Skip to content

Commit cd5808f

Browse files
committed
Updated Rector to commit 992f3ff9d162c8ef648427d19f557574591b8580
rectorphp/rector-src@992f3ff [CodeQuality][Php84] Handle crash on ForeachToArrayFindRector+OptionalParametersAfterRequiredRector (#7033)
1 parent 9a07852 commit cd5808f

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,27 @@ public function getNodeTypes() : array
8888
*/
8989
public function refactor(Node $node)
9090
{
91-
$scope = ScopeFetcher::fetch($node);
9291
if ($node instanceof ClassMethod || $node instanceof Function_) {
93-
return $this->refactorClassMethodOrFunction($node, $scope);
92+
return $this->refactorClassMethodOrFunction($node);
9493
}
9594
if ($node instanceof New_) {
96-
return $this->refactorNew($node, $scope);
95+
return $this->refactorNew($node);
9796
}
98-
return $this->refactorMethodCallOrFuncCall($node, $scope);
97+
return $this->refactorMethodCallOrFuncCall($node);
9998
}
10099
/**
101100
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
102101
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|null
103102
*/
104-
private function refactorClassMethodOrFunction($node, Scope $scope)
103+
private function refactorClassMethodOrFunction($node)
105104
{
106105
if ($node->params === []) {
107106
return null;
108107
}
109108
if ($node->getAttribute(self::HAS_SWAPPED_PARAMS, \false) === \true) {
110109
return null;
111110
}
111+
$scope = ScopeFetcher::fetch($node);
112112
if ($node instanceof ClassMethod) {
113113
$reflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($node, $scope);
114114
} else {
@@ -125,7 +125,7 @@ private function refactorClassMethodOrFunction($node, Scope $scope)
125125
$node->setAttribute(self::HAS_SWAPPED_PARAMS, \true);
126126
return $node;
127127
}
128-
private function refactorNew(New_ $new, Scope $scope) : ?New_
128+
private function refactorNew(New_ $new) : ?New_
129129
{
130130
if ($new->args === []) {
131131
return null;
@@ -137,6 +137,7 @@ private function refactorNew(New_ $new, Scope $scope) : ?New_
137137
if (!$methodReflection instanceof MethodReflection) {
138138
return null;
139139
}
140+
$scope = ScopeFetcher::fetch($new);
140141
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $new, $scope);
141142
if ($expectedArgOrParamOrder === null) {
142143
return null;
@@ -148,7 +149,7 @@ private function refactorNew(New_ $new, Scope $scope) : ?New_
148149
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $node
149150
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall|null
150151
*/
151-
private function refactorMethodCallOrFuncCall($node, Scope $scope)
152+
private function refactorMethodCallOrFuncCall($node)
152153
{
153154
if ($node->isFirstClassCallable()) {
154155
return null;
@@ -157,6 +158,7 @@ private function refactorMethodCallOrFuncCall($node, Scope $scope)
157158
if (!$reflection instanceof MethodReflection && !$reflection instanceof FunctionReflection) {
158159
return null;
159160
}
161+
$scope = ScopeFetcher::fetch($node);
160162
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($reflection, $node, $scope);
161163
if ($expectedArgOrParamOrder === null) {
162164
return null;
@@ -184,6 +186,7 @@ private function resolveExpectedArgParamOrderIfDifferent($reflection, $node, Sco
184186
if ($reflection instanceof FunctionReflection && $this->vendorLocationDetector->detectFunctionReflection($reflection)) {
185187
return null;
186188
}
189+
$scope = ScopeFetcher::fetch($node);
187190
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($reflection, $node, $scope);
188191
$expectedParameterReflections = $this->requireOptionalParamResolver->resolveFromParametersAcceptor($parametersAcceptor);
189192
if ($expectedParameterReflections === $parametersAcceptor->getParameters()) {

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 = '4c3ec6c5d0f59e7f82da2edf7331db88b2cbfef9';
22+
public const PACKAGE_VERSION = '992f3ff9d162c8ef648427d19f557574591b8580';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-06-30 04:22:51';
27+
public const RELEASE_DATE = '2025-06-30 15:53:50';
2828
/**
2929
* @var int
3030
*/

src/ProcessAnalyzer/RectifiedAnalyzer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Stmt;
88
use Rector\Contract\Rector\RectorInterface;
9+
use Rector\NodeAnalyzer\ScopeAnalyzer;
910
use Rector\NodeTypeResolver\Node\AttributeKey;
1011
/**
1112
* This service verify if the Node:
@@ -17,6 +18,14 @@
1718
*/
1819
final class RectifiedAnalyzer
1920
{
21+
/**
22+
* @readonly
23+
*/
24+
private ScopeAnalyzer $scopeAnalyzer;
25+
public function __construct(ScopeAnalyzer $scopeAnalyzer)
26+
{
27+
$this->scopeAnalyzer = $scopeAnalyzer;
28+
}
2029
/**
2130
* @param class-string<RectorInterface> $rectorClass
2231
*/
@@ -66,9 +75,9 @@ private function isJustReprintedOverlappedTokenStart(Node $node, ?Node $original
6675
if ($startTokenPos >= 0) {
6776
return \true;
6877
}
69-
if ($node instanceof Stmt) {
70-
return !\in_array(AttributeKey::SCOPE, \array_keys($node->getAttributes()), \true);
78+
if (!$this->scopeAnalyzer->isRefreshable($node)) {
79+
return \false;
7180
}
72-
return $node->getAttributes() === [];
81+
return !\in_array(AttributeKey::SCOPE, \array_keys($node->getAttributes()), \true);
7382
}
7483
}

0 commit comments

Comments
 (0)