mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-19 06:52:51 +02:00
make use of createStaticCall
This commit is contained in:
parent
518e891d99
commit
7a07fe6a70
@ -63,10 +63,7 @@ CODE_SAMPLE
|
||||
{
|
||||
foreach ($this->functionToStaticMethod as $function => $staticMethod) {
|
||||
if ($this->isName($node, $function)) {
|
||||
$staticCall = $this->createStaticCall('Nette\Utils\Strings', $staticMethod);
|
||||
$staticCall->args = $node->args;
|
||||
|
||||
return $staticCall;
|
||||
return $this->createStaticCall('Nette\Utils\Strings', $staticMethod, $node->args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use Rector\Exception\Rector\InvalidRectorConfigurationException;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
@ -129,7 +128,12 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
return new StaticCall(new Name('self'), $node->name);
|
||||
$name = $this->getName($node->name);
|
||||
if ($name === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createStaticCall('self', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,8 +4,6 @@ namespace Rector\Php\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use Rector\NodeTypeResolver\Application\FunctionLikeNodeCollector;
|
||||
use Rector\NodeTypeResolver\Node\Attribute;
|
||||
use Rector\Rector\AbstractRector;
|
||||
@ -99,6 +97,6 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
return new StaticCall(new Name('self'), $methodName);
|
||||
return $this->createStaticCall('self', $methodName);
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ final class PhpSpecPromisesToPHPUnitAssertRector extends AbstractPhpSpecToPHPUni
|
||||
if ($this->isName($methodCall, 'beConstructedThrough')) {
|
||||
// static method
|
||||
$methodName = $this->getValue($methodCall->args[0]->value);
|
||||
$staticCall = new StaticCall(new FullyQualified($this->testedClass), $methodName);
|
||||
$staticCall = $this->createStaticCall($this->testedClass, $methodName);
|
||||
|
||||
$this->moveConstructorArguments($methodCall, $staticCall);
|
||||
|
||||
|
@ -6,8 +6,6 @@ use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
@ -44,9 +42,6 @@ final class ConstantToStaticCallRector extends AbstractRector
|
||||
return null;
|
||||
}
|
||||
|
||||
$staticCallNode = new StaticCall(new FullyQualified('Environment'), 'getEnv');
|
||||
$staticCallNode->args[] = new Arg(new String_($constantName));
|
||||
|
||||
return $staticCallNode;
|
||||
return $this->createStaticCall('Environment', 'getEnv', [new Arg(new String_($constantName))]);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ namespace Rector\Silverstripe\Rector;
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
@ -51,9 +49,6 @@ final class DefineConstantToStaticCallRector extends AbstractRector
|
||||
return null;
|
||||
}
|
||||
|
||||
$staticCallNode = new StaticCall(new FullyQualified('Environment'), 'getEnv');
|
||||
$staticCallNode->args = $node->args;
|
||||
|
||||
return $staticCallNode;
|
||||
return $this->createStaticCall('Environment', 'getEnv', $node->args);
|
||||
}
|
||||
}
|
||||
|
@ -144,4 +144,5 @@ parameters:
|
||||
- '#Method Rector\\NodeTypeResolver\\NodeVisitor\\(.*?)\:\:enterNode\(\) should return int\|PhpParser\\Node\|void\|null but return statement is missing#'
|
||||
- '#Negated boolean expression is always true#'
|
||||
- '#Strict comparison using \=\=\= between PhpParser\\Node and null will always evaluate to false#'
|
||||
|
||||
- '#In method "Rector\\FileSystemRector\\Rector\\AbstractFileSystemRector\:\:createStaticCall", parameter \$args type is "array"\. Please provide a @param annotation to further specify the type of the array\. For instance\: @param int\[\] \$args\. More info\: http\://bit\.ly/typehintarray#'
|
||||
- '#In method "Rector\\Rector\\AbstractRector\:\:createStaticCall", parameter \$args type is "array"\. Please provide a @param annotation to further specify the type of the array\. For instance\: @param int\[\] \$args\. More info\: http\://bit\.ly/typehintarray#'
|
||||
|
@ -4,8 +4,6 @@ namespace Rector\Rector\Function_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
@ -58,7 +56,7 @@ final class FunctionToStaticCallRector extends AbstractRector
|
||||
|
||||
[$className, $methodName] = $staticCall;
|
||||
|
||||
return new StaticCall(new FullyQualified($className), $methodName, $node->args);
|
||||
return $this->createStaticCall($className, $methodName, $node->args);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -4,8 +4,6 @@ namespace Rector\Rector\New_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
@ -74,9 +72,7 @@ CODE_SAMPLE
|
||||
continue;
|
||||
}
|
||||
|
||||
$className = new FullyQualified($staticCall[0]);
|
||||
|
||||
return new StaticCall($className, $staticCall[1], $node->args);
|
||||
return $this->createStaticCall($staticCall[0], $staticCall[1], $node->args);
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
@ -34,9 +34,18 @@ trait NodeFactoryTrait
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
|
||||
protected function createStaticCall(string $class, string $method): Expr\StaticCall
|
||||
/**
|
||||
* @param Arg[] $args
|
||||
*/
|
||||
protected function createStaticCall(string $class, string $method, array $args = []): Expr\StaticCall
|
||||
{
|
||||
return new Node\Expr\StaticCall(new Node\Name\FullyQualified($class), $method);
|
||||
if (in_array($class, ['self', 'parent', 'static'], true)) {
|
||||
$class = new Name($class);
|
||||
} else {
|
||||
$class = new Name\FullyQualified($class);
|
||||
}
|
||||
|
||||
return new Node\Expr\StaticCall($class, $method, $args);
|
||||
}
|
||||
|
||||
protected function createClassConstant(string $class, string $constant): ClassConstFetch
|
||||
|
Loading…
x
Reference in New Issue
Block a user