Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,12 +59,12 @@ public function getNodeTypes(): array
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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_;
Expand Down Expand Up @@ -115,10 +116,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$this->newUseStatements = [];
$this->newFunctionUseStatements = [];
$this->importsInClassCollection->reset();
$this->docBlockManipulator->resetImportedNames();
$this->resetCollectedNames();

$this->resolveAlreadyImportedUses($node);

Expand Down Expand Up @@ -263,7 +261,7 @@ private function importNamesAndCollectNewUseStatements(Namespace_ $node): array
}

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;
Expand Down Expand Up @@ -342,4 +340,13 @@ private function isCurrentNamespace(string $namespaceName, string $newUseStateme

return ! Strings::contains($afterCurrentNamespace, '\\');
}

private function resetCollectedNames(): void
{
$this->newUseStatements = [];
$this->newFunctionUseStatements = [];
$this->alreadyUsedShortNames = [];
$this->importsInClassCollection->reset();
$this->docBlockManipulator->resetImportedNames();
}
}
8 changes: 5 additions & 3 deletions src/Rector/NodeFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
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;

/**
Expand All @@ -37,15 +39,15 @@ public function autowireNodeFactoryTrait(NodeFactory $nodeFactory): void
/**
* @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
Expand Down