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
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,6 @@ parameters:
message: '#Offset 0 does not exist on array<PhpParser\\Node\\Stmt>\|null#'
path: rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php

# resolve before Rector 1.0
- '#Call to deprecated method findParentType#'
- '#Call to deprecated method findParentByTypes#'

- '#Cognitive complexity for "Rector\\Transform\\Rector\\StaticCall\\StaticCallToMethodCallRector\:\:refactorWithScope\(\)" is 14, keep it under 11#'
- '#Cognitive complexity for "Rector\\TypeDeclaration\\Rector\\ClassMethod\\ParamTypeByMethodCallTypeRector\:\:refactorWithScope\(\)" is 13, keep it under 11#'

Expand Down
20 changes: 7 additions & 13 deletions rules/Php72/NodeFactory/AnonymousFunctionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php72\NodeManipulator\ClosureNestedUsesDecorator;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand All @@ -65,7 +64,6 @@ public function __construct(
private readonly StaticTypeMapper $staticTypeMapper,
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
private readonly SimplePhpParser $simplePhpParser,
private readonly ClosureNestedUsesDecorator $closureNestedUsesDecorator,
private readonly AstResolver $astResolver,
private readonly PrivatesAccessor $privatesAccessor,
private readonly InlineCodeParser $inlineCodeParser
Expand All @@ -85,27 +83,23 @@ public function create(
): Closure {
$useVariables = $this->createUseVariablesFromParams($stmts, $params);

$anonymousFunctionNode = new Closure();
$anonymousFunctionNode->params = $params;
$anonymousFunctionClosure = new Closure();
$anonymousFunctionClosure->params = $params;

if ($static) {
$anonymousFunctionNode->static = $static;
$anonymousFunctionClosure->static = $static;
}

foreach ($useVariables as $useVariable) {
$anonymousFunctionNode = $this->closureNestedUsesDecorator->applyNestedUses(
$anonymousFunctionNode,
$useVariable
);
$anonymousFunctionNode->uses[] = new ClosureUse($useVariable);
$anonymousFunctionClosure->uses[] = new ClosureUse($useVariable);
}

if ($returnTypeNode instanceof Node) {
$anonymousFunctionNode->returnType = $returnTypeNode;
$anonymousFunctionClosure->returnType = $returnTypeNode;
}

$anonymousFunctionNode->stmts = $stmts;
return $anonymousFunctionNode;
$anonymousFunctionClosure->stmts = $stmts;
return $anonymousFunctionClosure;
}

public function createFromPhpMethodReflection(PhpMethodReflection $phpMethodReflection, Expr $expr): ?Closure
Expand Down
96 changes: 0 additions & 96 deletions rules/Php72/NodeManipulator/ClosureNestedUsesDecorator.php

This file was deleted.

23 changes: 0 additions & 23 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ public function __construct(
) {
}

/**
* @deprecated Make use of child nodes instead
* @param class-string<T> $type
* @template T of Node
* @return T|null
*/
public function findParentType(Node $node, string $type): ?Node
{
Assert::isAOf($type, Node::class);

$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);

while ($parentNode instanceof Node) {
if ($parentNode instanceof $type) {
return $parentNode;
}

$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
}

return null;
}

/**
* @template T of Node
* @param array<class-string<T>> $types
Expand Down
14 changes: 0 additions & 14 deletions tests/PhpParser/Node/BetterNodeFinder/BetterNodeFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Rector\Core\Tests\PhpParser\Node\BetterNodeFinder;

use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Parser\SimplePhpParser;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
Expand Down Expand Up @@ -37,17 +35,5 @@ public function testFindFirstAncestorInstanceOf(): void

$this->assertInstanceOf(Variable::class, $variable);
$this->assertInstanceOf(Class_::class, $class);

/** @var Variable $variable */
$classLikeNode = $this->betterNodeFinder->findParentType($variable, ClassLike::class);
$this->assertSame($classLikeNode, $class);
}

public function testFindMissingFirstAncestorInstanceOf(): void
{
/** @var Variable $variableNode */
$variableNode = $this->betterNodeFinder->findFirstInstanceOf($this->nodes, Variable::class);

$this->assertNull($this->betterNodeFinder->findParentType($variableNode, Array_::class));
}
}