[cs] import namespaces

This commit is contained in:
Tomas Votruba 2019-05-05 20:48:46 +02:00
parent bd87eadc55
commit b9b4c5c1b1
3 changed files with 11 additions and 6 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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