Skip to content

Commit

Permalink
Add inside array item marker to remove PARENT_NODE from downgrade (#4447
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TomasVotruba committed Jul 9, 2023
1 parent 919f5d4 commit 14081fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Expand Up @@ -321,4 +321,9 @@ final class AttributeKey
* @var string
*/
public const INSIDE_ARRAY_DIM_FETCH = 'inside_array_dim_fetch';

/**
* @var string
*/
public const INSIDE_ARRAY_ITEM = 'inside_array_item';
}
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -51,6 +52,10 @@ public function enterNode(Node $node): ?Node
$node->var->setAttribute(AttributeKey::INSIDE_ARRAY_DIM_FETCH, true);
}

if ($node instanceof ArrayItem) {
$node->value->setAttribute(AttributeKey::INSIDE_ARRAY_ITEM, true);
}

if ($node instanceof Isset_ || $node instanceof Unset_) {
$this->processContextInIssetOrUnset($node);
return null;
Expand Down
2 changes: 0 additions & 2 deletions rules/Php72/NodeFactory/AnonymousFunctionFactory.php
Expand Up @@ -9,7 +9,6 @@
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ClosureUse;
Expand All @@ -27,7 +26,6 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\UnionType;
use PHPStan\Reflection\FunctionVariantWithPhpDocs;
Expand Down
4 changes: 2 additions & 2 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Expand Up @@ -254,7 +254,7 @@ private function isClassToInterfaceValidChange(Name $name, string $newClassName)
return $this->isValidClassNameChange($name, $classReflection);
}

if (!$classReflection->isInterface()) {
if (! $classReflection->isInterface()) {
return $this->isValidClassNameChange($name, $classReflection);
}

Expand Down Expand Up @@ -341,7 +341,7 @@ private function isValidClassNameChange(Name $name, ClassReflection $classReflec

if ($name->getAttribute(AttributeKey::IS_CLASS_IMPLEMENT) === true) {
// is interface to class?
return ! $classReflection->isClass();
return ! $classReflection->isClass();
}

return true;
Expand Down

0 comments on commit 14081fe

Please sign in to comment.