Skip to content

Commit

Permalink
Remove GetterNodeParamTypeInferer (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 27, 2022
1 parent ca8249d commit f862bf9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 208 deletions.

This file was deleted.

This file was deleted.

9 changes: 5 additions & 4 deletions src/NodeAnalyzer/PropertyFetchAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Core\NodeAnalyzer;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
Expand Down Expand Up @@ -208,14 +209,14 @@ public function isFilledViaMethodCallInConstructStmts(ClassLike $classLike, stri
/**
* @param string[] $propertyNames
*/
public function isLocalPropertyOfNames(Node $node, array $propertyNames): bool
public function isLocalPropertyOfNames(Expr $expr, array $propertyNames): bool
{
if (! $this->isLocalPropertyFetch($node)) {
if (! $this->isLocalPropertyFetch($expr)) {
return false;
}

/** @var PropertyFetch $node */
return $this->nodeNameResolver->isNames($node->name, $propertyNames);
/** @var PropertyFetch $expr */
return $this->nodeNameResolver->isNames($expr->name, $propertyNames);
}

private function isPropertyAssignFoundInClassMethod(
Expand Down
57 changes: 0 additions & 57 deletions src/NodeManipulator/PropertyFetchAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
Expand Down Expand Up @@ -71,59 +69,4 @@ function (Node $node) use ($propertyName, $classLike, &$count): ?int {

return $count === 2;
}

/**
* @return string[]
*/
public function getPropertyNamesOfAssignOfVariable(ClassMethod $classMethod, string $paramName): array
{
$propertyNames = [];

$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod, function (Node $node) use (
$paramName,
&$propertyNames
) {
if (! $node instanceof Assign) {
return null;
}

if (! $this->isVariableAssignToThisPropertyFetch($node, $paramName)) {
return null;
}

/** @var Assign $node */
$propertyName = $this->nodeNameResolver->getName($node->expr);
if (is_string($propertyName)) {
$propertyNames[] = $propertyName;
}

return null;
});

return $propertyNames;
}

/**
* Matches:
* "$this->someValue = $<variableName>;"
*/
private function isVariableAssignToThisPropertyFetch(Assign $assign, string $variableName): bool
{
if (! $assign->expr instanceof Variable) {
return false;
}

if (! $this->nodeNameResolver->isName($assign->expr, $variableName)) {
return false;
}

if (! $assign->var instanceof PropertyFetch) {
return false;
}

$propertyFetch = $assign->var;

// must be local property
return $this->nodeNameResolver->isName($propertyFetch->var, 'this');
}
}

0 comments on commit f862bf9

Please sign in to comment.