apply new Naming_

This commit is contained in:
TomasVotruba 2020-06-29 23:19:37 +02:00
parent 477308c030
commit 0cb82c2a6f
120 changed files with 612 additions and 503 deletions

View File

@ -19,6 +19,9 @@ final class StaticEasyPrefixer
'Symplify\SmartFileSystem\*',
'Symfony\Component\EventDispatcher\EventSubscriberInterface',
'Symfony\Component\Console\Style\SymfonyStyle',
// doctrine annotations to autocomplete
'Doctrine\ORM\Mapping\*',
'JMS\DiExtraBundle\Annotation\Inject',
];
public static function prefixClass(string $class, string $prefix): string

View File

@ -69,8 +69,8 @@ final class AnnotationReaderFactory
if (class_exists(ConstantPreservingAnnotationReader::class) && class_exists(
ConstantPreservingDocParser::class
)) {
$docParser = new ConstantPreservingDocParser();
return new ConstantPreservingAnnotationReader($docParser);
$constantPreservingDocParser = new ConstantPreservingDocParser();
return new ConstantPreservingAnnotationReader($constantPreservingDocParser);
}
// fallback for testing incompatibilities

View File

@ -349,8 +349,8 @@ final class PhpDocInfo
$currentVarTagValueNode->type = $newPHPStanPhpDocType;
} else {
// add completely new one
$returnTagValueNode = new AttributeAwareVarTagValueNode($newPHPStanPhpDocType, '', '');
$this->addTagValueNode($returnTagValueNode);
$attributeAwareVarTagValueNode = new AttributeAwareVarTagValueNode($newPHPStanPhpDocType, '', '');
$this->addTagValueNode($attributeAwareVarTagValueNode);
}
}
@ -370,8 +370,8 @@ final class PhpDocInfo
$currentReturnTagValueNode->type = $newPHPStanPhpDocType;
} else {
// add completely new one
$returnTagValueNode = new AttributeAwareReturnTagValueNode($newPHPStanPhpDocType, '');
$this->addTagValueNode($returnTagValueNode);
$attributeAwareReturnTagValueNode = new AttributeAwareReturnTagValueNode($newPHPStanPhpDocType, '');
$this->addTagValueNode($attributeAwareReturnTagValueNode);
}
}
@ -379,16 +379,16 @@ final class PhpDocInfo
{
$tag = '@' . ltrim($tag, '@');
$phpDocTagNode = new AttributeAwarePhpDocTagNode($tag, new GenericTagValueNode(''));
$this->addPhpDocTagNode($phpDocTagNode);
$attributeAwarePhpDocTagNode = new AttributeAwarePhpDocTagNode($tag, new GenericTagValueNode(''));
$this->addPhpDocTagNode($attributeAwarePhpDocTagNode);
}
public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void
{
$name = $this->resolveNameForPhpDocTagValueNode($phpDocTagValueNode);
$phpDocTagNode = new AttributeAwarePhpDocTagNode($name, $phpDocTagValueNode);
$this->addPhpDocTagNode($phpDocTagNode);
$attributeAwarePhpDocTagNode = new AttributeAwarePhpDocTagNode($name, $phpDocTagValueNode);
$this->addPhpDocTagNode($attributeAwarePhpDocTagNode);
}
public function isNewNode(): bool

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
use Doctrine\ORM\Mapping\JoinTable;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property;
@ -103,7 +104,7 @@ final class JoinTablePhpDocNodeFactory extends AbstractPhpDocNodeFactory
}
/**
* @param \Doctrine\ORM\Mapping\JoinTable $joinTable
* @param JoinTable $joinTable
* @return JoinColumnTagValueNode[]
*/
private function createJoinColumnTagValues(string $annotationContent, $joinTable, string $type): array

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\JMS;
use JMS\DiExtraBundle\Annotation\Inject;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
@ -44,7 +45,7 @@ final class JMSInjectPhpDocNodeFactory extends AbstractPhpDocNodeFactory
return null;
}
/** @var \JMS\DiExtraBundle\Annotation\Inject|null $inject */
/** @var Inject|null $inject */
$inject = $this->nodeAnnotationReader->readPropertyAnnotation($node, $annotationClass);
if ($inject === null) {
return null;

View File

@ -98,8 +98,8 @@ final class AttributeAwareNodeFactoryTest extends AbstractKernelTestCase
*/
private function createPropertyDocNode(): PhpDocNode
{
$nullableStringTypeNode = new NullableTypeNode(new IdentifierTypeNode('string'));
$propertyTagValueNode = new PropertyTagValueNode($nullableStringTypeNode, 'name', '');
$nullableTypeNode = new NullableTypeNode(new IdentifierTypeNode('string'));
$propertyTagValueNode = new PropertyTagValueNode($nullableTypeNode, 'name', '');
$children = [new PhpDocTagNode('@property', $propertyTagValueNode)];

View File

@ -229,18 +229,18 @@ final class ParsedNodeCollector
return $this->findClassConstant($class, $constantName);
}
private function addClass(Class_ $classNode): void
private function addClass(Class_ $class): void
{
if ($this->isClassAnonymous($classNode)) {
if ($this->isClassAnonymous($class)) {
return;
}
$className = $classNode->getAttribute(AttributeKey::CLASS_NAME);
$className = $class->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) {
throw new ShouldNotHappenException();
}
$this->classes[$className] = $classNode;
$this->classes[$className] = $class;
}
private function addClassConstant(ClassConst $classConst): void
@ -269,13 +269,13 @@ final class ParsedNodeCollector
return $className;
}
private function isClassAnonymous(Class_ $classNode): bool
private function isClassAnonymous(Class_ $class): bool
{
if ($classNode->isAnonymous() || $classNode->name === null) {
if ($class->isAnonymous() || $class->name === null) {
return true;
}
// PHPStan polution
return Strings::startsWith($classNode->name->toString(), 'AnonymousClass');
return Strings::startsWith($class->name->toString(), 'AnonymousClass');
}
}

View File

@ -153,12 +153,12 @@ final class PropertyFetchTypeResolver implements NodeTypeResolverInterface
}
// property is used
$propertyReflection = new ReflectionProperty($varObjectType->getClassName(), $propertyName);
if (! $propertyReflection->getDocComment()) {
$reflectionProperty = new ReflectionProperty($varObjectType->getClassName(), $propertyName);
if (! $reflectionProperty->getDocComment()) {
return new MixedType();
}
$phpDocNode = $this->betterPhpDocParser->parseString((string) $propertyReflection->getDocComment());
$phpDocNode = $this->betterPhpDocParser->parseString((string) $reflectionProperty->getDocComment());
$varTagValues = $phpDocNode->getVarTagValues();
if (! isset($varTagValues[0])) {

View File

@ -45,9 +45,9 @@ final class PropertyTypeResolver implements NodeTypeResolverInterface
public function resolve(Node $propertyNode): Type
{
// fake property to local PropertyFetch → PHPStan understands that
$propertyFetchNode = new PropertyFetch(new Variable('this'), (string) $propertyNode->props[0]->name);
$propertyFetchNode->setAttribute(AttributeKey::SCOPE, $propertyNode->getAttribute(AttributeKey::SCOPE));
$propertyFetch = new PropertyFetch(new Variable('this'), (string) $propertyNode->props[0]->name);
$propertyFetch->setAttribute(AttributeKey::SCOPE, $propertyNode->getAttribute(AttributeKey::SCOPE));
return $this->nodeTypeResolver->resolve($propertyFetchNode);
return $this->nodeTypeResolver->resolve($propertyFetch);
}
}

View File

@ -31,12 +31,12 @@ final class TraitTypeResolver implements NodeTypeResolverInterface
*/
public function resolve(Node $traitNode): Type
{
$traitReflection = new ReflectionClass((string) $traitNode->namespacedName);
$reflectionClass = new ReflectionClass((string) $traitNode->namespacedName);
$types = [];
$types[] = new ObjectType($traitReflection->getName());
$types[] = new ObjectType($reflectionClass->getName());
foreach ($traitReflection->getTraits() as $usedTraitReflection) {
foreach ($reflectionClass->getTraits() as $usedTraitReflection) {
$types[] = new ObjectType($usedTraitReflection->getName());
}

View File

@ -54,7 +54,7 @@ final class FunctionMethodAndClassNodeVisitor extends NodeVisitorAbstract
/**
* @var Function_|null
*/
private $functionNode;
private $function;
/**
* @var ClassNaming
@ -76,7 +76,7 @@ final class FunctionMethodAndClassNodeVisitor extends NodeVisitorAbstract
$this->className = null;
$this->methodName = null;
$this->classMethod = null;
$this->functionNode = null;
$this->function = null;
return null;
}
@ -137,10 +137,10 @@ final class FunctionMethodAndClassNodeVisitor extends NodeVisitorAbstract
private function processFunction(Node $node): void
{
if ($node instanceof Function_) {
$this->functionNode = $node;
$this->function = $node;
}
$node->setAttribute(AttributeKey::FUNCTION_NODE, $this->functionNode);
$node->setAttribute(AttributeKey::FUNCTION_NODE, $this->function);
}
private function setClassNodeAndName(?ClassLike $classLike): void
@ -157,13 +157,13 @@ final class FunctionMethodAndClassNodeVisitor extends NodeVisitorAbstract
}
}
private function setParentClassName(Class_ $classNode, Node $node): void
private function setParentClassName(Class_ $class, Node $node): void
{
if ($classNode->extends === null) {
if ($class->extends === null) {
return;
}
$parentClassResolvedName = $classNode->extends->getAttribute(AttributeKey::RESOLVED_NAME);
$parentClassResolvedName = $class->extends->getAttribute(AttributeKey::RESOLVED_NAME);
if ($parentClassResolvedName instanceof FullyQualified) {
$parentClassResolvedName = $parentClassResolvedName->toString();
}

View File

@ -26,7 +26,7 @@ final class NamespaceNodeVisitor extends NodeVisitorAbstract
/**
* @var Namespace_|null
*/
private $namespaceNode;
private $namespace;
/**
* @var BetterNodeFinder
@ -45,7 +45,7 @@ final class NamespaceNodeVisitor extends NodeVisitorAbstract
public function beforeTraverse(array $nodes): ?array
{
$this->namespaceName = null;
$this->namespaceNode = null;
$this->namespace = null;
// init basic use nodes for non-namespaced code
/** @var Use_[] $uses */
@ -59,7 +59,7 @@ final class NamespaceNodeVisitor extends NodeVisitorAbstract
{
if ($node instanceof Namespace_) {
$this->namespaceName = $node->name !== null ? $node->name->toString() : null;
$this->namespaceNode = $node;
$this->namespace = $node;
/** @var Use_[] $uses */
$uses = $this->betterNodeFinder->findInstanceOf($node, Use_::class);
@ -67,7 +67,7 @@ final class NamespaceNodeVisitor extends NodeVisitorAbstract
}
$node->setAttribute(AttributeKey::NAMESPACE_NAME, $this->namespaceName);
$node->setAttribute(AttributeKey::NAMESPACE_NODE, $this->namespaceNode);
$node->setAttribute(AttributeKey::NAMESPACE_NODE, $this->namespace);
$node->setAttribute(AttributeKey::USE_NODES, $this->useNodes);
return $node;

View File

@ -66,9 +66,9 @@ final class RemoveDeepChainMethodCallNodeVisitor extends NodeVisitorAbstract
{
if ($node === $this->removingExpression) {
// keep any node, so we don't remove it permanently
$nopNode = new Nop();
$nopNode->setAttributes($node->getAttributes());
return $nopNode;
$nop = new Nop();
$nop->setAttributes($node->getAttributes());
return $nop;
}
return $node;

View File

@ -37,9 +37,9 @@ final class StaticTypeMapperTest extends AbstractKernelTestCase
*/
public function testMapPHPStanPhpDocTypeNodeToPHPStanType(TypeNode $typeNode, string $expectedType): void
{
$node = new String_('hey');
$string = new String_('hey');
$phpStanType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, $node);
$phpStanType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, $string);
$this->assertInstanceOf($expectedType, $phpStanType);
}

View File

@ -64,9 +64,9 @@ final class PropertyToAddCollector implements NodeCollectorInterface
public function addPropertyWithoutConstructorToClass(
string $propertyName,
?Type $propertyType,
Class_ $classNode
Class_ $class
): void {
$this->propertiesWithoutConstructorByClass[spl_object_hash($classNode)][$propertyName] = $propertyType;
$this->propertiesWithoutConstructorByClass[spl_object_hash($class)][$propertyName] = $propertyType;
}
/**

View File

@ -143,9 +143,9 @@ PHP
* Creates:
* "$this->repository = $entityManager->getRepository()"
*/
private function createRepositoryAssign(Class_ $classNode): Assign
private function createRepositoryAssign(Class_ $class): Assign
{
$repositoryClassName = (string) $classNode->getAttribute(AttributeKey::CLASS_NAME);
$repositoryClassName = (string) $class->getAttribute(AttributeKey::CLASS_NAME);
$entityClassName = $this->doctrineEntityAndRepositoryMapper->mapRepositoryToEntity($repositoryClassName);
if ($entityClassName === null) {

View File

@ -99,8 +99,8 @@ PHP
return null;
}
$methodReflection = new ReflectionMethod($class, $method);
if ($methodReflection->getNumberOfParameters() > 0) {
$reflectionMethod = new ReflectionMethod($class, $method);
if ($reflectionMethod->getNumberOfParameters() > 0) {
return null;
}

View File

@ -139,9 +139,9 @@ PHP
/**
* @param Variable|PropertyFetch $objectExpr
*/
private function matchCallableMethod(Expr $objectExpr, String_ $methodExpr): ?ClassMethod
private function matchCallableMethod(Expr $objectExpr, String_ $string): ?ClassMethod
{
$methodName = $this->getValue($methodExpr);
$methodName = $this->getValue($string);
if (! is_string($methodName)) {
throw new ShouldNotHappenException();
}

View File

@ -172,9 +172,9 @@ PHP
return ! $foreach->stmts[0] instanceof If_;
}
private function shouldSkipIf(If_ $ifNode): bool
private function shouldSkipIf(If_ $if): bool
{
$ifCondition = $ifNode->cond;
$ifCondition = $if->cond;
return ! $ifCondition instanceof Identical && ! $ifCondition instanceof Equal;
}
@ -192,9 +192,9 @@ PHP
);
}
private function isIfBodyABoolReturnNode(If_ $firstNodeInsideForeach): bool
private function isIfBodyABoolReturnNode(If_ $if): bool
{
$ifStatment = $firstNodeInsideForeach->stmts[0];
$ifStatment = $if->stmts[0];
if (! $ifStatment instanceof Return_) {
return false;
}
@ -209,9 +209,9 @@ PHP
/**
* @param Identical|Equal $binaryOp
*/
private function createInArrayFunction(Node $node, BinaryOp $binaryOp, Foreach_ $foreachNode): FuncCall
private function createInArrayFunction(Node $node, BinaryOp $binaryOp, Foreach_ $foreach): FuncCall
{
$arguments = $this->createArgs([$node, $foreachNode->expr]);
$arguments = $this->createArgs([$node, $foreach->expr]);
if ($binaryOp instanceof Identical) {
$arguments[] = $this->createArg($this->createTrue());

View File

@ -104,18 +104,18 @@ PHP
return $this->createAssignNode($node, $name, $onlyNodeInIf->var);
}
private function shouldSkip(Foreach_ $foreachNode): bool
private function shouldSkip(Foreach_ $foreach): bool
{
if (count($foreachNode->stmts) !== 1) {
if (count($foreach->stmts) !== 1) {
return true;
}
if (! $foreachNode->stmts[0] instanceof If_) {
if (! $foreach->stmts[0] instanceof If_) {
return true;
}
/** @var If_ $ifNode */
$ifNode = $foreachNode->stmts[0];
$ifNode = $foreach->stmts[0];
if ($ifNode->else !== null) {
return true;
@ -128,13 +128,10 @@ PHP
return ! $ifNode->cond instanceof FuncCall;
}
private function createAssignNode(Foreach_ $foreachNode, string $name, ArrayDimFetch $arrayDimFetch): Assign
private function createAssignNode(Foreach_ $foreach, string $name, ArrayDimFetch $arrayDimFetch): Assign
{
$functionNameNode = new String_($name);
$arrayFilterFuncCall = new FuncCall(new Name('array_filter'), [
new Arg($foreachNode->expr),
new Arg($functionNameNode),
]);
$string = new String_($name);
$arrayFilterFuncCall = new FuncCall(new Name('array_filter'), [new Arg($foreach->expr), new Arg($string)]);
return new Assign($arrayDimFetch->var, $arrayFilterFuncCall);
}

View File

@ -30,7 +30,7 @@ final class SimplifyForeachToCoalescingRector extends AbstractRector
/**
* @var Return_|null
*/
private $returnNode;
private $return;
/**
* @var ForeachManipulator
@ -80,7 +80,7 @@ PHP
return null;
}
$this->returnNode = null;
$this->return = null;
if ($node->keyVar === null) {
return null;
@ -108,9 +108,9 @@ PHP
/**
* @return Assign|Return_|null
*/
private function matchReturnOrAssignNode(Foreach_ $foreachNode): ?Node
private function matchReturnOrAssignNode(Foreach_ $foreach): ?Node
{
return $this->foreachManipulator->matchOnlyStmt($foreachNode, function (Node $node): ?Node {
return $this->foreachManipulator->matchOnlyStmt($foreach, function (Node $node): ?Node {
if (! $node instanceof If_) {
return null;
}
@ -133,64 +133,64 @@ PHP
});
}
private function processForeachNodeWithReturnInside(Foreach_ $foreachNode, Return_ $returnNode): ?Node
private function processForeachNodeWithReturnInside(Foreach_ $foreach, Return_ $return): ?Node
{
if (! $this->areNodesEqual($foreachNode->valueVar, $returnNode->expr)) {
if (! $this->areNodesEqual($foreach->valueVar, $return->expr)) {
return null;
}
/** @var If_ $ifNode */
$ifNode = $foreachNode->stmts[0];
$ifNode = $foreach->stmts[0];
/** @var Identical $identicalNode */
$identicalNode = $ifNode->cond;
if ($this->areNodesEqual($identicalNode->left, $foreachNode->keyVar)) {
if ($this->areNodesEqual($identicalNode->left, $foreach->keyVar)) {
$checkedNode = $identicalNode->right;
} elseif ($this->areNodesEqual($identicalNode->right, $foreachNode->keyVar)) {
} elseif ($this->areNodesEqual($identicalNode->right, $foreach->keyVar)) {
$checkedNode = $identicalNode->left;
} else {
return null;
}
// is next node Return?
if ($foreachNode->getAttribute(AttributeKey::NEXT_NODE) instanceof Return_) {
$this->returnNode = $foreachNode->getAttribute(AttributeKey::NEXT_NODE);
$this->removeNode($this->returnNode);
if ($foreach->getAttribute(AttributeKey::NEXT_NODE) instanceof Return_) {
$this->return = $foreach->getAttribute(AttributeKey::NEXT_NODE);
$this->removeNode($this->return);
}
$coalesceNode = new Coalesce(new ArrayDimFetch(
$foreachNode->expr,
$coalesce = new Coalesce(new ArrayDimFetch(
$foreach->expr,
$checkedNode
), $this->returnNode && $this->returnNode->expr !== null ? $this->returnNode->expr : $checkedNode);
), $this->return && $this->return->expr !== null ? $this->return->expr : $checkedNode);
if ($this->returnNode !== null) {
return new Return_($coalesceNode);
if ($this->return !== null) {
return new Return_($coalesce);
}
return null;
}
private function processForeachNodeWithAssignInside(Foreach_ $foreachNode, Assign $assign): ?Node
private function processForeachNodeWithAssignInside(Foreach_ $foreach, Assign $assign): ?Node
{
/** @var If_ $ifNode */
$ifNode = $foreachNode->stmts[0];
$ifNode = $foreach->stmts[0];
/** @var Identical $identicalNode */
$identicalNode = $ifNode->cond;
if ($this->areNodesEqual($identicalNode->left, $foreachNode->keyVar)) {
if ($this->areNodesEqual($identicalNode->left, $foreach->keyVar)) {
$checkedNode = $assign->var;
$keyNode = $identicalNode->right;
} elseif ($this->areNodesEqual($identicalNode->right, $foreachNode->keyVar)) {
} elseif ($this->areNodesEqual($identicalNode->right, $foreach->keyVar)) {
$checkedNode = $assign->var;
$keyNode = $identicalNode->left;
} else {
return null;
}
$arrayDimFetchNode = new ArrayDimFetch($foreachNode->expr, $keyNode);
$arrayDimFetch = new ArrayDimFetch($foreach->expr, $keyNode);
return new Assign($checkedNode, new Coalesce($arrayDimFetchNode, $checkedNode));
return new Assign($checkedNode, new Coalesce($arrayDimFetch, $checkedNode));
}
}

View File

@ -83,12 +83,12 @@ final class GetClassToInstanceOfRector extends AbstractRector
return null;
}
$instanceOfNode = new Instanceof_($varNode, new FullyQualified($className));
$instanceof = new Instanceof_($varNode, new FullyQualified($className));
if ($node instanceof NotIdentical) {
return new BooleanNot($instanceOfNode);
return new BooleanNot($instanceof);
}
return $instanceOfNode;
return $instanceof;
}
private function isClassReference(Node $node): bool

View File

@ -76,29 +76,29 @@ PHP
return $node;
}
private function shouldSkip(If_ $node): bool
private function shouldSkip(If_ $if): bool
{
if ($node->else !== null) {
if ($if->else !== null) {
return true;
}
if (count($node->stmts) !== 1) {
if (count($if->stmts) !== 1) {
return true;
}
if ($node->elseifs !== []) {
if ($if->elseifs !== []) {
return true;
}
if (! $node->stmts[0] instanceof If_) {
if (! $if->stmts[0] instanceof If_) {
return true;
}
if ($node->stmts[0]->else !== null) {
if ($if->stmts[0]->else !== null) {
return true;
}
return (bool) $node->stmts[0]->elseifs;
return (bool) $if->stmts[0]->elseifs;
}
private function combineComments(Node $firstNode, Node $secondNode): void

View File

@ -144,14 +144,14 @@ PHP
*/
private function resolveCount(bool $isNegated, Expr $expr): BinaryOp
{
$valueNode = new LNumber(0);
$lNumber = new LNumber(0);
// compare === 0, assumption
if ($isNegated) {
return new Identical($expr, $valueNode);
return new Identical($expr, $lNumber);
}
return new Greater($expr, $valueNode);
return new Greater($expr, $lNumber);
}
/**
@ -159,14 +159,14 @@ PHP
*/
private function resolveArray(bool $isNegated, Expr $expr): BinaryOp
{
$valueNode = new Array_([]);
$array = new Array_([]);
// compare === []
if ($isNegated) {
return new Identical($expr, $valueNode);
return new Identical($expr, $array);
}
return new NotIdentical($expr, $valueNode);
return new NotIdentical($expr, $array);
}
/**
@ -174,14 +174,14 @@ PHP
*/
private function resolveString(bool $isNegated, Expr $expr): BinaryOp
{
$valueNode = new String_('');
$string = new String_('');
// compare === ''
if ($isNegated) {
return new Identical($expr, $valueNode);
return new Identical($expr, $string);
}
return new NotIdentical($expr, $valueNode);
return new NotIdentical($expr, $string);
}
/**
@ -189,24 +189,24 @@ PHP
*/
private function resolveInteger(bool $isNegated, Expr $expr): BinaryOp
{
$valueNode = new LNumber(0);
$lNumber = new LNumber(0);
if ($isNegated) {
return new Identical($expr, $valueNode);
return new Identical($expr, $lNumber);
}
return new NotIdentical($expr, $valueNode);
return new NotIdentical($expr, $lNumber);
}
private function resolveFloat(bool $isNegated, Expr $expr): BinaryOp
{
$valueNode = new DNumber(0.0);
$dNumber = new DNumber(0.0);
if ($isNegated) {
return new Identical($expr, $valueNode);
return new Identical($expr, $dNumber);
}
return new NotIdentical($expr, $valueNode);
return new NotIdentical($expr, $dNumber);
}
/**

View File

@ -100,40 +100,40 @@ PHP
return null;
}
$funcCallNode = new FuncCall(new Name('array_merge'), [
$funcCall = new FuncCall(new Name('array_merge'), [
new Arg(new Coalesce($valueNode, new Array_([]))),
new Arg($secondAssign->expr),
]);
return new Assign($valueNode, $funcCallNode);
return new Assign($valueNode, $funcCall);
}
private function shouldSkip(If_ $ifNode): bool
private function shouldSkip(If_ $if): bool
{
if ($ifNode->else === null) {
if ($if->else === null) {
return true;
}
if (count($ifNode->elseifs) > 1) {
if (count($if->elseifs) > 1) {
return true;
}
if (! $ifNode->cond instanceof Isset_) {
if (! $if->cond instanceof Isset_) {
return true;
}
if (! $this->hasOnlyStatementAssign($ifNode)) {
if (! $this->hasOnlyStatementAssign($if)) {
return true;
}
if (! $this->hasOnlyStatementAssign($ifNode->else)) {
if (! $this->hasOnlyStatementAssign($if->else)) {
return true;
}
if (! $this->areNodesEqual($ifNode->cond->vars[0], $ifNode->stmts[0]->expr->var)) {
if (! $this->areNodesEqual($if->cond->vars[0], $if->stmts[0]->expr->var)) {
return true;
}
return ! $this->areNodesEqual($ifNode->cond->vars[0], $ifNode->else->stmts[0]->expr->var);
return ! $this->areNodesEqual($if->cond->vars[0], $if->else->stmts[0]->expr->var);
}
/**

View File

@ -109,22 +109,22 @@ PHP
return $newReturnNode;
}
private function shouldSkip(If_ $ifNode): bool
private function shouldSkip(If_ $if): bool
{
if (count($ifNode->elseifs) > 0) {
if (count($if->elseifs) > 0) {
return true;
}
if ($this->isElseSeparatedThenIf($ifNode)) {
if ($this->isElseSeparatedThenIf($if)) {
return true;
}
if (! $this->isIfWithSingleReturnExpr($ifNode)) {
if (! $this->isIfWithSingleReturnExpr($if)) {
return true;
}
/** @var Return_ $ifInnerNode */
$ifInnerNode = $ifNode->stmts[0];
$ifInnerNode = $if->stmts[0];
/** @var Expr $returnedExpr */
$returnedExpr = $ifInnerNode->expr;
@ -133,35 +133,35 @@ PHP
return true;
}
$nextNode = $ifNode->getAttribute(AttributeKey::NEXT_NODE);
$nextNode = $if->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_ || $nextNode->expr === null) {
return true;
}
// negate + negate → skip for now
if ($this->isFalse($returnedExpr) && Strings::contains($this->print($ifNode->cond), '!=')) {
if ($this->isFalse($returnedExpr) && Strings::contains($this->print($if->cond), '!=')) {
return true;
}
return ! $this->isBool($nextNode->expr);
}
private function processReturnTrue(If_ $ifNode, Return_ $nextReturnNode): Return_
private function processReturnTrue(If_ $if, Return_ $nextReturnNode): Return_
{
if ($ifNode->cond instanceof BooleanNot && $nextReturnNode->expr !== null && $this->isTrue(
if ($if->cond instanceof BooleanNot && $nextReturnNode->expr !== null && $this->isTrue(
$nextReturnNode->expr
)) {
return new Return_($this->boolCastOrNullCompareIfNeeded($ifNode->cond->expr));
return new Return_($this->boolCastOrNullCompareIfNeeded($if->cond->expr));
}
return new Return_($this->boolCastOrNullCompareIfNeeded($ifNode->cond));
return new Return_($this->boolCastOrNullCompareIfNeeded($if->cond));
}
private function processReturnFalse(If_ $ifNode, Return_ $nextReturnNode): ?Return_
private function processReturnFalse(If_ $if, Return_ $nextReturnNode): ?Return_
{
if ($ifNode->cond instanceof Identical) {
if ($if->cond instanceof Identical) {
return new Return_($this->boolCastOrNullCompareIfNeeded(
new NotIdentical($ifNode->cond->left, $ifNode->cond->right)
new NotIdentical($if->cond->left, $if->cond->right)
));
}
@ -173,11 +173,11 @@ PHP
return null;
}
if ($ifNode->cond instanceof BooleanNot) {
return new Return_($this->boolCastOrNullCompareIfNeeded($ifNode->cond->expr));
if ($if->cond instanceof BooleanNot) {
return new Return_($this->boolCastOrNullCompareIfNeeded($if->cond->expr));
}
return new Return_($this->boolCastOrNullCompareIfNeeded(new BooleanNot($ifNode->cond)));
return new Return_($this->boolCastOrNullCompareIfNeeded(new BooleanNot($if->cond)));
}
private function isIfWithSingleReturnExpr(If_ $if): bool

View File

@ -101,15 +101,15 @@ PHP
return $node;
}
private function shouldSkip(Return_ $returnNode): bool
private function shouldSkip(Return_ $return): bool
{
if (! $returnNode->expr instanceof Variable) {
if (! $return->expr instanceof Variable) {
return true;
}
$variableNode = $returnNode->expr;
$variableNode = $return->expr;
$previousExpression = $returnNode->getAttribute(AttributeKey::PREVIOUS_NODE);
$previousExpression = $return->getAttribute(AttributeKey::PREVIOUS_NODE);
if ($previousExpression === null || ! $previousExpression instanceof Expression) {
return true;
}

View File

@ -40,11 +40,11 @@ final class AliasUsesResolver
/**
* @return string[]
*/
private function resolveForNamespace(Namespace_ $node): array
private function resolveForNamespace(Namespace_ $namespace): array
{
$aliasedUses = [];
$this->useImportsTraverser->traverserStmts($node->stmts, function (
$this->useImportsTraverser->traverserStmts($namespace->stmts, function (
UseUse $useUse,
string $name
) use (&$aliasedUses): void {

View File

@ -104,8 +104,8 @@ final class UsedImportsResolver
/**
* @return FullyQualifiedObjectType[]
*/
private function resolveForNamespace(Namespace_ $node): array
private function resolveForNamespace(Namespace_ $namespace): array
{
return $this->resolveForStmts($node->stmts);
return $this->resolveForStmts($namespace->stmts);
}
}

View File

@ -147,12 +147,12 @@ PHP
return null;
}
private function transformArrayToYieldsOnMethodNode(ClassMethod $classMethod, Array_ $arrayNode): void
private function transformArrayToYieldsOnMethodNode(ClassMethod $classMethod, Array_ $array): void
{
$yieldNodes = $this->nodeTransformer->transformArrayToYields($arrayNode);
$yieldNodes = $this->nodeTransformer->transformArrayToYields($array);
// remove whole return node
$parentNode = $arrayNode->getAttribute(AttributeKey::PARENT_NODE);
$parentNode = $array->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
}

View File

@ -147,20 +147,20 @@ PHP
/**
* @param string[] $propertyNames
*/
private function completeDefaultArrayToPropertyNames(Class_ $node, array $propertyNames): void
private function completeDefaultArrayToPropertyNames(Class_ $class, array $propertyNames): void
{
$this->traverseNodesWithCallable($node, function (Node $node) use ($propertyNames): ?PropertyProperty {
if (! $node instanceof PropertyProperty) {
$this->traverseNodesWithCallable($class, function (Node $class) use ($propertyNames): ?PropertyProperty {
if (! $class instanceof PropertyProperty) {
return null;
}
if (! $this->isNames($node, $propertyNames)) {
if (! $this->isNames($class, $propertyNames)) {
return null;
}
$node->default = new Array_();
$class->default = new Array_();
return $node;
return $class;
});
}

View File

@ -80,21 +80,21 @@ PHP
/**
* Remove "./" which would break the path
*/
private function removeExtraDotSlash(String_ $includedPath): void
private function removeExtraDotSlash(String_ $string): void
{
if (! Strings::startsWith($includedPath->value, './')) {
if (! Strings::startsWith($string->value, './')) {
return;
}
$includedPath->value = Strings::replace($includedPath->value, '#^\.\/#', '/');
$string->value = Strings::replace($string->value, '#^\.\/#', '/');
}
private function prependSlashIfMissing(String_ $includedPath): void
private function prependSlashIfMissing(String_ $string): void
{
if (Strings::startsWith($includedPath->value, '/')) {
if (Strings::startsWith($string->value, '/')) {
return;
}
$includedPath->value = '/' . $includedPath->value;
$string->value = '/' . $string->value;
}
}

View File

@ -96,8 +96,8 @@ PHP
if ($secondCase->cond !== null) {
// has condition
$equalNode = new Equal($node->cond, $secondCase->cond);
$ifNode->elseifs[] = new ElseIf_($equalNode, $this->removeBreakNodes($secondCase->stmts));
$equal = new Equal($node->cond, $secondCase->cond);
$ifNode->elseifs[] = new ElseIf_($equal, $this->removeBreakNodes($secondCase->stmts));
} else {
// defaults
$ifNode->else = new Else_($this->removeBreakNodes($secondCase->stmts));

View File

@ -196,8 +196,8 @@ PHP
return 0;
}
$reflectedFunction = new ReflectionFunction($functionFqn);
$foundThrownThrowables = $this->functionAnnotationResolver->extractFunctionAnnotatedThrows($reflectedFunction);
$reflectionFunction = new ReflectionFunction($functionFqn);
$foundThrownThrowables = $this->functionAnnotationResolver->extractFunctionAnnotatedThrows($reflectionFunction);
$alreadyAnnotatedThrowables = $this->extractAlreadyAnnotatedThrowables($funcCall);
return $this->diffThrowables($foundThrownThrowables, $alreadyAnnotatedThrowables);
}
@ -216,9 +216,9 @@ PHP
private function buildThrowsDocComment(string $throwableClass): AttributeAwarePhpDocTagNode
{
$genericTagValueNode = new ThrowsTagValueNode(new IdentifierTypeNode($throwableClass), '');
$throwsTagValueNode = new ThrowsTagValueNode(new IdentifierTypeNode($throwableClass), '');
return new AttributeAwarePhpDocTagNode('@throws', $genericTagValueNode);
return new AttributeAwarePhpDocTagNode('@throws', $throwsTagValueNode);
}
private function identifyThrownThrowablesInStaticCall(StaticCall $staticCall): array

View File

@ -254,11 +254,11 @@ PHP
}
}
private function renameInterface(string $lastName, Interface_ $parentNode, $usedName): void
private function renameInterface(string $lastName, Interface_ $interface, $usedName): void
{
foreach ($parentNode->extends as $key => $extendInterfaceName) {
foreach ($interface->extends as $key => $extendInterfaceName) {
if ($this->areNamesEqual($extendInterfaceName, $usedName)) {
$parentNode->extends[$key] = new Name($lastName);
$interface->extends[$key] = new Name($lastName);
}
}
}

View File

@ -57,10 +57,10 @@ final class ClassMethodAndCallMatcher
return false;
}
$classMethodStaticType = new ObjectType($className);
$objectType = new ObjectType($className);
$callerStaticType = $this->nodeTypeResolver->getStaticType($methodCall->var);
return $classMethodStaticType->isSuperTypeOf($callerStaticType)->yes();
return $objectType->isSuperTypeOf($callerStaticType)->yes();
}
private function isStaticCallMatchingClassMethod(StaticCall $staticCall, ClassMethod $classMethod): bool
@ -75,13 +75,13 @@ final class ClassMethodAndCallMatcher
return false;
}
$classMethodStaticType = new ObjectType($className);
$objectType = new ObjectType($className);
$callerStaticType = $this->nodeTypeResolver->resolve($staticCall->class);
if ($callerStaticType instanceof MixedType) {
return false;
}
return $classMethodStaticType->isSuperTypeOf($callerStaticType)->yes();
return $objectType->isSuperTypeOf($callerStaticType)->yes();
}
}

View File

@ -115,17 +115,17 @@ PHP
$this->removeNode($if);
}
private function processForeach(Foreach_ $node): void
private function processForeach(Foreach_ $foreach): void
{
if ($node->stmts !== []) {
if ($foreach->stmts !== []) {
return;
}
if ($this->isNodeWithSideEffect($node->expr)) {
if ($this->isNodeWithSideEffect($foreach->expr)) {
return;
}
$this->removeNode($node);
$this->removeNode($foreach);
}
private function isNodeWithSideEffect(Expr $expr): bool

View File

@ -6,6 +6,7 @@ namespace Rector\DeadCode\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\PropertyProperty;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
@ -65,7 +66,7 @@ PHP
return null;
}
if ($node->getAttribute(AttributeKey::PREVIOUS_NODE) instanceof Node\NullableType) {
if ($node->getAttribute(AttributeKey::PREVIOUS_NODE) instanceof NullableType) {
return null;
}

View File

@ -143,8 +143,8 @@ final class ClassUnusedPrivateClassMethodResolver
if (! method_exists($class, $method)) {
return false;
}
$methodReflection = new ReflectionMethod($class, $method);
$reflectionMethod = new ReflectionMethod($class, $method);
return $methodReflection->isAbstract();
return $reflectionMethod->isAbstract();
}
}

View File

@ -24,8 +24,8 @@ final class ConstructorClassMethodFactory
return null;
}
$methodBuilder = new Method('__construct');
$methodBuilder->makePublic();
$method = new Method('__construct');
$method->makePublic();
foreach ($properties as $propertyName => $property) {
/** @var string $propertyName */
@ -36,15 +36,15 @@ final class ConstructorClassMethodFactory
$paramBuilder->setType($property->type);
}
$methodBuilder->addParam($paramBuilder->getNode());
$method->addParam($paramBuilder->getNode());
// add assign
$assign = $this->createAssign($propertyName);
$methodBuilder->addStmt($assign);
$method->addStmt($assign);
}
return $methodBuilder->getNode();
return $method->getNode();
}
private function createAssign(string $propertyName): Assign

View File

@ -47,15 +47,15 @@ final class NamespaceFactory
*/
private function createNewClass(DecoupleClassMethodMatch $decoupleClassMethodMatch, array $classStmts): Class_
{
$classBuilder = new ClassBuilder($decoupleClassMethodMatch->getClassName());
$classBuilder->addStmts($classStmts);
$classBuilder->makeFinal();
$class = new ClassBuilder($decoupleClassMethodMatch->getClassName());
$class->addStmts($classStmts);
$class->makeFinal();
$parentClassName = $decoupleClassMethodMatch->getParentClassName();
if ($parentClassName !== null) {
$classBuilder->extend(new FullyQualified($parentClassName));
$class->extend(new FullyQualified($parentClassName));
}
return $classBuilder->getNode();
return $class->getNode();
}
}

View File

@ -159,9 +159,9 @@ PHP
private function createPropertyArrayCollectionAssign(string $toManyPropertyName): Expression
{
$propertyFetch = $this->createPropertyFetch('this', $toManyPropertyName);
$newCollection = new New_(new FullyQualified(ArrayCollection::class));
$new = new New_(new FullyQualified(ArrayCollection::class));
$assign = new Assign($propertyFetch, $newCollection);
$assign = new Assign($propertyFetch, $new);
return new Expression($assign);
}

View File

@ -212,9 +212,9 @@ CODE_SAMPLE
return $propertyWithUuid;
}
private function hasClassPropertyName(Class_ $node, string $uuidPropertyName): bool
private function hasClassPropertyName(Class_ $class, string $uuidPropertyName): bool
{
foreach ($node->getProperties() as $property) {
foreach ($class->getProperties() as $property) {
if (! $this->isName($property, $uuidPropertyName)) {
continue;
}

View File

@ -215,14 +215,14 @@ PHP
* After:
* $this->entityManager->
*/
private function replaceEntityRegistryVariableWithEntityManagerProperty(Class_ $node): void
private function replaceEntityRegistryVariableWithEntityManagerProperty(Class_ $class): void
{
$this->traverseNodesWithCallable($node->stmts, function (Node $node): ?PropertyFetch {
if (! $node instanceof Variable) {
$this->traverseNodesWithCallable($class->stmts, function (Node $class): ?PropertyFetch {
if (! $class instanceof Variable) {
return null;
}
if (! $this->isObjectType($node, ObjectManager::class)) {
if (! $this->isObjectType($class, ObjectManager::class)) {
return null;
}

View File

@ -92,8 +92,8 @@ CODE_SAMPLE
/** @var PhpDocInfo $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
$uuidObjectType = new FullyQualifiedObjectType(UuidInterface::class);
$phpDocInfo->changeVarType($uuidObjectType);
$fullyQualifiedObjectType = new FullyQualifiedObjectType(UuidInterface::class);
$phpDocInfo->changeVarType($fullyQualifiedObjectType);
$phpDocInfo->removeByType(GeneratedValueTagValueNode::class);
$this->changeColumnTypeToUuidBinary($phpDocInfo);

View File

@ -39,8 +39,8 @@ final class ImplicitToExplicitRoutingAnnotationDecorator
$phpDocInfo = $classMethod->getAttribute(AttributeKey::PHP_DOC_INFO);
$phpDocInfo->addTagValueNodeWithShortName($symfonyRouteTagValueNode);
$symfonyRouteUseObjectType = new FullyQualifiedObjectType(SymfonyRouteTagValueNode::CLASS_NAME);
$this->addUseType($symfonyRouteUseObjectType, $classMethod);
$fullyQualifiedObjectType = new FullyQualifiedObjectType(SymfonyRouteTagValueNode::CLASS_NAME);
$this->addUseType($fullyQualifiedObjectType, $classMethod);
// remove
$this->useNodesToAddCollector->removeShortUse($classMethod, 'Route');

View File

@ -107,8 +107,8 @@ PHP
return null;
}
$objectType = new FullyQualifiedObjectType($functionChange->getClass());
$this->addPropertyToClass($classNode, $objectType, $functionChange->getProperty());
$fullyQualifiedObjectType = new FullyQualifiedObjectType($functionChange->getClass());
$this->addPropertyToClass($classNode, $fullyQualifiedObjectType, $functionChange->getProperty());
$propertyFetchNode = $this->createPropertyFetch('this', $functionChange->getProperty());

View File

@ -119,9 +119,9 @@ PHP
return $expr;
}
$newArgumentValue = new Mul($oldValue, new LNumber(60));
$mul = new Mul($oldValue, new LNumber(60));
$expr->args[$argumentPosition] = new Arg($newArgumentValue);
$expr->args[$argumentPosition] = new Arg($mul);
return $expr;
}

View File

@ -114,13 +114,13 @@ PHP
}
private function refactorClassStmts(
Class_ $node,
Class_ $class,
string $getSingletonMethodName,
string $singletonPropertyName
): Class_ {
foreach ($node->getMethods() as $property) {
foreach ($class->getMethods() as $property) {
if ($this->isName($property, $getSingletonMethodName)) {
$this->removeNodeFromStatements($node, $property);
$this->removeNodeFromStatements($class, $property);
continue;
}
@ -134,15 +134,15 @@ PHP
// remove non-public empty
if ($property->stmts === []) {
$this->removeNodeFromStatements($node, $property);
$this->removeNodeFromStatements($class, $property);
} else {
$this->makePublic($property);
}
}
$this->removePropertyByName($node, $singletonPropertyName);
$this->removePropertyByName($class, $singletonPropertyName);
return $node;
return $class;
}
private function removePropertyByName(Class_ $class, string $propertyName): void

View File

@ -176,11 +176,11 @@ PHP
private function createClassMethodFromFunction(string $methodName, Function_ $function): ClassMethod
{
$methodBuilder = new Method($methodName);
$methodBuilder->makePublic();
$methodBuilder->makeStatic();
$methodBuilder->addStmts($function->stmts);
$method = new Method($methodName);
$method->makePublic();
$method->makeStatic();
$method->addStmts($function->stmts);
return $methodBuilder->getNode();
return $method->getNode();
}
}

View File

@ -75,14 +75,14 @@ PHP
return $this->processMethodCall($node);
}
private function processStringNode(String_ $stringNode): ?Node
private function processStringNode(String_ $string): ?Node
{
foreach ($this->methodNamesByType as $type => $methodName) {
if (! $this->isObjectType($stringNode, $type)) {
if (! $this->isObjectType($string, $type)) {
continue;
}
return $this->createMethodCall($stringNode->expr, $methodName);
return $this->createMethodCall($string->expr, $methodName);
}
return null;

View File

@ -262,8 +262,8 @@ PHP
return $expectsMethodCall;
}
$methodReflection = new ReflectionMethod($mockVariableType, $methodName);
if ($methodReflection->getNumberOfRequiredParameters() === 0) {
$reflectionMethod = new ReflectionMethod($mockVariableType, $methodName);
if ($reflectionMethod->getNumberOfRequiredParameters() === 0) {
return $expectsMethodCall;
}

View File

@ -96,14 +96,14 @@ PHP
private function createTearDownMethodWithMockeryClose(): ClassMethod
{
$tearDownClassMethodBuilder = new Method('tearDown');
$tearDownClassMethodBuilder->setReturnType('void');
$tearDownClassMethodBuilder->makeProtected();
$method = new Method('tearDown');
$method->setReturnType('void');
$method->makeProtected();
$staticCall = $this->createMockeryClose();
$tearDownClassMethodBuilder->addStmt($staticCall);
$method->addStmt($staticCall);
return $tearDownClassMethodBuilder->getNode();
return $method->getNode();
}
private function containsMockeryClose(ClassMethod $classMethod): bool

View File

@ -147,11 +147,11 @@ PHP
unset($funcCall->args[1]);
// add for
$xVar = new Variable('x');
$forNode = new For_([
'init' => [new Assign($xVar, new LNumber(0))],
'cond' => [new Smaller($xVar, new LNumber(5))],
'loop' => [new PostInc($xVar)],
$variable = new Variable('x');
$for = new For_([
'init' => [new Assign($variable, new LNumber(0))],
'cond' => [new Smaller($variable, new LNumber(5))],
'loop' => [new PostInc($variable)],
'stmts' => [new Expression($funcCall)],
]);
@ -160,7 +160,7 @@ PHP
throw new ShouldNotHappenException();
}
$this->addNodeAfterNode($forNode, $previousStatement);
$this->addNodeAfterNode($for, $previousStatement);
return $assign;
}

View File

@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Rector\Naming\Guard;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
@ -52,17 +54,22 @@ final class BreakingVariableRenameGuard
$this->nodeNameResolver = $nodeNameResolver;
}
public function shouldSkip(
public function shouldSkipVariable(
string $currentName,
string $expectedName,
ClassMethod $classMethod,
Variable $variable
): bool {
// is the suffix? → also accepted
if (Strings::endsWith($currentName, ucfirst($expectedName))) {
return true;
}
if ($this->conflictingNameResolver->checkNameIsInClassMethod($expectedName, $classMethod)) {
return true;
}
if ($this->overridenExistingNamesResolver->checkNameInClassMethod($currentName, $classMethod)) {
if ($this->overridenExistingNamesResolver->checkNameInClassMethodForNew($currentName, $classMethod)) {
return true;
}
@ -70,11 +77,34 @@ final class BreakingVariableRenameGuard
return true;
}
if ($this->isUsedInIfAndOtherBranches($variable, $currentName)) {
return $this->isUsedInIfAndOtherBranches($variable, $currentName);
}
public function shouldSkipParam(
string $currentName,
string $expectedName,
ClassMethod $classMethod,
Param $param
): bool {
// is the suffix? → also accepted
if (Strings::endsWith($currentName, ucfirst($expectedName))) {
return true;
}
return false;
$conflictingNames = $this->conflictingNameResolver->resolveConflictingVariableNamesForParam($classMethod);
if (in_array($expectedName, $conflictingNames, true)) {
return true;
}
if ($this->conflictingNameResolver->checkNameIsInClassMethod($expectedName, $classMethod)) {
return true;
}
if ($this->overridenExistingNamesResolver->checkNameInClassMethodForParam($expectedName, $classMethod)) {
return true;
}
return $this->isVariableAlreadyDefined($param->var, $currentName);
}
private function isVariableAlreadyDefined(Variable $variable, string $currentVariableName): bool

View File

@ -43,12 +43,33 @@ final class OverridenExistingNamesResolver
$this->arrayFilter = $arrayFilter;
}
public function checkNameInClassMethod(string $variableName, ClassMethod $classMethod): bool
public function checkNameInClassMethodForNew(string $variableName, ClassMethod $classMethod): bool
{
$overridenVariableNames = $this->resolveOveriddenNamesForNew($classMethod);
return in_array($variableName, $overridenVariableNames, true);
}
public function checkNameInClassMethodForParam(string $expectedName, ClassMethod $classMethod): bool
{
/** @var Assign[] $assigns */
$assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Assign::class);
$usedVariableNames = [];
foreach ($assigns as $assign) {
if (! $assign->var instanceof Variable) {
continue;
}
$variableName = $this->nodeNameResolver->getName($assign->var);
if ($variableName === null) {
continue;
}
$usedVariableNames[] = $variableName;
}
return in_array($expectedName, $usedVariableNames, true);
}
/**
* @return string[]
*/
@ -64,6 +85,7 @@ final class OverridenExistingNamesResolver
/** @var Assign[] $assigns */
$assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Assign::class);
foreach ($assigns as $assign) {
/** @var Variable $assignVariable */
$assignVariable = $assign->var;

View File

@ -100,7 +100,7 @@ PHP
continue;
}
if ($this->breakingVariableRenameGuard->shouldSkip($currentName, $expectedName, $node, $variable)) {
if ($this->breakingVariableRenameGuard->shouldSkipVariable($currentName, $expectedName, $node, $variable)) {
continue;
}

View File

@ -15,6 +15,7 @@ use PhpParser\Node\VarLikeIdentifier;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Naming\Guard\BreakingVariableRenameGuard;
use Rector\Naming\Naming\ConflictingNameResolver;
use Rector\Naming\Naming\ExpectedNameResolver;
@ -38,12 +39,19 @@ final class RenamePropertyToMatchTypeRector extends AbstractRector
*/
private $hasChange = false;
/**
* @var BreakingVariableRenameGuard
*/
private $breakingVariableRenameGuard;
public function __construct(
BreakingVariableRenameGuard $breakingVariableRenameGuard,
ConflictingNameResolver $conflictingNameResolver,
ExpectedNameResolver $expectedNameResolver
) {
$this->conflictingNameResolver = $conflictingNameResolver;
$this->expectedNameResolver = $expectedNameResolver;
$this->breakingVariableRenameGuard = $breakingVariableRenameGuard;
}
public function getDefinition(): RectorDefinition
@ -110,15 +118,20 @@ PHP
private function refactorClassMethods(ClassLike $classLike): void
{
foreach ($classLike->getMethods() as $classMethod) {
$conflictingNames = $this->conflictingNameResolver->resolveConflictingVariableNamesForParam($classMethod);
foreach ($classMethod->params as $param) {
$expectedName = $this->expectedNameResolver->resolveForParamIfNotYet($param);
if ($expectedName === null) {
continue;
}
if (in_array($expectedName, $conflictingNames, true)) {
/** @var string $paramName */
$paramName = $this->getName($param);
if ($this->breakingVariableRenameGuard->shouldSkipParam(
$paramName,
$expectedName,
$classMethod,
$param
)) {
continue;
}

View File

@ -0,0 +1,16 @@
<?php
namespace Rector\Naming\Tests\Rector\ClassMethod\RenameVariableToMatchNewTypeRector\Fixture;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Param;
final class SkipNextSuffix
{
public function run(Param $resolverParam)
{
$setDefaultsMethodCall = new MethodCall($resolverParam->var, new Identifier('setDefaults'));
return $setDefaultsMethodCall;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixture;
use PhpParser\Node;
use PhpParser\Node\Stmt\If_;
class SkipExistingIf
{
private function shortenElseIf(If_ $node): ?Node
{
if ($node->else === null) {
return null;
}
$if = $node->else->stmts[0];
}
}

View File

@ -69,8 +69,8 @@ final class EventValueObjectClassFactory
*/
private function createConstructClassMethod(array $variableWithTypes): ClassMethod
{
$methodBuilder = new Method('__construct');
$methodBuilder->makePublic();
$method = new Method('__construct');
$method->makePublic();
foreach ($variableWithTypes as $variableWithType) {
$param = new Param(new Variable($variableWithType->getName()));
@ -79,24 +79,24 @@ final class EventValueObjectClassFactory
$param->type = $variableWithType->getPhpParserTypeNode();
}
$methodBuilder->addParam($param);
$method->addParam($param);
$assign = $this->nodeFactory->createPropertyAssignment($variableWithType->getName());
$methodBuilder->addStmt($assign);
$method->addStmt($assign);
}
return $methodBuilder->getNode();
return $method->getNode();
}
private function createEventClassBuilder(string $className): ClassBuilder
{
$shortClassName = $this->classNaming->getShortName($className);
$classBuilder = new ClassBuilder($shortClassName);
$classBuilder->makeFinal();
$classBuilder->extend(new FullyQualified('Symfony\Contracts\EventDispatcher\Event'));
$class = new ClassBuilder($shortClassName);
$class->makeFinal();
$class->extend(new FullyQualified('Symfony\Contracts\EventDispatcher\Event'));
return $classBuilder;
return $class;
}
private function wrapClassToNamespace(string $className, Class_ $class): Namespace_

View File

@ -272,8 +272,11 @@ PHP
$handleRequestMethodCall = new MethodCall($formVariable, 'handleRequest', [new Arg($requestVariable)]);
$classMethod->stmts[] = new Expression($handleRequestMethodCall);
$cond = new BooleanAnd(new MethodCall($formVariable, 'isSuccess'), new MethodCall($formVariable, 'isValid'));
$if = new If_($cond);
$booleanAnd = new BooleanAnd(new MethodCall($formVariable, 'isSuccess'), new MethodCall(
$formVariable,
'isValid'
));
$if = new If_($booleanAnd);
$classMethod->stmts[] = $if;

View File

@ -115,13 +115,13 @@ PHP
return $node;
}
private function renameArrayKeys(Return_ $returnNode): void
private function renameArrayKeys(Return_ $return): void
{
if (! $returnNode->expr instanceof Array_) {
if (! $return->expr instanceof Array_) {
return;
}
foreach ($returnNode->expr->items as $arrayItem) {
foreach ($return->expr->items as $arrayItem) {
$eventInfo = $this->matchStringKeys($arrayItem);
if ($eventInfo === null) {
$eventInfo = $this->matchClassConstKeys($arrayItem);
@ -136,7 +136,7 @@ PHP
), $eventInfo->getConstant());
// method name
$className = (string) $returnNode->getAttribute(AttributeKey::CLASS_NAME);
$className = (string) $return->getAttribute(AttributeKey::CLASS_NAME);
$methodName = (string) $this->getValue($arrayItem->value);
$this->processMethodArgument($className, $methodName, $eventInfo);
}

View File

@ -280,12 +280,12 @@ PHP
return false;
}
$methodReflection = new ReflectionMethod($className, $methodName);
if ($methodReflection->getReturnType() === null) {
$reflectionMethod = new ReflectionMethod($className, $methodName);
if ($reflectionMethod->getReturnType() === null) {
return false;
}
$staticCallReturnType = (string) $methodReflection->getReturnType();
$staticCallReturnType = (string) $reflectionMethod->getReturnType();
return is_a($staticCallReturnType, IRouter::class, true);
}
@ -317,10 +317,10 @@ PHP
return $phpDocInfo->hasByType(SymfonyRouteTagValueNode::class);
}
private function resolvePathFromClassAndMethodNodes(Class_ $classNode, ClassMethod $classMethod): string
private function resolvePathFromClassAndMethodNodes(Class_ $class, ClassMethod $classMethod): string
{
/** @var string $presenterName */
$presenterName = $this->getName($classNode);
$presenterName = $this->getName($class);
/** @var string $presenterPart */
$presenterPart = Strings::after($presenterName, '\\', -1);

View File

@ -91,8 +91,8 @@ PHP
['request', 'symfonyRequest']
);
$requestVariableNode = new Variable($requestName);
$headersPropertyFetch = new PropertyFetch($requestVariableNode, 'headers');
$variable = new Variable($requestName);
$headersPropertyFetch = new PropertyFetch($variable, 'headers');
$node->var = $headersPropertyFetch;
$node->name = new Identifier('get');

View File

@ -201,9 +201,9 @@ PHP
return $staticCall;
}
$delimCaptureConstant = new ConstFetch(new Name('PREG_SPLIT_DELIM_CAPTURE'));
$negatedDelimCaptureConstantAsInt = new BitwiseAnd(new LNumber(0), new BitwiseNot($delimCaptureConstant));
$staticCall->args[2] = new Arg($negatedDelimCaptureConstantAsInt);
$constFetch = new ConstFetch(new Name('PREG_SPLIT_DELIM_CAPTURE'));
$bitwiseAnd = new BitwiseAnd(new LNumber(0), new BitwiseNot($constFetch));
$staticCall->args[2] = new Arg($bitwiseAnd);
return $staticCall;
}

View File

@ -76,15 +76,15 @@ PHP
}
$key = $node->args[0]->value;
$leftVariable = new ArrayDimFetch($node->var, $key);
$arrayDimFetch = new ArrayDimFetch($node->var, $key);
$dateControlClass = new FullyQualified('Nextras\FormComponents\Controls\DateControl');
$newDateControl = new New_($dateControlClass);
$fullyQualified = new FullyQualified('Nextras\FormComponents\Controls\DateControl');
$new = new New_($fullyQualified);
if (isset($node->args[1])) {
$newDateControl->args[] = $node->args[1];
$new->args[] = $node->args[1];
}
return new Assign($leftVariable, $newDateControl);
return new Assign($arrayDimFetch, $new);
}
}

View File

@ -93,7 +93,7 @@ PHP
/**
* @return ClassConst[]
*/
private function resolveClassConstByPosition(Node\Stmt\Class_ $class): array
private function resolveClassConstByPosition(Class_ $class): array
{
$classConstConstsByValue = [];
foreach ($class->stmts as $key => $classStmt) {

View File

@ -29,13 +29,13 @@ final class StmtOrder
return array_combine($oldKeys, $newKeys);
}
public function reorderClassStmtsByOldToNewKeys(Class_ $node, array $oldToNewKeys): Class_
public function reorderClassStmtsByOldToNewKeys(Class_ $class, array $oldToNewKeys): Class_
{
$reorderedStmts = [];
$stmtCount = count($node->stmts);
$stmtCount = count($class->stmts);
foreach ($node->stmts as $key => $stmt) {
foreach ($class->stmts as $key => $stmt) {
if (! array_key_exists($key, $oldToNewKeys)) {
$reorderedStmts[$key] = $stmt;
continue;
@ -52,9 +52,9 @@ final class StmtOrder
continue;
}
$node->stmts[$i] = $reorderedStmts[$i];
$class->stmts[$i] = $reorderedStmts[$i];
}
return $node;
return $class;
}
}

View File

@ -71,8 +71,8 @@ PHP
$node->name = new Identifier('getConditions');
$dimFetch = new ArrayDimFetch($node, new LNumber(0));
$arrayDimFetch = new ArrayDimFetch($node, new LNumber(0));
return new Coalesce($dimFetch, new String_(''));
return new Coalesce($arrayDimFetch, new String_(''));
}
}

View File

@ -88,9 +88,9 @@ final class PhpSpecMockCollector
return in_array($variableName, $this->propertyMocksByClass[$className] ?? [], true);
}
public function getTypeForClassAndVariable(Class_ $node, string $variable): string
public function getTypeForClassAndVariable(Class_ $class, string $variable): string
{
$className = $this->nodeNameResolver->getName($node);
$className = $this->nodeNameResolver->getName($class);
if (! isset($this->mocksWithsTypes[$className][$variable])) {
throw new ShouldNotHappenException();

View File

@ -117,11 +117,11 @@ final class PhpSpecClassToPHPUnitClassRector extends AbstractPhpSpecToPHPUnitRec
throw new ShouldNotHappenException();
}
$newClass = new New_($testedObjectType);
$new = new New_($testedObjectType);
$letClassMethod = new ClassMethod(new Identifier('setUp'));
$this->makeProtected($letClassMethod);
$letClassMethod->stmts[] = new Expression(new Assign($propertyFetch, $newClass));
$letClassMethod->stmts[] = new Expression(new Assign($propertyFetch, $new));
$this->phpUnitTypeDeclarationDecorator->decorate($letClassMethod);
@ -131,9 +131,9 @@ final class PhpSpecClassToPHPUnitClassRector extends AbstractPhpSpecToPHPUnitRec
/**
* This is already checked on construction of object
*/
private function removeSelfTypeMethod(Class_ $node): Class_
private function removeSelfTypeMethod(Class_ $class): Class_
{
foreach ($node->getMethods() as $classMethod) {
foreach ($class->getMethods() as $classMethod) {
if (count((array) $classMethod->stmts) !== 1) {
continue;
}
@ -154,9 +154,9 @@ final class PhpSpecClassToPHPUnitClassRector extends AbstractPhpSpecToPHPUnitRec
}
// remove it
$this->removeNodeFromStatements($node, $classMethod);
$this->removeNodeFromStatements($class, $classMethod);
}
return $node;
return $class;
}
}

View File

@ -81,22 +81,22 @@ PHP
return $node;
}
private function processContinueStatement(Continue_ $node): Node
private function processContinueStatement(Continue_ $continue): Node
{
if ($node->num === null) {
if ($continue->num === null) {
return new Break_();
} elseif ($node->num instanceof LNumber) {
if ($this->getValue($node->num) <= 1) {
} elseif ($continue->num instanceof LNumber) {
if ($this->getValue($continue->num) <= 1) {
return new Break_();
}
} elseif ($node->num instanceof Variable) {
return $this->processVariableNum($node, $node->num);
} elseif ($continue->num instanceof Variable) {
return $this->processVariableNum($continue, $continue->num);
}
return $node;
return $continue;
}
private function processVariableNum(Continue_ $node, Variable $numVariable): Node
private function processVariableNum(Continue_ $continue, Variable $numVariable): Node
{
$staticType = $this->getStaticType($numVariable);
@ -104,6 +104,6 @@ PHP
return new Break_();
}
return $node;
return $continue;
}
}

View File

@ -118,11 +118,11 @@ PHP
return null;
}
$name = new FullyQualified($classLikeName);
$fullyQualified = new FullyQualified($classLikeName);
/** @see \Rector\PostRector\Collector\UseNodesToAddCollector::isShortImported() */
$name->setAttribute(AttributeKey::FILE_INFO, $node->getAttribute(AttributeKey::FILE_INFO));
$fullyQualified->setAttribute(AttributeKey::FILE_INFO, $node->getAttribute(AttributeKey::FILE_INFO));
return new ClassConstFetch($name, 'class');
return new ClassConstFetch($fullyQualified, 'class');
}
private function classLikeSensitiveExists(string $classLikeName): bool
@ -140,9 +140,9 @@ PHP
return false;
}
$classReflection = new ReflectionClass($classLikeName);
$reflectionClass = new ReflectionClass($classLikeName);
if ($classLikeName !== $classReflection->getName()) {
if ($classLikeName !== $reflectionClass->getName()) {
$this->sensitiveNonExistingClasses[] = $classLikeName;
return false;
}

View File

@ -105,9 +105,9 @@ final class EregToPregMatchRector extends AbstractRector
return $node;
}
private function processStringPattern(FuncCall $funcCall, String_ $patternNode, string $functionName): void
private function processStringPattern(FuncCall $funcCall, String_ $string, string $functionName): void
{
$pattern = $patternNode->value;
$pattern = $string->value;
$pattern = $this->eregToPcreTransformer->transform($pattern, $this->isCaseInsensitiveFunction($functionName));
$funcCall->args[0]->value = new String_($pattern);

View File

@ -138,9 +138,9 @@ PHP
}
// spaceship ready!
$spaceshipNode = new Spaceship($this->secondValue, $this->firstValue);
$spaceship = new Spaceship($this->secondValue, $this->firstValue);
return new Return_($spaceshipNode);
return new Return_($spaceship);
}
private function reset(): void

View File

@ -123,9 +123,9 @@ PHP
}
if ($this->isInstantiable($className)) {
$newNode = new New_($node->class);
$new = new New_($node->class);
return new MethodCall($newNode, $node->name, $node->args);
return new MethodCall($new, $node->name, $node->args);
}
// can we add static to method?

View File

@ -91,16 +91,16 @@ PHP
}
}
private function keepStatementsToParentCase(Case_ $caseNode): void
private function keepStatementsToParentCase(Case_ $case): void
{
$previousNode = $caseNode->getAttribute(AttributeKey::PREVIOUS_NODE);
$previousNode = $case->getAttribute(AttributeKey::PREVIOUS_NODE);
if (! $previousNode instanceof Case_) {
return;
}
if ($previousNode->stmts === []) {
$previousNode->stmts = $caseNode->stmts;
$caseNode->stmts = [];
$previousNode->stmts = $case->stmts;
$case->stmts = [];
}
}
}

View File

@ -90,11 +90,11 @@ PHP
// there is "$string[] = ...;", which would cause error in PHP 7+
// fallback - if no array init found, retype to (array)
$retypeArrayAssignNode = new Assign($arrayDimFetchNode->var, new ArrayCast($arrayDimFetchNode->var));
$assign = new Assign($arrayDimFetchNode->var, new ArrayCast($arrayDimFetchNode->var));
$this->addNodeAfterNode(clone $node, $node);
return $retypeArrayAssignNode;
return $assign;
}
/**

View File

@ -75,8 +75,8 @@ PHP
}
if ($this->isNullableType($countedNode) || $this->isStaticType($countedNode, NullType::class)) {
$identicalNode = new Identical($countedNode, $this->createNull());
$ternaryNode = new Ternary($identicalNode, new LNumber(0), $node);
$identical = new Identical($countedNode, $this->createNull());
$ternaryNode = new Ternary($identical, new LNumber(0), $node);
} else {
if ($this->isAtLeastPhpVersion(PhpVersionFeature::IS_COUNTABLE)) {
$conditionNode = new FuncCall(new Name('is_countable'), [new Arg($countedNode)]);

View File

@ -96,8 +96,8 @@ PHP
// $value = current($values);
// next($values);
$currentFuncCall = $this->createFuncCall('current', $eachFuncCall->args);
$assignCurrentNode = new Assign($listNode->items[1]->value, $currentFuncCall);
$this->addNodeAfterNode($assignCurrentNode, $node);
$assign = new Assign($listNode->items[1]->value, $currentFuncCall);
$this->addNodeAfterNode($assign, $node);
$nextFuncCall = $this->createFuncCall('next', $eachFuncCall->args);
$this->addNodeAfterNode($nextFuncCall, $node);

View File

@ -104,7 +104,7 @@ PHP
/** @var ArrayItem $valueItem */
$valueItem = array_pop($listNode->items);
$foreachNode = new Foreach_($foreachedExpr, $valueItem, [
$foreach = new Foreach_($foreachedExpr, $valueItem, [
'stmts' => $node->stmts,
]);
@ -114,10 +114,10 @@ PHP
$keyItem = array_pop($listNode->items);
if ($keyItem !== null) {
$foreachNode->keyVar = $keyItem->value;
$foreach->keyVar = $keyItem->value;
}
}
return $foreachNode;
return $foreach;
}
}

View File

@ -94,16 +94,16 @@ PHP
return null;
}
$condition = new NotIdentical($valueNode, $this->createNull());
$notIdentical = new NotIdentical($valueNode, $this->createNull());
$newFuncCallNode = new FuncCall($node->name, $node->args);
$ternaryNode = new Ternary($condition, $newFuncCallNode, new ClassConstFetch(new Name('self'), new Identifier(
$funcCall = new FuncCall($node->name, $node->args);
$ternary = new Ternary($notIdentical, $funcCall, new ClassConstFetch(new Name('self'), new Identifier(
'class'
)));
$newFuncCallNode->setAttribute(AttributeKey::PARENT_NODE, $ternaryNode);
$funcCall->setAttribute(AttributeKey::PARENT_NODE, $ternary);
return $ternaryNode;
return $ternary;
}
private function shouldSkip(FuncCall $funcCall): bool

View File

@ -64,10 +64,10 @@ PHP
return null;
}
$booleanNotNode = new BooleanNot($node);
$node->setAttribute(AttributeKey::PARENT_NODE, $booleanNotNode);
$booleanNot = new BooleanNot($node);
$node->setAttribute(AttributeKey::PARENT_NODE, $booleanNot);
return $booleanNotNode;
return $booleanNot;
}
private function shouldSkip(FuncCall $funcCall): bool

View File

@ -86,21 +86,21 @@ PHP
return $node;
}
private function escapeStringNode(String_ $stringNode): void
private function escapeStringNode(String_ $string): void
{
$stringValue = $stringNode->value;
$stringValue = $string->value;
if (Strings::match($stringValue, self::LEFT_HAND_UNESCAPED_DASH_PATTERN)) {
$stringNode->value = Strings::replace($stringValue, self::LEFT_HAND_UNESCAPED_DASH_PATTERN, '$1\-');
$string->value = Strings::replace($stringValue, self::LEFT_HAND_UNESCAPED_DASH_PATTERN, '$1\-');
// helped needed to skip re-escaping regular expression
$stringNode->setAttribute(AttributeKey::IS_REGULAR_PATTERN, true);
$string->setAttribute(AttributeKey::IS_REGULAR_PATTERN, true);
return;
}
if (Strings::match($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_PATTERN)) {
$stringNode->value = Strings::replace($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_PATTERN, '\-$1]');
$string->value = Strings::replace($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_PATTERN, '\-$1]');
// helped needed to skip re-escaping regular expression
$stringNode->setAttribute(AttributeKey::IS_REGULAR_PATTERN, true);
$string->setAttribute(AttributeKey::IS_REGULAR_PATTERN, true);
}
}
}

View File

@ -59,12 +59,12 @@ PHP
return null;
}
$newNode = new New_($node->class, [new Arg($node->args[0]->value)]);
$new = new New_($node->class, [new Arg($node->args[0]->value)]);
if (isset($node->args[1]) && $this->isTrue($node->args[1]->value)) {
return new String_($newNode);
return new String_($new);
}
return $newNode;
return $new;
}
}

View File

@ -11,10 +11,12 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\If_;
use PHPStan\Type\ArrayType;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
@ -193,7 +195,7 @@ final class TokenManipulator
/**
* @param Node[] $nodes
*/
public function removeIsArray(array $nodes, Expr\Variable $singleTokenVariable): void
public function removeIsArray(array $nodes, Variable $singleTokenVariable): void
{
$this->callableNodeTraverser->traverseNodesWithCallable($nodes, function (Node $node) use (
$singleTokenVariable
@ -297,7 +299,7 @@ final class TokenManipulator
return true;
}
if ($parentNode instanceof Expr\BooleanNot) {
if ($parentNode instanceof BooleanNot) {
$parentParentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentParentNode instanceof If_) {
$parentParentNode->cond = $parentNode;

View File

@ -8,6 +8,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Foreach_;
@ -113,7 +114,7 @@ PHP
private function refactorTokenInForeach(Foreach_ $tokensForeach): void
{
$singleToken = $tokensForeach->valueVar;
if (! $singleToken instanceof Expr\Variable) {
if (! $singleToken instanceof Variable) {
return;
}

View File

@ -23,10 +23,10 @@ final class TypeFactoryStaticHelper
}
// this is needed to prevent missing broker static fatal error, for tests with missing class
$unionTypeClassReflection = new ReflectionClass(UnionType::class);
$reflectionClass = new ReflectionClass(UnionType::class);
/** @var UnionType $unionType */
$unionType = $unionTypeClassReflection->newInstanceWithoutConstructor();
$unionType = $reflectionClass->newInstanceWithoutConstructor();
$privatesAccessor = new PrivatesAccessor();
$privatesAccessor->setPrivateProperty($unionType, 'types', $objectTypes);

View File

@ -113,10 +113,10 @@ PHP
return $this->classManipulator->hasTrait($class, self::PROPHECY_TRAIT);
}
private function hasProphesizeMethodCall(Class_ $node): bool
private function hasProphesizeMethodCall(Class_ $class): bool
{
return (bool) $this->betterNodeFinder->findFirst($node, function (Node $node) {
return $this->isMethodCall($node, 'this', 'prophesize');
return (bool) $this->betterNodeFinder->findFirst($class, function (Node $class) {
return $this->isMethodCall($class, 'this', 'prophesize');
});
}
}

View File

@ -98,11 +98,11 @@ PHP
if ($this->expectedKeys === []) {
// no keys → intersect!
$arrayIntersect = new FuncCall(new Name('array_intersect'));
$arrayIntersect->args[] = new Arg($expectedArray);
$arrayIntersect->args[] = $node->args[1];
$funcCall = new FuncCall(new Name('array_intersect'));
$funcCall->args[] = new Arg($expectedArray);
$funcCall->args[] = $node->args[1];
$identical = new Identical($arrayIntersect, $expectedArray);
$identical = new Identical($funcCall, $expectedArray);
$assertTrue = $this->createPHPUnitCallWithName($node, 'assertTrue');
$assertTrue->args[] = new Arg($identical);

View File

@ -172,10 +172,10 @@ PHP
* @param Node[] $nodes
* @return Node[]
*/
private function removeAllOtherNamespaces(array $nodes, Namespace_ $namespaceNode): array
private function removeAllOtherNamespaces(array $nodes, Namespace_ $namespace): array
{
foreach ($nodes as $key => $stmt) {
if ($stmt instanceof Namespace_ && $stmt !== $namespaceNode) {
if ($stmt instanceof Namespace_ && $stmt !== $namespace) {
unset($nodes[$key]);
}
}
@ -186,12 +186,12 @@ PHP
private function refactorClassLike(
SmartFileInfo $smartFileInfo,
bool $shouldDeleteFile,
Namespace_ $newStmt,
Namespace_ $namespace,
ClassLike $classLike,
array $newStmtsSet
): void {
$this->removeAllClassLikesFromNamespaceNode($newStmt);
$newStmt->stmts[] = $classLike;
$this->removeAllClassLikesFromNamespaceNode($namespace);
$namespace->stmts[] = $classLike;
$fileDestination = $this->createClassLikeFileDestination($classLike, $smartFileInfo);
@ -210,11 +210,11 @@ PHP
return $currentDirectory . DIRECTORY_SEPARATOR . $classLike->name . '.php';
}
private function removeAllClassLikesFromNamespaceNode(Namespace_ $namespaceNode): void
private function removeAllClassLikesFromNamespaceNode(Namespace_ $namespace): void
{
foreach ($namespaceNode->stmts as $key => $namespaceStatement) {
foreach ($namespace->stmts as $key => $namespaceStatement) {
if ($namespaceStatement instanceof ClassLike) {
unset($namespaceNode->stmts[$key]);
unset($namespace->stmts[$key]);
}
}
}

View File

@ -342,8 +342,8 @@ PHP
private function createContainerGetTypeMethodCall(ObjectType $objectType): MethodCall
{
$containerProperty = new StaticPropertyFetch(new Name('self'), 'container');
$getMethodCall = new MethodCall($containerProperty, 'get');
$staticPropertyFetch = new StaticPropertyFetch(new Name('self'), 'container');
$getMethodCall = new MethodCall($staticPropertyFetch, 'get');
$className = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($objectType);
if (! $className instanceof Name) {

View File

@ -34,20 +34,20 @@ final class StaticTypesInClassResolver
* @param string[] $types
* @return ObjectType[]
*/
public function collectStaticCallTypeInClass(Class_ $node, array $types): array
public function collectStaticCallTypeInClass(Class_ $class, array $types): array
{
$staticTypesInClass = [];
$this->callableNodeTraverser->traverseNodesWithCallable($node->stmts, function (Node $node) use (
$this->callableNodeTraverser->traverseNodesWithCallable($class->stmts, function (Node $class) use (
$types,
&$staticTypesInClass
) {
if (! $node instanceof StaticCall) {
if (! $class instanceof StaticCall) {
return null;
}
foreach ($types as $type) {
if ($this->nodeTypeResolver->isObjectType($node->class, $type)) {
if ($this->nodeTypeResolver->isObjectType($class->class, $type)) {
$staticTypesInClass[] = new FullyQualifiedObjectType($type);
}
}

View File

@ -288,12 +288,12 @@ final class ClassRenamer
});
}
private function isValidClassNameChange(Node $node, string $newName, Class_ $classNode): bool
private function isValidClassNameChange(Node $node, string $newName, Class_ $class): bool
{
if ($classNode->extends === $node && interface_exists($newName)) {
if ($class->extends === $node && interface_exists($newName)) {
return false;
}
return ! (in_array($node, $classNode->implements, true) && class_exists($newName));
return ! (in_array($node, $class->implements, true) && class_exists($newName));
}
private function isValidUseImportChange(string $newName, UseUse $useUse): bool

View File

@ -147,10 +147,10 @@ CODE_SAMPLE
private function getParentInterfaceIfFound(string $implementedInterfaceName): ?string
{
$interfaceReflection = new ReflectionClass($implementedInterfaceName);
$reflectionClass = new ReflectionClass($implementedInterfaceName);
// get first parent interface
return $interfaceReflection->getInterfaceNames()[0] ?? null;
return $reflectionClass->getInterfaceNames()[0] ?? null;
}
private function removeInterfaceFile(string $interfaceName, string $classFileLocation): void
@ -178,8 +178,8 @@ CODE_SAMPLE
private function resolveClassFileLocation(string $implementedInterfaceName)
{
$deadInterfaceReflection = new ReflectionClass($implementedInterfaceName);
return $deadInterfaceReflection->getFileName();
$reflectionClass = new ReflectionClass($implementedInterfaceName);
return $reflectionClass->getFileName();
}
private function removeOrReplaceImlementedInterface(string $implementedInterfaceName, Class_ $class, int $key): void

View File

@ -109,14 +109,14 @@ final class ThisRenderFactory
*
* @return Array_[]
*/
private function resolveArrayArgumentsFromMethodCall(Return_ $returnNode): array
private function resolveArrayArgumentsFromMethodCall(Return_ $return): array
{
if (! $returnNode->expr instanceof MethodCall) {
if (! $return->expr instanceof MethodCall) {
return [];
}
$arguments = [];
foreach ($returnNode->expr->args as $arg) {
foreach ($return->expr->args as $arg) {
if (! $arg->value instanceof Array_) {
continue;
}

View File

@ -108,13 +108,13 @@ PHP
return $node;
}
private function refactorUse(Use_ $user): ?Use_
private function refactorUse(Use_ $use): ?Use_
{
if ($user->type !== Use_::TYPE_NORMAL) {
if ($use->type !== Use_::TYPE_NORMAL) {
return null;
}
foreach ($user->uses as $useUse) {
foreach ($use->uses as $useUse) {
if (! $this->isName($useUse->name, 'Sensio\Bundle\FrameworkExtraBundle\Configuration\Route')) {
continue;
}
@ -122,6 +122,6 @@ PHP
$useUse->name = new Name('Symfony\Component\Routing\Annotation\Route');
}
return $user;
return $use;
}
}

View File

@ -112,19 +112,19 @@ PHP
return null;
}
private function addAbstractControllerParentClassIfMissing(Class_ $node): ?Class_
private function addAbstractControllerParentClassIfMissing(Class_ $class): ?Class_
{
if ($node->extends !== null) {
if ($class->extends !== null) {
return null;
}
if (! $this->classHasTemplateAnnotations($node)) {
if (! $this->classHasTemplateAnnotations($class)) {
return null;
}
$node->extends = new FullyQualified('Symfony\Bundle\FrameworkBundle\Controller\AbstractController');
$class->extends = new FullyQualified('Symfony\Bundle\FrameworkBundle\Controller\AbstractController');
return $node;
return $class;
}
private function replaceTemplateAnnotation(ClassMethod $classMethod): ?Node

View File

@ -66,8 +66,8 @@ final class InjectMethodFactory
$shortClassName = $this->classNaming->getShortName($className);
$methodBuilder = new Method('inject' . $shortClassName);
$methodBuilder->makePublic();
$method = new Method('inject' . $shortClassName);
$method->makePublic();
foreach ($objectTypes as $objectType) {
/** @var ObjectType $objectType */
@ -75,14 +75,14 @@ final class InjectMethodFactory
$param = new Param($propertyName);
$param->setType(new FullyQualified($objectType->getClassName()));
$methodBuilder->addParam($param);
$method->addParam($param);
$assign = $this->nodeFactory->createPropertyAssignment($propertyName);
$methodBuilder->addStmt($assign);
$method->addStmt($assign);
}
$classMethod = $methodBuilder->getNode();
$classMethod = $method->getNode();
if ($framework === MultiParentingToAbstractDependencyRector::FRAMEWORK_SYMFONY) {
$phpDocInfo = $this->phpDocInfoFactory->createEmpty($classMethod);

Some files were not shown because too many files have changed in this diff Show More