mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit da2dd66088e15a5c182a047726933306a8fdc28c
da2dd66088
RemoveUnusedNonEmptyArrayBeforeForeachRector: skip array dim fetch (#5166)
This commit is contained in:
parent
4c4ad160dd
commit
9f158ba7a8
|
@ -115,15 +115,8 @@ CODE_SAMPLE
|
|||
/** @var Foreach_ $foreach */
|
||||
$foreach = $if->stmts[0];
|
||||
$foreachExpr = $foreach->expr;
|
||||
if ($foreachExpr instanceof Variable) {
|
||||
$variableName = $this->nodeNameResolver->getName($foreachExpr);
|
||||
if (\is_string($variableName) && $this->reservedKeywordAnalyzer->isNativeVariable($variableName)) {
|
||||
return \false;
|
||||
}
|
||||
$ifType = $scope->getNativeType($foreachExpr);
|
||||
if (!$ifType->isArray()->yes()) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->shouldSkipForeachExpr($foreachExpr, $scope)) {
|
||||
return \false;
|
||||
}
|
||||
$ifCond = $if->cond;
|
||||
if ($ifCond instanceof BooleanAnd) {
|
||||
|
@ -190,4 +183,25 @@ CODE_SAMPLE
|
|||
$stmt->setAttribute(AttributeKey::COMMENTS, $comments);
|
||||
return $stmt;
|
||||
}
|
||||
private function shouldSkipForeachExpr(Expr $foreachExpr, Scope $scope) : bool
|
||||
{
|
||||
if ($foreachExpr instanceof Expr\ArrayDimFetch && $foreachExpr->dim !== null) {
|
||||
$exprType = $this->nodeTypeResolver->getNativeType($foreachExpr->var);
|
||||
$dimType = $this->nodeTypeResolver->getNativeType($foreachExpr->dim);
|
||||
if (!$exprType->hasOffsetValueType($dimType)->yes()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
if ($foreachExpr instanceof Variable) {
|
||||
$variableName = $this->nodeNameResolver->getName($foreachExpr);
|
||||
if (\is_string($variableName) && $this->reservedKeywordAnalyzer->isNativeVariable($variableName)) {
|
||||
return \true;
|
||||
}
|
||||
$ifType = $scope->getNativeType($foreachExpr);
|
||||
if (!$ifType->isArray()->yes()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'c639ef8ad9213881d4fe08554f090934bc5dda07';
|
||||
public const PACKAGE_VERSION = 'da2dd66088e15a5c182a047726933306a8fdc28c';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-10-14 19:48:51';
|
||||
public const RELEASE_DATE = '2023-10-14 20:22:50';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue