mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
cleanup
This commit is contained in:
parent
6ca687a213
commit
e61f80bd21
@ -35,9 +35,9 @@
|
|||||||
"doctrine/inflector": "^2.0",
|
"doctrine/inflector": "^2.0",
|
||||||
"jean85/pretty-package-versions": "^1.5.1|^2.0.1",
|
"jean85/pretty-package-versions": "^1.5.1|^2.0.1",
|
||||||
"nette/caching": "^3.1",
|
"nette/caching": "^3.1",
|
||||||
|
"nette/robot-loader": "^3.4",
|
||||||
"nette/utils": "^3.2",
|
"nette/utils": "^3.2",
|
||||||
"nikic/php-parser": "^4.10.4",
|
"nikic/php-parser": "^4.10.4",
|
||||||
"nette/robot-loader": "^3.4",
|
|
||||||
"phpstan/phpdoc-parser": "^0.4.12",
|
"phpstan/phpdoc-parser": "^0.4.12",
|
||||||
"phpstan/phpstan": "^0.12.81",
|
"phpstan/phpstan": "^0.12.81",
|
||||||
"phpstan/phpstan-phpunit": "^0.12.18",
|
"phpstan/phpstan-phpunit": "^0.12.18",
|
||||||
|
@ -182,7 +182,7 @@ final class LocalPropertyAnalyzer
|
|||||||
|
|
||||||
private function shouldSkipForLaravelCollection(PropertyFetch $propertyFetch): bool
|
private function shouldSkipForLaravelCollection(PropertyFetch $propertyFetch): bool
|
||||||
{
|
{
|
||||||
$staticCallOrClassMethod = $this->betterNodeFinder->findFirstAncestorInstancesOf(
|
$staticCallOrClassMethod = $this->betterNodeFinder-> findParentTypes(
|
||||||
$propertyFetch,
|
$propertyFetch,
|
||||||
[ClassMethod::class, StaticCall::class]
|
[ClassMethod::class, StaticCall::class]
|
||||||
);
|
);
|
||||||
|
@ -21,7 +21,6 @@ use Symplify\PackageBuilder\Php\TypeChecker;
|
|||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T of Node
|
|
||||||
* @see \Rector\Core\Tests\PhpParser\Node\BetterNodeFinder\BetterNodeFinderTest
|
* @see \Rector\Core\Tests\PhpParser\Node\BetterNodeFinder\BetterNodeFinderTest
|
||||||
*/
|
*/
|
||||||
final class BetterNodeFinder
|
final class BetterNodeFinder
|
||||||
@ -59,6 +58,7 @@ final class BetterNodeFinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @template T of Node
|
||||||
* @param class-string<T> $type
|
* @param class-string<T> $type
|
||||||
* @return T|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
@ -85,6 +85,7 @@ final class BetterNodeFinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @template T of Node
|
||||||
* @param array<class-string<T>> $types
|
* @param array<class-string<T>> $types
|
||||||
* @return T|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
@ -111,27 +112,7 @@ final class BetterNodeFinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<class-string<T>> $types
|
* @template T of Node
|
||||||
* @return T|null
|
|
||||||
*/
|
|
||||||
public function findFirstAncestorInstancesOf(Node $node, array $types): ?Node
|
|
||||||
{
|
|
||||||
$currentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
|
||||||
|
|
||||||
while ($currentNode instanceof Node) {
|
|
||||||
foreach ($types as $type) {
|
|
||||||
if (is_a($currentNode, $type, true)) {
|
|
||||||
return $currentNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$currentNode = $currentNode->getAttribute(AttributeKey::PARENT_NODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param class-string<T> $type
|
* @param class-string<T> $type
|
||||||
* @param Node|Node[]|Stmt[] $nodes
|
* @param Node|Node[]|Stmt[] $nodes
|
||||||
* @return T[]
|
* @return T[]
|
||||||
@ -139,11 +120,11 @@ final class BetterNodeFinder
|
|||||||
public function findInstanceOf($nodes, string $type): array
|
public function findInstanceOf($nodes, string $type): array
|
||||||
{
|
{
|
||||||
Assert::isAOf($type, Node::class);
|
Assert::isAOf($type, Node::class);
|
||||||
|
|
||||||
return $this->nodeFinder->findInstanceOf($nodes, $type);
|
return $this->nodeFinder->findInstanceOf($nodes, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @template T of Node
|
||||||
* @param class-string<T> $type
|
* @param class-string<T> $type
|
||||||
* @param Node|Node[] $nodes
|
* @param Node|Node[] $nodes
|
||||||
* @return T|null
|
* @return T|null
|
||||||
@ -151,18 +132,16 @@ final class BetterNodeFinder
|
|||||||
public function findFirstInstanceOf($nodes, string $type): ?Node
|
public function findFirstInstanceOf($nodes, string $type): ?Node
|
||||||
{
|
{
|
||||||
Assert::isAOf($type, Node::class);
|
Assert::isAOf($type, Node::class);
|
||||||
|
|
||||||
return $this->nodeFinder->findFirstInstanceOf($nodes, $type);
|
return $this->nodeFinder->findFirstInstanceOf($nodes, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<T> $type
|
* @param class-string<Node> $type
|
||||||
* @param Node|Node[] $nodes
|
* @param Node|Node[] $nodes
|
||||||
*/
|
*/
|
||||||
public function hasInstanceOfName($nodes, string $type, string $name): bool
|
public function hasInstanceOfName($nodes, string $type, string $name): bool
|
||||||
{
|
{
|
||||||
Assert::isAOf($type, Node::class);
|
Assert::isAOf($type, Node::class);
|
||||||
|
|
||||||
return (bool) $this->findInstanceOfName($nodes, $type, $name);
|
return (bool) $this->findInstanceOfName($nodes, $type, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,16 +164,15 @@ final class BetterNodeFinder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node|Node[] $nodes
|
* @param Node|Node[] $nodes
|
||||||
* @param class-string<T>[] $types
|
* @param array<class-string<Node>> $types
|
||||||
*/
|
*/
|
||||||
public function hasInstancesOf($nodes, array $types): bool
|
public function hasInstancesOf($nodes, array $types): bool
|
||||||
{
|
{
|
||||||
Assert::allIsAOf($types, Node::class);
|
Assert::allIsAOf($types, Node::class);
|
||||||
|
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
$nodeFinderFindFirstInstanceOf = $this->nodeFinder->findFirstInstanceOf($nodes, $type);
|
$foundNode = $this->nodeFinder->findFirstInstanceOf($nodes, $type);
|
||||||
|
if (! $foundNode instanceof Node) {
|
||||||
if (! $nodeFinderFindFirstInstanceOf instanceof Node) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +183,7 @@ final class BetterNodeFinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @template T of Node
|
||||||
* @param class-string<T> $type
|
* @param class-string<T> $type
|
||||||
* @param Node|Node[] $nodes
|
* @param Node|Node[] $nodes
|
||||||
* @return T|null
|
* @return T|null
|
||||||
@ -336,7 +315,8 @@ final class BetterNodeFinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<T>[] $types
|
* @template T of Node
|
||||||
|
* @param array<class-string<T>> $types
|
||||||
* @return T|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
public function findFirstPreviousOfTypes(Node $mainNode, array $types): ?Node
|
public function findFirstPreviousOfTypes(Node $mainNode, array $types): ?Node
|
||||||
@ -368,6 +348,7 @@ final class BetterNodeFinder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node|Node[] $nodes
|
* @param Node|Node[] $nodes
|
||||||
|
* @template T of Node
|
||||||
* @param class-string<T> $type
|
* @param class-string<T> $type
|
||||||
* @return T|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user