mirror of
https://github.com/rectorphp/rector.git
synced 2024-09-03 22:22:14 +00:00
Fixes from PHPStan
This commit is contained in:
parent
5a963a6508
commit
32617ecbac
@ -25,7 +25,7 @@ final class PropertyFetchTypeResolverTest extends AbstractNodeTypeResolverTest
|
|||||||
$propertyFetchNodes = $this->getNodesForFileOfType($file, PropertyFetch::class);
|
$propertyFetchNodes = $this->getNodesForFileOfType($file, PropertyFetch::class);
|
||||||
$propertyFetchNode = $propertyFetchNodes[$nodePosition];
|
$propertyFetchNode = $propertyFetchNodes[$nodePosition];
|
||||||
|
|
||||||
$this->assertSame($propertyName, $propertyFetchNode->name->toString());
|
$this->assertSame($propertyName, (string) $propertyFetchNode->name);
|
||||||
$this->assertSame($expectedTypes, $this->nodeTypeResolver->resolve($propertyFetchNode));
|
$this->assertSame($expectedTypes, $this->nodeTypeResolver->resolve($propertyFetchNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
phpstan.neon
23
phpstan.neon
@ -19,37 +19,30 @@ parameters:
|
|||||||
# known values
|
# known values
|
||||||
- '#Argument of an invalid type array<PhpParser\\Node>\|null supplied for foreach, only iterables are supported#' # 1
|
- '#Argument of an invalid type array<PhpParser\\Node>\|null supplied for foreach, only iterables are supported#' # 1
|
||||||
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\Node::\$name#' # 2
|
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\Node::\$name#' # 2
|
||||||
- '#Calling method getName\(\) on possibly null value of type Rector\\Builder\\Class_\\VariableInfo\|null#' # 1
|
|
||||||
|
|
||||||
- '#Method Rector\\Node\\NodeFactory::create(Null|False)Constant\(\) should return PhpParser\\Node\\Expr\\ConstFetch but returns PhpParser\\Node\\Expr#' # 1
|
- '#Method Rector\\Node\\NodeFactory::createNullConstant\(\) should return PhpParser\\Node\\Expr\\ConstFetch but returns PhpParser\\Node\\Expr#' # 1
|
||||||
- '#Method Rector\\Node\\NodeFactory::createNamespace\(\) should return PhpParser\\Node\\Stmt\\Namespace_ but returns PhpParser\\Node#' # 1
|
- '#Method Rector\\Node\\NodeFactory::createNamespace\(\) should return PhpParser\\Node\\Stmt\\Namespace_ but returns PhpParser\\Node#' # 1
|
||||||
- '#Calling method getText\(\) on possibly null value of type PhpParser\\Comment\\Doc\|null#' # 3
|
- '#Calling method getText\(\) on possibly null value of type PhpParser\\Comment\\Doc\|null#' # 3
|
||||||
- '#Instanceof between PhpParser\\Node\\Expr\|string and PhpParser\\Node\\Identifier will always evaluate to false#' # 8
|
- '#Instanceof between PhpParser\\Node\\Expr\|string and PhpParser\\Node\\(Identifier|Name) will always evaluate to false#' # 9
|
||||||
- '#Method Rector\\NodeTraverserQueue\\BetterNodeFinder::findFirstAncestorInstanceOf\(\) should return PhpParser\\Node\|null but returns object#' # 1
|
- '#Method Rector\\NodeTraverserQueue\\BetterNodeFinder::findFirstAncestorInstanceOf\(\) should return PhpParser\\Node\|null but returns object#' # 1
|
||||||
- '#Access to an undefined property PhpParser\\Node\\Stmt\\ClassLike::\$namespacedName#' # 2
|
- '#Access to an undefined property PhpParser\\Node\\Stmt\\(Class_|ClassLike)::\$namespacedName#' # 3
|
||||||
- '#Access to an undefined property PhpParser\\Node\\Stmt\\Class_::\$namespacedName#' # 1
|
|
||||||
- '#Property Rector\\NodeTypeResolver\\NodeVisitor\\NamespaceResolver::\$useNodes \(array<PhpParser\\Node\\Stmt\\Use_>\) does not accept array<PhpParser\\Node>#' # 1
|
- '#Property Rector\\NodeTypeResolver\\NodeVisitor\\NamespaceResolver::\$useNodes \(array<PhpParser\\Node\\Stmt\\Use_>\) does not accept array<PhpParser\\Node>#' # 1
|
||||||
- '#Parameter \#1 \$classMethodNode of method Rector\\NodeTypeResolver\\TypesExtractor\\ConstructorPropertyTypesExtractor::extractPropertiesFromConstructorMethodNode\(\) expects PhpParser\\Node\\Stmt\\ClassMethod, PhpParser\\Node given#' # 1
|
- '#Parameter \#1 \$classMethodNode of method Rector\\NodeTypeResolver\\TypesExtractor\\ConstructorPropertyTypesExtractor::extractPropertiesFromConstructorMethodNode\(\) expects PhpParser\\Node\\Stmt\\ClassMethod, PhpParser\\Node given#' # 1
|
||||||
- '#Instanceof between PhpParser\\Node\\Expr\|string and PhpParser\\Node\\Name will always evaluate to false#' # 1
|
|
||||||
- '#Parameter \#1 \$node of method Rector\\NodeTypeResolver\\NodeTypeResolver::resolve\(\) expects PhpParser\\Node, PhpParser\\Node\\Expr|string given#' # 3
|
- '#Parameter \#1 \$node of method Rector\\NodeTypeResolver\\NodeTypeResolver::resolve\(\) expects PhpParser\\Node, PhpParser\\Node\\Expr|string given#' # 3
|
||||||
- '#Method Rector\\NodeTraverser\\RectorNodeTraverser::getRectors\(\) should return array<Rector\\Contract\\Rector\\RectorInterface> but returns array<PhpParser\\NodeVisitor>#' # 1
|
- '#Method Rector\\NodeTraverser\\RectorNodeTraverser::getRectors\(\) should return array<Rector\\Contract\\Rector\\RectorInterface> but returns array<PhpParser\\NodeVisitor>#' # 1
|
||||||
|
|
||||||
# known value of Name of MethodCall
|
|
||||||
- '#Cannot call method toString\(\) on PhpParser\\Node\\Expr\|string#' # 4
|
|
||||||
|
|
||||||
# buggy
|
# buggy
|
||||||
- '#Access to an undefined property PhpParser\\Node::\$args#' # 8
|
- '#Access to an undefined property PhpParser\\Node\\Expr::\$value#' # 2
|
||||||
- '#Parameter \#1 \$classLikeNode of method Rector\\NodeAnalyzer\\ClassLikeAnalyzer::resolveExtendsTypes\(\) expects PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt\\Interface_, PhpParser\\Node\\Stmt\\ClassLike given#' # 1
|
- '#Parameter \#1 \$classLikeNode of method Rector\\NodeAnalyzer\\ClassLikeAnalyzer::resolveExtendsTypes\(\) expects PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt\\Interface_, PhpParser\\Node\\Stmt\\ClassLike given#' # 1
|
||||||
- '#Parameter \#1 \$functionLikeNode of method Rector\\NodeTypeResolver\\TypeContext::getFunctionReflection\(\) expects PhpParser\\Node\\Expr\\Closure\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Function_, PhpParser\\Node\\FunctionLike given#' # 1
|
- '#Parameter \#1 \$functionLikeNode of method Rector\\NodeTypeResolver\\TypeContext::getFunctionReflection\(\) expects PhpParser\\Node\\Expr\\Closure\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Function_, PhpParser\\Node\\FunctionLike given#' # 1
|
||||||
- '#Access to an undefined property PhpParser\\Node\\Param::\$var#' # 4
|
- '#Access to an undefined property PhpParser\\Node\\Param::\$var#' # 4
|
||||||
- '#Call to an undefined method PhpParser\\BuilderFactory::(classConstFetch|methodCall|staticCall)\(\)#' # 8
|
- '#Call to an undefined method PhpParser\\BuilderFactory::(args|classConstFetch|methodCall|staticCall)\(\)#' # 9
|
||||||
- '#Call to an undefined method PhpParser\\BuilderFactory::args\(\)#' # 1
|
|
||||||
- "#Casting to string something that's already string#" # 4
|
- "#Casting to string something that's already string#" # 4
|
||||||
- '#Call to an undefined method PhpParser\\Node\\Stmt\\UseUse::getAlias\(\)#' # 2
|
- '#Call to an undefined method PhpParser\\Node\\Stmt\\UseUse::getAlias\(\)#' # 2
|
||||||
- '#Call to an undefined method PhpParser\\PrettyPrinter\\Standard::printFormatPreserving\(\)#' # 1
|
- '#Call to an undefined method PhpParser\\PrettyPrinter\\Standard::printFormatPreserving\(\)#' # 1
|
||||||
- '#Access to an undefined property PhpParser\\Node\\Expr::\$var#' # 1
|
- '#Access to an undefined property PhpParser\\Node\\Expr::\$(name|var)#' # 2
|
||||||
- '#Access to an undefined property PhpParser\\Node\\Expr::\$name#' # 2
|
- '#Call to an undefined method PhpParser\\Node\\Expr\\BinaryOp::getOperatorSigil\(\).#' # 1
|
||||||
- '#Call to an undefined method PhpParser\\Node\\Expr|PhpParser\\Node\\Name::toCodeString\(\).#' # 9
|
- '#Call to an undefined method PhpParser\\Node\\Expr\\ArrayItem::getComments\(\).#' # 2
|
||||||
|
|
||||||
excludes_analyse:
|
excludes_analyse:
|
||||||
# test files
|
# test files
|
||||||
|
@ -36,20 +36,18 @@ final class ChainMethodCallAnalyzer
|
|||||||
// node chaining is in reverse order than code
|
// node chaining is in reverse order than code
|
||||||
$methods = array_reverse($methods);
|
$methods = array_reverse($methods);
|
||||||
|
|
||||||
$currentMethodCall = $node;
|
|
||||||
|
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
if ((string) $currentMethodCall->name !== $method) {
|
if ((string) $node->name !== $method) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentMethodCall = $currentMethodCall->var;
|
$node = $node->var;
|
||||||
if ($currentMethodCall instanceof MethodCall) {
|
if ($node instanceof MethodCall) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$variableTypes = $this->nodeTypeResolver->resolve($currentMethodCall);
|
$variableTypes = $this->nodeTypeResolver->resolve($node);
|
||||||
|
|
||||||
return in_array($type, $variableTypes, true);
|
return in_array($type, $variableTypes, true);
|
||||||
}
|
}
|
||||||
|
@ -33,16 +33,21 @@ final class MethodArgumentAnalyzer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $node->args[$position - 1]->value instanceof String_;
|
/** @var MethodCall $methodCallNode */
|
||||||
|
$methodCallNode = $node;
|
||||||
|
|
||||||
|
return $methodCallNode->args[$position - 1]->value instanceof String_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isMethodNthArgumentNull(Node $methodCallNode, int $position): bool
|
public function isMethodNthArgumentNull(Node $node, int $position): bool
|
||||||
{
|
{
|
||||||
if (! $this->hasMethodNthArgument($methodCallNode, $position)) {
|
if (! $this->hasMethodNthArgument($node, $position)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var MethodCall $methodCallNode */
|
/** @var MethodCall $methodCallNode */
|
||||||
|
$methodCallNode = $node;
|
||||||
|
|
||||||
$value = $methodCallNode->args[$position - 1]->value;
|
$value = $methodCallNode->args[$position - 1]->value;
|
||||||
if (! $value instanceof ConstFetch) {
|
if (! $value instanceof ConstFetch) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -22,7 +22,7 @@ final class ReplaceVariableByPropertyFetchRector extends AbstractRector
|
|||||||
private $variablesToPropertyFetchCollection;
|
private $variablesToPropertyFetchCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var VariableInfo|null
|
* @var VariableInfo
|
||||||
*/
|
*/
|
||||||
private $activeVariableInfo;
|
private $activeVariableInfo;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ final class SomeController
|
|||||||
* @var ProductRepository
|
* @var ProductRepository
|
||||||
*/
|
*/
|
||||||
private $productRepository;
|
private $productRepository;
|
||||||
|
|
||||||
public function __construct(ProductRepository $productRepository)
|
public function __construct(ProductRepository $productRepository)
|
||||||
{
|
{
|
||||||
$this->productRepository = $productRepository;
|
$this->productRepository = $productRepository;
|
||||||
@ -61,7 +61,7 @@ final class SomeController
|
|||||||
public function default()
|
public function default()
|
||||||
{
|
{
|
||||||
$products = $productRepository->fetchAll();
|
$products = $productRepository->fetchAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CODE_SAMPLE
|
CODE_SAMPLE
|
||||||
,
|
,
|
||||||
@ -72,7 +72,7 @@ final class SomeController
|
|||||||
* @var ProductRepository
|
* @var ProductRepository
|
||||||
*/
|
*/
|
||||||
private $productRepository;
|
private $productRepository;
|
||||||
|
|
||||||
public function __construct(ProductRepository $productRepository)
|
public function __construct(ProductRepository $productRepository)
|
||||||
{
|
{
|
||||||
$this->productRepository = $productRepository;
|
$this->productRepository = $productRepository;
|
||||||
@ -81,7 +81,7 @@ final class SomeController
|
|||||||
public function default()
|
public function default()
|
||||||
{
|
{
|
||||||
$products = $this->productRepository->fetchAll();
|
$products = $this->productRepository->fetchAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CODE_SAMPLE
|
CODE_SAMPLE
|
||||||
),
|
),
|
||||||
@ -91,8 +91,6 @@ CODE_SAMPLE
|
|||||||
|
|
||||||
public function isCandidate(Node $node): bool
|
public function isCandidate(Node $node): bool
|
||||||
{
|
{
|
||||||
$this->activeVariableInfo = null;
|
|
||||||
|
|
||||||
if (! $node instanceof Variable) {
|
if (! $node instanceof Variable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
class SomeRepository extends EntityRepository
|
class SomeRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
public function someMethod()
|
public function someMethod()
|
||||||
@ -78,7 +78,7 @@ SAMPLE
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
class SomeRepository extends EntityRepository
|
class SomeRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
public function someMethod()
|
public function someMethod()
|
||||||
|
@ -115,14 +115,16 @@ CODE_SAMPLE
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var MethodCall $node */
|
/** @var MethodCall $methodCallNode */
|
||||||
if (count($node->args) !== 1) {
|
$methodCallNode = $node;
|
||||||
|
|
||||||
|
if (count($methodCallNode->args) !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node->args[0]->value instanceof String_) {
|
if ($methodCallNode->args[0]->value instanceof String_) {
|
||||||
/** @var String_ $string */
|
/** @var String_ $string */
|
||||||
$string = $node->args[0]->value;
|
$string = $methodCallNode->args[0]->value;
|
||||||
|
|
||||||
// is alias
|
// is alias
|
||||||
if (Strings::contains($string->value, ':')) {
|
if (Strings::contains($string->value, ':')) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Rector\Rector\Contrib\Doctrine;
|
namespace Rector\Rector\Contrib\Doctrine;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
use Rector\Node\NodeFactory;
|
use Rector\Node\NodeFactory;
|
||||||
use Rector\NodeAnalyzer\MethodArgumentAnalyzer;
|
use Rector\NodeAnalyzer\MethodArgumentAnalyzer;
|
||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
@ -64,16 +65,22 @@ final class AliasToClassRector extends AbstractRector
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->isAliasWithConfiguredEntity($node->args[0]->value->value);
|
/** @var MethodCall $methodCall */
|
||||||
|
$methodCall = $node;
|
||||||
|
|
||||||
|
return $this->isAliasWithConfiguredEntity($methodCall->args[0]->value->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refactor(Node $node): ?Node
|
/**
|
||||||
|
* @param MethodCall $methodCall
|
||||||
|
*/
|
||||||
|
public function refactor(Node $methodCall): ?Node
|
||||||
{
|
{
|
||||||
$node->args[0]->value = $this->nodeFactory->createClassConstantReference(
|
$methodCall->args[0]->value = $this->nodeFactory->createClassConstantReference(
|
||||||
$this->convertAliasToFqn($node->args[0]->value->value)
|
$this->convertAliasToFqn($methodCall->args[0]->value->value)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $node;
|
return $methodCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isAlias(string $name): bool
|
private function isAlias(string $name): bool
|
||||||
|
@ -96,7 +96,7 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$methodName = $secondArgumentValue->name->toString();
|
$methodName = (string) $secondArgumentValue->name;
|
||||||
$this->activeFuncCallName = $methodName;
|
$this->activeFuncCallName = $methodName;
|
||||||
|
|
||||||
return isset($this->defaultOldToNewMethods[$methodName]);
|
return isset($this->defaultOldToNewMethods[$methodName]);
|
||||||
|
@ -111,7 +111,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractPHPUnitRector
|
|||||||
unset($oldArgs[0]);
|
unset($oldArgs[0]);
|
||||||
|
|
||||||
$node->args = array_merge($this->nodeFactory->createArgs([
|
$node->args = array_merge($this->nodeFactory->createArgs([
|
||||||
$this->nodeFactory->createString($propertyFetchNode->name->toString()),
|
$this->nodeFactory->createString((string) $propertyFetchNode->name),
|
||||||
$propertyFetchNode->var,
|
$propertyFetchNode->var,
|
||||||
]), $oldArgs);
|
]), $oldArgs);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ final class AssertPropertyExistsRector extends AbstractPHPUnitRector
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$methodName = $firstArgumentValue->name->toString();
|
$methodName = (string) $firstArgumentValue->name;
|
||||||
|
|
||||||
return $methodName === 'property_exists';
|
return $methodName === 'property_exists';
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ final class AssertRegExpRector extends AbstractPHPUnitRector
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$methodName = $secondArgumentValue->name->toString();
|
$methodName = (string) $secondArgumentValue->name;
|
||||||
|
|
||||||
return $methodName === 'preg_match';
|
return $methodName === 'preg_match';
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$methodName = $firstArgumentValue->name->toString();
|
$methodName = (string) $firstArgumentValue->name;
|
||||||
|
|
||||||
return isset($this->oldMethodsToTypes[$methodName]);
|
return isset($this->oldMethodsToTypes[$methodName]);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
|
|||||||
/** @var FuncCall $isFunctionNode */
|
/** @var FuncCall $isFunctionNode */
|
||||||
$isFunctionNode = $methodCallNode->args[0]->value;
|
$isFunctionNode = $methodCallNode->args[0]->value;
|
||||||
$argument = $isFunctionNode->args[0]->value;
|
$argument = $isFunctionNode->args[0]->value;
|
||||||
$isFunctionName = $isFunctionNode->name->toString();
|
$isFunctionName = (string) $isFunctionNode->name;
|
||||||
|
|
||||||
$oldArguments = $methodCallNode->args;
|
$oldArguments = $methodCallNode->args;
|
||||||
unset($oldArguments[0]);
|
unset($oldArguments[0]);
|
||||||
|
@ -154,7 +154,7 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractPHPUnitRector
|
|||||||
{
|
{
|
||||||
$funcCallOrEmptyNode = $methodCallNode->args[0]->value;
|
$funcCallOrEmptyNode = $methodCallNode->args[0]->value;
|
||||||
if ($funcCallOrEmptyNode instanceof FuncCall) {
|
if ($funcCallOrEmptyNode instanceof FuncCall) {
|
||||||
$funcCallOrEmptyNodeName = $funcCallOrEmptyNode->name->toString();
|
$funcCallOrEmptyNodeName = (string) $funcCallOrEmptyNode->name;
|
||||||
$funcCallOrEmptyNodeArgs = $funcCallOrEmptyNode->args;
|
$funcCallOrEmptyNodeArgs = $funcCallOrEmptyNode->args;
|
||||||
$oldArguments = $methodCallNode->args;
|
$oldArguments = $methodCallNode->args;
|
||||||
unset($oldArguments[0]);
|
unset($oldArguments[0]);
|
||||||
|
@ -58,17 +58,18 @@ final class OptionNameRector extends AbstractRector
|
|||||||
}
|
}
|
||||||
|
|
||||||
$arrayParentNode = $arrayItemParentNode->getAttribute(Attribute::PARENT_NODE);
|
$arrayParentNode = $arrayItemParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||||
$argParentNode = $arrayParentNode->getAttribute(Attribute::PARENT_NODE);
|
|
||||||
|
|
||||||
/** @var MethodCall $argParentNode */
|
/** @var MethodCall $argParentNode */
|
||||||
$methodCallNode = $argParentNode->getAttribute(Attribute::PARENT_NODE);
|
$argParentNode = $arrayParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||||
|
|
||||||
/** @var MethodCall|Node $methodCallNode */
|
/** @var MethodCall|Node $methodCallNode */
|
||||||
|
$methodCallNode = $argParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||||
|
|
||||||
if (! $methodCallNode instanceof MethodCall) {
|
if (! $methodCallNode instanceof MethodCall) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $methodCallNode->name->toString() === 'add';
|
return (string) $methodCallNode->name === 'add';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,13 +52,13 @@ final class FluentReplaceRector extends AbstractRector
|
|||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function otherFunction()
|
public function otherFunction()
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$someClass = new SomeClass();
|
$someClass = new SomeClass();
|
||||||
$someClass->someFunction()
|
$someClass->someFunction()
|
||||||
->otherFunction();
|
->otherFunction();
|
||||||
@ -70,12 +70,12 @@ CODE_SAMPLE
|
|||||||
public function someFunction()
|
public function someFunction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function otherFunction()
|
public function otherFunction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$someClass = new SomeClass();
|
$someClass = new SomeClass();
|
||||||
$someClass->someFunction();
|
$someClass->someFunction();
|
||||||
$someClass->otherFunction();
|
$someClass->otherFunction();
|
||||||
@ -152,7 +152,7 @@ CODE_SAMPLE
|
|||||||
{
|
{
|
||||||
$nextMethodCallNode = $this->methodCallNodeFactory->createWithVariableAndMethodName(
|
$nextMethodCallNode = $this->methodCallNodeFactory->createWithVariableAndMethodName(
|
||||||
$innerMethodCallNode->var,
|
$innerMethodCallNode->var,
|
||||||
$outerMethodCallNode->name->toString()
|
(string) $outerMethodCallNode->name
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addNodeAfterNode($nextMethodCallNode, $innerMethodCallNode);
|
$this->addNodeAfterNode($nextMethodCallNode, $innerMethodCallNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user