Skip to content

Commit

Permalink
Updated Rector to commit e4708c58a4ddb167511d61dff636d9edcdd0e805
Browse files Browse the repository at this point in the history
rectorphp/rector-src@e4708c5 [CodeQuality] Ensure check native array type on Foreach* rules (#6222)
  • Loading branch information
TomasVotruba committed Aug 6, 2024
1 parent c050377 commit d40c7c4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function shouldSkip(Foreach_ $foreach, array $emptyArrayVariables) : boo
if (!$assignVariableExpr instanceof Expr) {
return \true;
}
$foreachedExprType = $this->getType($foreach->expr);
$foreachedExprType = $this->nodeTypeResolver->getNativeType($foreach->expr);
// only arrays, not traversable/iterable
if (!$foreachedExprType->isArray()->yes()) {
return \true;
Expand Down
4 changes: 1 addition & 3 deletions rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeFinder;
use PHPStan\Type\ObjectType;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeManipulator\BinaryOpManipulator;
use Rector\Php71\ValueObject\TwoNodeMatch;
Expand Down Expand Up @@ -151,8 +150,7 @@ private function shouldSkipForeach(Foreach_ $foreach) : bool
if (!$foreach->stmts[0] instanceof If_) {
return \true;
}
$foreachValueStaticType = $this->getType($foreach->expr);
return $foreachValueStaticType instanceof ObjectType;
return !$this->nodeTypeResolver->getNativeType($foreach->expr)->isArray()->yes();
}
private function shouldSkipIf(If_ $if) : bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Foreach_;
use PHPStan\Type\ObjectType;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
use Rector\NodeManipulator\StmtsManipulator;
Expand Down Expand Up @@ -95,7 +94,7 @@ public function refactor(Node $node) : ?Node
if (!$stmt->keyVar instanceof Expr) {
continue;
}
if (!$this->isArrayType($stmt->expr)) {
if (!$this->nodeTypeResolver->getNativeType($stmt->expr)->isArray()->yes()) {
continue;
}
// special case of nested array items
Expand Down Expand Up @@ -186,12 +185,4 @@ private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach, Expr $keyV
$foreach->keyVar = null;
$foreach->expr = $this->nodeFactory->createFuncCall('array_keys', [$foreach->expr]);
}
private function isArrayType(Expr $expr) : bool
{
$exprType = $this->getType($expr);
if ($exprType instanceof ObjectType) {
return \false;
}
return $exprType->isArray()->yes();
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '69a3e31e443dc9610e675ee2ac380cd8f6581a4c';
public const PACKAGE_VERSION = 'e4708c58a4ddb167511d61dff636d9edcdd0e805';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-06 20:52:34';
public const RELEASE_DATE = '2024-08-06 21:18:42';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/scoper-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Restore the backup and ensure the excluded files are properly marked as loaded
$GLOBALS['__composer_autoload_files'] = \array_merge(
$existingComposerAutoloadFiles,
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
);

return $loader;
Expand Down

0 comments on commit d40c7c4

Please sign in to comment.