Skip to content

Commit

Permalink
[CodeQuality] Skip Closure call on CompleteDynamicPropertiesRector (#668
Browse files Browse the repository at this point in the history
)

Co-authored-by: Zoran Antolovic <zoran.antolovic.os@gmail.com>
  • Loading branch information
samsonasik and zoka123 committed Aug 13, 2021
1 parent ceef3b3 commit b53d44d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector\Fixture;

use stdClass;

class SkipClosureCall
{
public function getPrivateProperty()
{
$randomGenerator = new stdClass();

(function () {
return $this->uuidV4Generator;
})->call($randomGenerator);
}
}
6 changes: 6 additions & 0 deletions rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeTraverser;
Expand Down Expand Up @@ -80,6 +81,11 @@ public function resolveFetchedPropertiesToTypesFromClass(Class_ $class): array
return null;
}

$parentFunctionLike = $this->betterNodeFinder->findParentType($node, FunctionLike::class);
if (! $parentFunctionLike instanceof ClassMethod) {
return null;
}

$propertyFetchType = $this->resolvePropertyFetchType($node);
$fetchedLocalPropertyNameToTypes[$propertyName][] = $propertyFetchType;

Expand Down

0 comments on commit b53d44d

Please sign in to comment.