Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename Attribute to AttributeKey to prevent duplicated names with other projects #1314

Merged
merged 1 commit into from Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 30 additions & 30 deletions .phpstorm.meta.php
Expand Up @@ -11,39 +11,39 @@
expectedArguments(
\PhpParser\Node::getAttribute(),
0,
\Rector\NodeTypeResolver\Node\Attribute::SCOPE,
\Rector\NodeTypeResolver\Node\Attribute::CLASS_NODE,
\Rector\NodeTypeResolver\Node\Attribute::CLASS_NAME,
\Rector\NodeTypeResolver\Node\Attribute::FILE_INFO,
\Rector\NodeTypeResolver\Node\Attribute::METHOD_NAME,
\Rector\NodeTypeResolver\Node\Attribute::METHOD_NODE,
\Rector\NodeTypeResolver\Node\Attribute::NAMESPACE_NAME,
\Rector\NodeTypeResolver\Node\Attribute::NAMESPACE_NODE,
\Rector\NodeTypeResolver\Node\Attribute::PARENT_NODE,
\Rector\NodeTypeResolver\Node\Attribute::NEXT_NODE,
\Rector\NodeTypeResolver\Node\Attribute::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\Attribute::CURRENT_EXPRESSION,
\Rector\NodeTypeResolver\Node\Attribute::PREVIOUS_EXPRESSION,
\Rector\NodeTypeResolver\Node\Attribute::USE_NODES,
\Rector\NodeTypeResolver\Node\Attribute::START_TOKEN_POSITION
\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE,
\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::FILE_INFO,
\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NAMESPACE_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::NAMESPACE_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_EXPRESSION,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_EXPRESSION,
\Rector\NodeTypeResolver\Node\AttributeKey::USE_NODES,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION
);

expectedArguments(
\PhpParser\Node::setAttribute(),
0,
\Rector\NodeTypeResolver\Node\Attribute::SCOPE,
\Rector\NodeTypeResolver\Node\Attribute::CLASS_NODE,
\Rector\NodeTypeResolver\Node\Attribute::CLASS_NAME,
\Rector\NodeTypeResolver\Node\Attribute::FILE_INFO,
\Rector\NodeTypeResolver\Node\Attribute::METHOD_NAME,
\Rector\NodeTypeResolver\Node\Attribute::METHOD_NODE,
\Rector\NodeTypeResolver\Node\Attribute::NAMESPACE_NAME,
\Rector\NodeTypeResolver\Node\Attribute::NAMESPACE_NODE,
\Rector\NodeTypeResolver\Node\Attribute::PARENT_NODE,
\Rector\NodeTypeResolver\Node\Attribute::NEXT_NODE,
\Rector\NodeTypeResolver\Node\Attribute::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\Attribute::CURRENT_EXPRESSION,
\Rector\NodeTypeResolver\Node\Attribute::PREVIOUS_EXPRESSION,
\Rector\NodeTypeResolver\Node\Attribute::USE_NODES,
\Rector\NodeTypeResolver\Node\Attribute::START_TOKEN_POSITION
\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE,
\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::FILE_INFO,
\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NAMESPACE_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::NAMESPACE_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_EXPRESSION,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_EXPRESSION,
\Rector\NodeTypeResolver\Node\AttributeKey::USE_NODES,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION
);
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Property;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -56,7 +56,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$classNode = $node->getAttribute(Attribute::CLASS_NODE);
$classNode = $node->getAttribute(AttributeKey::CLASS_NODE);
if ($classNode === null) {
return null;
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -96,7 +96,7 @@ public function refactor(Node $node): ?Node
$typeNode = strtolower($typeNode);

$varNode = $node->args[0]->value;
$parentNode = $node->getAttribute(Attribute::PARENT_NODE);
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);

// result of function or probably used
if ($parentNode instanceof Expr || $parentNode instanceof Arg) {
Expand Down
Expand Up @@ -4,7 +4,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\NotEqual;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -55,7 +55,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
// invoke override to default "!="
$node->setAttribute(Attribute::ORIGINAL_NODE, null);
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);

return $node;
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Manipulator\BinaryOpManipulator;
use Rector\PhpParser\NodeTraverser\CallableNodeTraverser;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -107,7 +107,7 @@ public function refactor(Node $node): ?Node
$inArrayFunctionCall = $this->createInArrayFunction($comparedNode, $ifCondition, $node);

/** @var Return_ $returnToRemove */
$returnToRemove = $node->getAttribute(Attribute::NEXT_NODE);
$returnToRemove = $node->getAttribute(AttributeKey::NEXT_NODE);

/** @var Return_ $return */
$return = $firstNodeInsideForeach->stmts[0];
Expand Down Expand Up @@ -149,7 +149,7 @@ private function shouldSkipForeach(Foreach_ $foreachNode): bool
return true;
}

$nextNode = $foreachNode->getAttribute(Attribute::NEXT_NODE);
$nextNode = $foreachNode->getAttribute(AttributeKey::NEXT_NODE);
if ($nextNode === null || ! $nextNode instanceof Return_) {
return true;
}
Expand Down
Expand Up @@ -11,7 +11,7 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Manipulator\ForeachManipulator;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -146,8 +146,8 @@ private function processForeachNodeWithReturnInside(Foreach_ $foreachNode, Retur
}

// is next node Return?
if ($foreachNode->getAttribute(Attribute::NEXT_NODE) instanceof Return_) {
$this->returnNode = $foreachNode->getAttribute(Attribute::NEXT_NODE);
if ($foreachNode->getAttribute(AttributeKey::NEXT_NODE) instanceof Return_) {
$this->returnNode = $foreachNode->getAttribute(AttributeKey::NEXT_NODE);
$this->removeNode($this->returnNode);
}

Expand Down
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Manipulator\IfManipulator;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -97,7 +97,7 @@ public function refactor(Node $node): ?Node
$this->coalescingNodes[] = $comparedNode;
$this->nodesToRemove[] = $currentNode;

$currentNode = $currentNode->getAttribute(Attribute::NEXT_NODE);
$currentNode = $currentNode->getAttribute(AttributeKey::NEXT_NODE);
continue;
}
return null;
Expand Down
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Manipulator\IfManipulator;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function refactor(Node $node): ?Node
if ($comparedNode !== null) {
$insideIfNode = $node->stmts[0];

$nextNode = $node->getAttribute(Attribute::NEXT_NODE);
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_ || $nextNode->expr === null) {
return null;
}
Expand All @@ -76,7 +76,7 @@ public function refactor(Node $node): ?Node

$comparedNode = $this->ifManipulator->matchIfValueReturnValue($node);
if ($comparedNode !== null) {
$nextNode = $node->getAttribute(Attribute::NEXT_NODE);
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_) {
return null;
}
Expand Down
Expand Up @@ -11,7 +11,7 @@
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -56,7 +56,7 @@ public function refactor(Node $node): ?Node
$ifInnerNode = $node->stmts[0];

/** @var Return_ $nextNode */
$nextNode = $node->getAttribute(Attribute::NEXT_NODE);
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);

/** @var Node $innerIfInnerNode */
$innerIfInnerNode = $ifInnerNode->expr;
Expand Down Expand Up @@ -102,7 +102,7 @@ private function shouldSkip(If_ $ifNode): bool
return true;
}

$nextNode = $ifNode->getAttribute(Attribute::NEXT_NODE);
$nextNode = $ifNode->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_ || $nextNode->expr === null) {
return true;
}
Expand Down
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\AssignAndBinaryMap;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function refactor(Node $node): ?Node
return null;
}

$previousNode = $node->getAttribute(Attribute::PREVIOUS_NODE);
$previousNode = $node->getAttribute(AttributeKey::PREVIOUS_NODE);
if (! $previousNode instanceof Expression) {
return null;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ private function shouldSkip(Return_ $returnNode): bool

$variableNode = $returnNode->expr;

$previousExpression = $returnNode->getAttribute(Attribute::PREVIOUS_NODE);
$previousExpression = $returnNode->getAttribute(AttributeKey::PREVIOUS_NODE);
if ($previousExpression === null || ! $previousExpression instanceof Expression) {
return true;
}
Expand All @@ -129,7 +129,7 @@ private function shouldSkip(Return_ $returnNode): bool
*/
private function isPreviousExpressionVisuallySimilar(Expression $previousExpression, Node $previousNode): bool
{
$prePreviousExpression = $previousExpression->getAttribute(Attribute::PREVIOUS_EXPRESSION);
$prePreviousExpression = $previousExpression->getAttribute(AttributeKey::PREVIOUS_EXPRESSION);
if ($prePreviousExpression instanceof Expression && $prePreviousExpression->expr instanceof AssignOp) {
if ($this->areNodesEqual($prePreviousExpression->expr->var, $previousNode->var)) {
return true;
Expand Down
Expand Up @@ -9,7 +9,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
use Rector\PhpParser\NodeTransformer;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -138,7 +138,7 @@ private function transformArrayToYieldsOnMethodNode(ClassMethod $classMethod, Ar
$yieldNodes = $this->nodeTransformer->transformArrayToYields($arrayNode);

// remove whole return node
$parentNode = $arrayNode->getAttribute(Attribute::PARENT_NODE);
$parentNode = $arrayNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
}
Expand Down
Expand Up @@ -4,7 +4,7 @@

use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -56,19 +56,19 @@ public function refactor(Node $node): ?Node
$doubleQuoteCount = substr_count($node->value, '"');
$singleQuoteCount = substr_count($node->value, "'");

if ($node->getAttribute(Attribute::KIND) === String_::KIND_SINGLE_QUOTED) {
if ($node->getAttribute(AttributeKey::KIND) === String_::KIND_SINGLE_QUOTED) {
if ($doubleQuoteCount === 0 && $singleQuoteCount > 0) {
$node->setAttribute(Attribute::KIND, String_::KIND_DOUBLE_QUOTED);
$node->setAttribute(AttributeKey::KIND, String_::KIND_DOUBLE_QUOTED);
// invoke override
$node->setAttribute(Attribute::ORIGINAL_NODE, null);
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}

if ($node->getAttribute(Attribute::KIND) === String_::KIND_DOUBLE_QUOTED) {
if ($node->getAttribute(AttributeKey::KIND) === String_::KIND_DOUBLE_QUOTED) {
if ($singleQuoteCount === 0 && $doubleQuoteCount > 0) {
$node->setAttribute(Attribute::KIND, String_::KIND_SINGLE_QUOTED);
$node->setAttribute(AttributeKey::KIND, String_::KIND_SINGLE_QUOTED);
// invoke override
$node->setAttribute(Attribute::ORIGINAL_NODE, null);
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/CodingStyle/src/Rector/Use_/RemoveUnusedAliasRector.php
Expand Up @@ -17,7 +17,7 @@
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeVisitor\NameResolver;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\NodeTraverser\CallableNodeTraverser;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -214,12 +214,12 @@ private function renameNameNode(array $usedNameNodes, string $lastName): void

private function resolveSearchNode(Use_ $node): Node
{
$searchNode = $node->getAttribute(Attribute::PARENT_NODE);
$searchNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($searchNode) {
return $searchNode;
}

$searchNode = $node->getAttribute(Attribute::NEXT_NODE);
$searchNode = $node->getAttribute(AttributeKey::NEXT_NODE);
if ($searchNode) {
return $searchNode;
}
Expand All @@ -239,7 +239,7 @@ private function resolveUsedNames(Node $searchNode): void
continue;
}

$parentNode = $nameNode->getAttribute(Attribute::PARENT_NODE);
$parentNode = $nameNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ private function resolveTraitUseNames(Node $searchNode): void
$identifierNodes = $this->betterNodeFinder->findInstanceOf($searchNode, Identifier::class);

foreach ($identifierNodes as $identifierNode) {
$parentNode = $identifierNode->getAttribute(Attribute::PARENT_NODE);
$parentNode = $identifierNode->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof UseUse) {
continue;
}
Expand Down