Skip to content

Commit

Permalink
Updated Rector to commit 5f21af7a492f8be43972c1d89fa150ae9e37475c
Browse files Browse the repository at this point in the history
rectorphp/rector-src@5f21af7 Remove unused AssignVariableNameResolverInterface instances (#6631)
  • Loading branch information
TomasVotruba committed Dec 27, 2024
1 parent df5de7b commit 59d44f7
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 223 deletions.

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions rules/Naming/Contract/AssignVariableNameResolverInterface.php

This file was deleted.

105 changes: 0 additions & 105 deletions rules/Naming/Naming/VariableNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,12 @@
declare (strict_types=1);
namespace Rector\Naming\Naming;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use Rector\Naming\AssignVariableNameResolver\NewAssignVariableNameResolver;
use Rector\Naming\AssignVariableNameResolver\PropertyFetchAssignVariableNameResolver;
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
/**
* @api used in downgrade
*/
final class VariableNaming
{
/**
* @readonly
*/
private NodeNameResolver $nodeNameResolver;
/**
* @readonly
*/
private NodeTypeResolver $nodeTypeResolver;
/**
* @var AssignVariableNameResolverInterface[]
*/
private array $assignVariableNameResolvers = [];
public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, PropertyFetchAssignVariableNameResolver $propertyFetchAssignVariableNameResolver, NewAssignVariableNameResolver $newAssignVariableNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->assignVariableNameResolvers = [$propertyFetchAssignVariableNameResolver, $newAssignVariableNameResolver];
}
/**
* @api used in downgrade
*/
Expand All @@ -64,75 +30,4 @@ public function createCountedValueName(string $valueName, ?Scope $scope) : strin
}
return $valueName;
}
private function resolveFromNodeAndType(Node $node, Type $type) : ?string
{
$variableName = $this->resolveBareFromNode($node);
if ($variableName === null) {
return null;
}
// adjust static to specific class
if ($variableName === 'this' && $type instanceof ThisType) {
$shortClassName = $this->nodeNameResolver->getShortName($type->getClassName());
return \lcfirst($shortClassName);
}
return $this->nodeNameResolver->getShortName($variableName);
}
private function resolveFromNode(Node $node) : ?string
{
$nodeType = $this->nodeTypeResolver->getType($node);
return $this->resolveFromNodeAndType($node, $nodeType);
}
private function resolveBareFromNode(Node $node) : ?string
{
$unwrappedNode = $this->unwrapNode($node);
if (!$unwrappedNode instanceof Node) {
return null;
}
foreach ($this->assignVariableNameResolvers as $assignVariableNameResolver) {
if ($assignVariableNameResolver->match($unwrappedNode)) {
return $assignVariableNameResolver->resolve($unwrappedNode);
}
}
if ($unwrappedNode instanceof MethodCall || $unwrappedNode instanceof NullsafeMethodCall || $unwrappedNode instanceof StaticCall) {
return $this->resolveFromMethodCall($unwrappedNode);
}
if ($unwrappedNode instanceof FuncCall) {
return $this->resolveFromNode($unwrappedNode->name);
}
$paramName = $this->nodeNameResolver->getName($unwrappedNode);
if ($paramName !== null) {
return $paramName;
}
if ($unwrappedNode instanceof String_) {
return $unwrappedNode->value;
}
return null;
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\NullsafeMethodCall|\PhpParser\Node\Expr\StaticCall $node
*/
private function resolveFromMethodCall($node) : ?string
{
if ($node->name instanceof MethodCall) {
return $this->resolveFromMethodCall($node->name);
}
$methodName = $this->nodeNameResolver->getName($node->name);
if (!\is_string($methodName)) {
return null;
}
return $methodName;
}
private function unwrapNode(Node $node) : ?Node
{
if ($node instanceof Arg) {
return $node->value;
}
if ($node instanceof Cast) {
return $node->expr;
}
if ($node instanceof Ternary) {
return $node->if;
}
return $node;
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '2.0.4';
public const PACKAGE_VERSION = '5f21af7a492f8be43972c1d89fa150ae9e37475c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-12-26 11:05:12';
public const RELEASE_DATE = '2024-12-27 20:20:25';
/**
* @var int
*/
Expand Down
3 changes: 0 additions & 3 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1544,9 +1544,6 @@
'Rector\\FileSystem\\JsonFileSystem' => $baseDir . '/src/FileSystem/JsonFileSystem.php',
'Rector\\Git\\RepositoryHelper' => $baseDir . '/src/Git/RepositoryHelper.php',
'Rector\\Instanceof_\\Rector\\Ternary\\FlipNegatedTernaryInstanceofRector' => $baseDir . '/rules/Instanceof_/Rector/Ternary/FlipNegatedTernaryInstanceofRector.php',
'Rector\\Naming\\AssignVariableNameResolver\\NewAssignVariableNameResolver' => $baseDir . '/rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php',
'Rector\\Naming\\AssignVariableNameResolver\\PropertyFetchAssignVariableNameResolver' => $baseDir . '/rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php',
'Rector\\Naming\\Contract\\AssignVariableNameResolverInterface' => $baseDir . '/rules/Naming/Contract/AssignVariableNameResolverInterface.php',
'Rector\\Naming\\ExpectedNameResolver\\InflectorSingularResolver' => $baseDir . '/rules/Naming/ExpectedNameResolver/InflectorSingularResolver.php',
'Rector\\Naming\\ExpectedNameResolver\\MatchParamTypeExpectedNameResolver' => $baseDir . '/rules/Naming/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php',
'Rector\\Naming\\ExpectedNameResolver\\MatchPropertyTypeExpectedNameResolver' => $baseDir . '/rules/Naming/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php',
Expand Down
3 changes: 0 additions & 3 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1763,9 +1763,6 @@ class ComposerStaticInite1459f150f08d0eee2804dfc37f818db
'Rector\\FileSystem\\JsonFileSystem' => __DIR__ . '/../..' . '/src/FileSystem/JsonFileSystem.php',
'Rector\\Git\\RepositoryHelper' => __DIR__ . '/../..' . '/src/Git/RepositoryHelper.php',
'Rector\\Instanceof_\\Rector\\Ternary\\FlipNegatedTernaryInstanceofRector' => __DIR__ . '/../..' . '/rules/Instanceof_/Rector/Ternary/FlipNegatedTernaryInstanceofRector.php',
'Rector\\Naming\\AssignVariableNameResolver\\NewAssignVariableNameResolver' => __DIR__ . '/../..' . '/rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php',
'Rector\\Naming\\AssignVariableNameResolver\\PropertyFetchAssignVariableNameResolver' => __DIR__ . '/../..' . '/rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php',
'Rector\\Naming\\Contract\\AssignVariableNameResolverInterface' => __DIR__ . '/../..' . '/rules/Naming/Contract/AssignVariableNameResolverInterface.php',
'Rector\\Naming\\ExpectedNameResolver\\InflectorSingularResolver' => __DIR__ . '/../..' . '/rules/Naming/ExpectedNameResolver/InflectorSingularResolver.php',
'Rector\\Naming\\ExpectedNameResolver\\MatchParamTypeExpectedNameResolver' => __DIR__ . '/../..' . '/rules/Naming/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php',
'Rector\\Naming\\ExpectedNameResolver\\MatchPropertyTypeExpectedNameResolver' => __DIR__ . '/../..' . '/rules/Naming/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php',
Expand Down
16 changes: 8 additions & 8 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2119,12 +2119,12 @@
"time": "2024-09-25T14:20:29+00:00",
"type": "library",
"extra": {
"thanks": {
"url": "https:\/\/github.com\/symfony\/contracts",
"name": "symfony\/contracts"
},
"branch-alias": {
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony\/contracts",
"url": "https:\/\/github.com\/symfony\/contracts"
}
},
"installation-source": "dist",
Expand Down Expand Up @@ -2477,12 +2477,12 @@
"time": "2024-09-25T14:20:29+00:00",
"type": "library",
"extra": {
"thanks": {
"url": "https:\/\/github.com\/symfony\/contracts",
"name": "symfony\/contracts"
},
"branch-alias": {
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony\/contracts",
"url": "https:\/\/github.com\/symfony\/contracts"
}
},
"installation-source": "dist",
Expand Down

0 comments on commit 59d44f7

Please sign in to comment.