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
34 changes: 13 additions & 21 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use ArrayAccess;
use Closure;
use IteratorAggregate;
use Override;
use PhpParser\Comment\Doc;
use PhpParser\Modifiers;
use PhpParser\Node;
Expand Down Expand Up @@ -49,7 +48,6 @@
use PhpParser\Node\Stmt\While_;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use PHPStan\Analyser\ExprHandler\AssignHandler;
use PHPStan\Analyser\ExprHandler\Helper\ImplicitToStringCallHelper;
use PHPStan\Analyser\ExprHandler\Helper\MethodThrowPointHelper;
Expand All @@ -73,7 +71,6 @@
use PHPStan\Node\ClassPropertyNode;
use PHPStan\Node\ClassStatementsGatherer;
use PHPStan\Node\ClosureReturnStatementsNode;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\Node\DoWhileLoopConditionNode;
use PHPStan\Node\ExecutionEndNode;
use PHPStan\Node\Expr\ExistingArrayDimFetch;
Expand Down Expand Up @@ -259,7 +256,6 @@ public function __construct(
#[AutowiredExtensions(of: StaticMethodParameterClosureTypeExtension::class)]
private readonly ExtensionsCollection $staticMethodParameterClosureTypeExtensions,
private readonly ScopeFactory $scopeFactory,
private readonly DeepNodeCloner $deepNodeCloner,
#[AutowiredParameter]
private readonly bool $polluteScopeWithLoopInitialAssignments,
#[AutowiredParameter]
Expand Down Expand Up @@ -2406,25 +2402,21 @@ public function processStmtNode(
));
}

$clonedVar = $this->deepNodeCloner->cloneNode($var->var);
$traverser = new NodeTraverser();
$traverser->addVisitor(new class () extends NodeVisitorAbstract {

#[Override]
public function leaveNode(Node $node): ?ExistingArrayDimFetch
{
if (!$node instanceof ArrayDimFetch || $node->dim === null) {
return null;
}

return new ExistingArrayDimFetch($node->var, $node->dim);
// wrap the already-processed chain in ExistingArrayDimFetch nodes
// referencing the original sub-expressions - the unset statement's
// own walk already processed them, and the assign target
// preparation prices the chain without re-walking it
$buildExistingChain = static function (Expr $node) use (&$buildExistingChain): Expr {
if (!$node instanceof ArrayDimFetch || $node->dim === null) {
return $node;
}

});

/** @var Expr $clonedVar */
[$clonedVar] = $traverser->traverse([$clonedVar]);
$scope = $this->processVirtualAssign($scope, $storage, $stmt, $clonedVar, new UnsetOffsetExpr($var->var, $var->dim), $nodeCallback)->getScope();
return new ExistingArrayDimFetch(
$buildExistingChain($node->var),
$node->dim,
);
};
$scope = $this->processVirtualAssign($scope, $storage, $stmt, $buildExistingChain($var->var), new UnsetOffsetExpr($var->var, $var->dim), $nodeCallback)->getScope();
} elseif ($var instanceof PropertyFetch) {
$scope = $scope->invalidateExpression($var);
$impurePoints[] = new ImpurePoint(
Expand Down
29 changes: 0 additions & 29 deletions src/Node/DeepNodeCloner.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Testing/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use PHPStan\File\FileHelper;
use PHPStan\File\FileReader;
use PHPStan\Fixable\Patcher;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
use PHPStan\Reflection\ClassReflectionFactory;
use PHPStan\Reflection\InitializerExprTypeResolver;
Expand Down Expand Up @@ -122,7 +121,6 @@ protected function createNodeScopeResolver(): NodeScopeResolver
self::getContainer()->getExtensionsCollection(MethodParameterClosureTypeExtension::class),
self::getContainer()->getExtensionsCollection(StaticMethodParameterClosureTypeExtension::class),
self::createScopeFactory($reflectionProvider, $typeSpecifier),
self::getContainer()->getByType(DeepNodeCloner::class),
$this->shouldPolluteScopeWithLoopInitialAssignments(),
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
self::getContainer()->getParameter('polluteScopeWithBlock'),
Expand Down
2 changes: 0 additions & 2 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PHPStan\Analyser\ScopeContext;
use PHPStan\File\FileHelper;
use PHPStan\File\SystemAgnosticSimpleRelativePathHelper;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\Node\InClassNode;
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
use PHPStan\PhpDoc\TypeStringResolver;
Expand Down Expand Up @@ -97,7 +96,6 @@ protected static function createNodeScopeResolver(): NodeScopeResolver
$container->getExtensionsCollection(MethodParameterClosureTypeExtension::class),
$container->getExtensionsCollection(StaticMethodParameterClosureTypeExtension::class),
self::createScopeFactory($reflectionProvider, $typeSpecifier),
self::getContainer()->getByType(DeepNodeCloner::class),
$container->getParameter('polluteScopeWithLoopInitialAssignments'),
$container->getParameter('polluteScopeWithAlwaysIterableForeach'),
$container->getParameter('polluteScopeWithBlock'),
Expand Down
2 changes: 0 additions & 2 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Dependency\ExportedNodeResolver;
use PHPStan\Dependency\PackageDependencyResolver;
use PHPStan\DependencyInjection\DirectExtensionsCollection;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\Node\Printer\ExprPrinter;
use PHPStan\Node\Printer\Printer;
use PHPStan\Parser\RichParser;
Expand Down Expand Up @@ -838,7 +837,6 @@ private function createAnalyser(): Analyser
$container->getExtensionsCollection(MethodParameterClosureTypeExtension::class),
$container->getExtensionsCollection(StaticMethodParameterClosureTypeExtension::class),
self::createScopeFactory($reflectionProvider, $typeSpecifier),
$container->getByType(DeepNodeCloner::class),
false,
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\DirectExtensionsCollection;
use PHPStan\File\FileHelper;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
use PHPStan\Reflection\ClassReflectionFactory;
use PHPStan\Reflection\InitializerExprTypeResolver;
Expand Down Expand Up @@ -142,7 +141,6 @@ protected function createNodeScopeResolver(): NodeScopeResolver
self::getContainer()->getExtensionsCollection(MethodParameterClosureTypeExtension::class),
self::getContainer()->getExtensionsCollection(StaticMethodParameterClosureTypeExtension::class),
self::createScopeFactory($reflectionProvider, $typeSpecifier),
self::getContainer()->getByType(DeepNodeCloner::class),
$this->shouldPolluteScopeWithLoopInitialAssignments(),
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
self::getContainer()->getParameter('polluteScopeWithBlock'),
Expand Down
2 changes: 0 additions & 2 deletions tests/PHPStan/Analyser/Fiber/FiberNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PHPStan\Analyser\ExprHandler\Helper\ImplicitToStringCallHelper;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\File\FileHelper;
use PHPStan\Node\DeepNodeCloner;
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
use PHPStan\Reflection\ClassReflectionFactory;
use PHPStan\Reflection\InitializerExprTypeResolver;
Expand Down Expand Up @@ -75,7 +74,6 @@ protected static function createNodeScopeResolver(): NodeScopeResolver
$container->getExtensionsCollection(MethodParameterClosureTypeExtension::class),
$container->getExtensionsCollection(StaticMethodParameterClosureTypeExtension::class),
self::createScopeFactory($reflectionProvider, $typeSpecifier),
$container->getByType(DeepNodeCloner::class),
$container->getParameter('polluteScopeWithLoopInitialAssignments'),
$container->getParameter('polluteScopeWithAlwaysIterableForeach'),
$container->getParameter('polluteScopeWithBlock'),
Expand Down
Loading