Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 23, 2021
1 parent dc1c2c7 commit ef8cf2b
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt\Nop;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
Expand All @@ -28,11 +27,6 @@ final class PhpDocInfoTest extends AbstractKernelTestCase
*/
private $phpDocInfoPrinter;

/**
* @var Node
*/
private $node;

/**
* @var SmartFileSystem
*/
Expand Down Expand Up @@ -86,9 +80,9 @@ private function createPhpDocInfoFromFile(string $path): PhpDocInfo
$phpDocInfoFactory = $this->getService(PhpDocInfoFactory::class);
$phpDocContent = $this->smartFileSystem->readFile($path);

$this->node = new Nop();
$this->node->setDocComment(new Doc($phpDocContent));
$nop = new Nop();
$nop->setDocComment(new Doc($phpDocContent));

return $phpDocInfoFactory->createFromNode($this->node);
return $phpDocInfoFactory->createFromNode($nop);
}
}
53 changes: 0 additions & 53 deletions packages/NodeCollector/NodeCollector/NodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ final class NodeRepository
*/
private $parsedPropertyFetchNodeCollector;

/**
* @var ParsedClassConstFetchNodeCollector
*/
private $parsedClassConstFetchNodeCollector;

/**
* @var ParsedNodeCollector
*/
Expand Down Expand Up @@ -132,7 +127,6 @@ public function __construct(
ArrayCallableMethodReferenceAnalyzer $arrayCallableMethodReferenceAnalyzer,
ParsedPropertyFetchNodeCollector $parsedPropertyFetchNodeCollector,
NodeNameResolver $nodeNameResolver,
ParsedClassConstFetchNodeCollector $parsedClassConstFetchNodeCollector,
ParsedNodeCollector $parsedNodeCollector,
TypeUnwrapper $typeUnwrapper,
ReflectionProvider $reflectionProvider,
Expand All @@ -141,7 +135,6 @@ public function __construct(
$this->nodeNameResolver = $nodeNameResolver;
$this->arrayCallableMethodReferenceAnalyzer = $arrayCallableMethodReferenceAnalyzer;
$this->parsedPropertyFetchNodeCollector = $parsedPropertyFetchNodeCollector;
$this->parsedClassConstFetchNodeCollector = $parsedClassConstFetchNodeCollector;
$this->parsedNodeCollector = $parsedNodeCollector;
$this->typeUnwrapper = $typeUnwrapper;
$this->reflectionProvider = $reflectionProvider;
Expand Down Expand Up @@ -360,52 +353,6 @@ public function findCallsByClassMethod(ClassMethod $classMethod): array
return $this->findCallsByClassAndMethod($class, $method);
}

/**
* @return ClassReflection[]
*/
public function findDirectClassConstantFetches(ClassReflection $classReflection, string $desiredConstantName): array
{
$classConstantFetchByClassAndName = $this->parsedClassConstFetchNodeCollector->getClassConstantFetchByClassAndName();
$classTypes = $classConstantFetchByClassAndName[$classReflection->getName()][$desiredConstantName] ?? [];

return $this->resolveClassReflectionsFromClassTypes($classTypes);
}

/**
* @return ClassReflection[]
*/
public function findIndirectClassConstantFetches(
ClassReflection $classReflection,
string $desiredConstantName
): array {
$classConstantFetchByClassAndName = $this->parsedClassConstFetchNodeCollector->getClassConstantFetchByClassAndName();

foreach ($classConstantFetchByClassAndName as $className => $classesByConstantName) {
if (! $this->reflectionProvider->hasClass($className)) {
return [];
}

$currentClassReflection = $this->reflectionProvider->getClass($className);
if (! isset($classesByConstantName[$desiredConstantName])) {
continue;
}

if (! $classReflection->isSubclassOf($currentClassReflection->getName()) &&
! $currentClassReflection->isSubclassOf($classReflection->getName())) {
continue;
}

// include child usages and parent usages
if ($currentClassReflection->getName() === $classReflection->getName()) {
continue;
}

return $this->resolveClassReflectionsFromClassTypes($classesByConstantName[$desiredConstantName]);
}

return [];
}

public function hasClassChildren(Class_ $desiredClass): bool
{
$desiredClassName = $desiredClass->getAttribute(AttributeKey::CLASS_NAME);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use Rector\NodeCollector\NodeCollector\NodeRepository;
use Rector\NodeCollector\NodeCollector\ParsedClassConstFetchNodeCollector;
use Rector\NodeCollector\NodeCollector\ParsedNodeCollector;
use Rector\NodeCollector\NodeCollector\ParsedPropertyFetchNodeCollector;

Expand All @@ -28,21 +27,14 @@ final class NodeCollectorNodeVisitor extends NodeVisitorAbstract
*/
private $parsedPropertyFetchNodeCollector;

/**
* @var ParsedClassConstFetchNodeCollector
*/
private $parsedClassConstFetchNodeCollector;

public function __construct(
ParsedClassConstFetchNodeCollector $parsedClassConstFetchNodeCollector,
NodeRepository $nodeRepository,
ParsedNodeCollector $parsedNodeCollector,
ParsedPropertyFetchNodeCollector $parsedPropertyFetchNodeCollector
) {
$this->nodeRepository = $nodeRepository;
$this->parsedNodeCollector = $parsedNodeCollector;
$this->parsedPropertyFetchNodeCollector = $parsedPropertyFetchNodeCollector;
$this->parsedClassConstFetchNodeCollector = $parsedClassConstFetchNodeCollector;
}

public function enterNode(Node $node)
Expand All @@ -53,7 +45,6 @@ public function enterNode(Node $node)

$this->nodeRepository->collect($node);
$this->parsedPropertyFetchNodeCollector->collect($node);
$this->parsedClassConstFetchNodeCollector->collect($node);

return null;
}
Expand Down
Loading

0 comments on commit ef8cf2b

Please sign in to comment.