Skip to content

Commit d40c7c4

Browse files
committed
Updated Rector to commit e4708c58a4ddb167511d61dff636d9edcdd0e805
rectorphp/rector-src@e4708c5 [CodeQuality] Ensure check native array type on Foreach* rules (#6222)
1 parent c050377 commit d40c7c4

File tree

5 files changed

+6
-17
lines changed

5 files changed

+6
-17
lines changed

rules/CodeQuality/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function shouldSkip(Foreach_ $foreach, array $emptyArrayVariables) : boo
132132
if (!$assignVariableExpr instanceof Expr) {
133133
return \true;
134134
}
135-
$foreachedExprType = $this->getType($foreach->expr);
135+
$foreachedExprType = $this->nodeTypeResolver->getNativeType($foreach->expr);
136136
// only arrays, not traversable/iterable
137137
if (!$foreachedExprType->isArray()->yes()) {
138138
return \true;

rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PhpParser\Node\Stmt\If_;
1515
use PhpParser\Node\Stmt\Return_;
1616
use PhpParser\NodeFinder;
17-
use PHPStan\Type\ObjectType;
1817
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1918
use Rector\NodeManipulator\BinaryOpManipulator;
2019
use Rector\Php71\ValueObject\TwoNodeMatch;
@@ -151,8 +150,7 @@ private function shouldSkipForeach(Foreach_ $foreach) : bool
151150
if (!$foreach->stmts[0] instanceof If_) {
152151
return \true;
153152
}
154-
$foreachValueStaticType = $this->getType($foreach->expr);
155-
return $foreachValueStaticType instanceof ObjectType;
153+
return !$this->nodeTypeResolver->getNativeType($foreach->expr)->isArray()->yes();
156154
}
157155
private function shouldSkipIf(If_ $if) : bool
158156
{

rules/CodeQuality/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpParser\Node\Expr\ArrayItem;
1010
use PhpParser\Node\Expr\Variable;
1111
use PhpParser\Node\Stmt\Foreach_;
12-
use PHPStan\Type\ObjectType;
1312
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1413
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
1514
use Rector\NodeManipulator\StmtsManipulator;
@@ -95,7 +94,7 @@ public function refactor(Node $node) : ?Node
9594
if (!$stmt->keyVar instanceof Expr) {
9695
continue;
9796
}
98-
if (!$this->isArrayType($stmt->expr)) {
97+
if (!$this->nodeTypeResolver->getNativeType($stmt->expr)->isArray()->yes()) {
9998
continue;
10099
}
101100
// special case of nested array items
@@ -186,12 +185,4 @@ private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach, Expr $keyV
186185
$foreach->keyVar = null;
187186
$foreach->expr = $this->nodeFactory->createFuncCall('array_keys', [$foreach->expr]);
188187
}
189-
private function isArrayType(Expr $expr) : bool
190-
{
191-
$exprType = $this->getType($expr);
192-
if ($exprType instanceof ObjectType) {
193-
return \false;
194-
}
195-
return $exprType->isArray()->yes();
196-
}
197188
}

src/Application/VersionResolver.php

+2-2
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 = '69a3e31e443dc9610e675ee2ac380cd8f6581a4c';
22+
public const PACKAGE_VERSION = 'e4708c58a4ddb167511d61dff636d9edcdd0e805';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-08-06 20:52:34';
27+
public const RELEASE_DATE = '2024-08-06 21:18:42';
2828
/**
2929
* @var int
3030
*/

vendor/scoper-autoload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Restore the backup and ensure the excluded files are properly marked as loaded
1515
$GLOBALS['__composer_autoload_files'] = \array_merge(
1616
$existingComposerAutoloadFiles,
17-
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
17+
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
1818
);
1919

2020
return $loader;

0 commit comments

Comments
 (0)