mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 09:42:45 +01:00
[cs] import namespaces
This commit is contained in:
parent
bd87eadc55
commit
b9b4c5c1b1
@ -3,7 +3,9 @@
|
||||
namespace Rector\CodeQuality\Rector\LogicalAnd;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\BinaryOp\LogicalAnd;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
@ -57,12 +59,12 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $node->left instanceof Node\Expr\Assign || ! $node->right instanceof Node\Expr\Assign) {
|
||||
if (! $node->left instanceof Assign || ! $node->right instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (! $parentNode instanceof Node\Stmt\Expression) {
|
||||
if (! $parentNode instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace Rector\CodingStyle\Rector\Namespace_;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
@ -260,7 +261,7 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
if (! $this->importsInClassCollection->hasImport($fullyQualifiedName)) {
|
||||
if ($node->getAttribute(AttributeKey::PARENT_NODE) instanceof Node\Expr\FuncCall) {
|
||||
if ($node->getAttribute(AttributeKey::PARENT_NODE) instanceof FuncCall) {
|
||||
$this->newFunctionUseStatements[$shortName] = $fullyQualifiedName;
|
||||
} else {
|
||||
$this->newUseStatements[$shortName] = $fullyQualifiedName;
|
||||
|
@ -12,7 +12,9 @@ use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\PhpParser\Node\NodeFactory;
|
||||
|
||||
/**
|
||||
@ -37,15 +39,15 @@ trait NodeFactoryTrait
|
||||
/**
|
||||
* @param Arg[] $args
|
||||
*/
|
||||
protected function createStaticCall(string $class, string $method, array $args = []): Expr\StaticCall
|
||||
protected function createStaticCall(string $class, string $method, array $args = []): StaticCall
|
||||
{
|
||||
if (in_array($class, ['self', 'parent', 'static'], true)) {
|
||||
$class = new Name($class);
|
||||
} else {
|
||||
$class = new Name\FullyQualified($class);
|
||||
$class = new FullyQualified($class);
|
||||
}
|
||||
|
||||
return new Node\Expr\StaticCall($class, $method, $args);
|
||||
return new StaticCall($class, $method, $args);
|
||||
}
|
||||
|
||||
protected function createClassConstant(string $class, string $constant): ClassConstFetch
|
||||
|
Loading…
x
Reference in New Issue
Block a user