Updated Rector to commit 76894e5c63

76894e5c63 [Naming] Add Closure and Function_ on RenameParamToMatchTypeRector (#2042)
This commit is contained in:
Tomas Votruba 2022-04-10 08:30:09 +00:00
parent 33ba60faee
commit d58370849e
14 changed files with 64 additions and 49 deletions

View File

@ -111,11 +111,11 @@ final class PHPStanNodeScopeResolver
$this->removeDeepChainMethodCallNodes($stmts);
$scope = $this->scopeFactory->createFromFile($smartFileInfo);
// skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254
$nodeCallback = function (\PhpParser\Node $node, \PHPStan\Analyser\MutatingScope $scope) use(&$nodeCallback) : void {
$nodeCallback = function (\PhpParser\Node $node, \PHPStan\Analyser\MutatingScope $mutatingScope) use(&$nodeCallback) : void {
if ($node instanceof \PhpParser\Node\Stmt\Trait_) {
$traitName = $this->resolveClassName($node);
$traitReflectionClass = $this->reflectionProvider->getClass($traitName);
$traitScope = clone $scope;
$traitScope = clone $mutatingScope;
$scopeContext = $this->privatesAccessor->getPrivatePropertyOfClass($traitScope, self::CONTEXT, \PHPStan\Analyser\ScopeContext::class);
$traitContext = clone $scopeContext;
$this->privatesAccessor->setPrivatePropertyOfClass($traitContext, 'classReflection', $traitReflectionClass, \PHPStan\Reflection\ClassReflection::class);
@ -126,16 +126,16 @@ final class PHPStanNodeScopeResolver
// the class reflection is resolved AFTER entering to class node
// so we need to get it from the first after this one
if ($node instanceof \PhpParser\Node\Stmt\Class_ || $node instanceof \PhpParser\Node\Stmt\Interface_) {
/** @var MutatingScope $scope */
$scope = $this->resolveClassOrInterfaceScope($node, $scope);
/** @var MutatingScope $mutatingScope */
$mutatingScope = $this->resolveClassOrInterfaceScope($node, $mutatingScope);
}
// special case for unreachable nodes
if ($node instanceof \PHPStan\Node\UnreachableStatementNode) {
$originalNode = $node->getOriginalStatement();
$originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::IS_UNREACHABLE, \true);
$originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $scope);
$originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $mutatingScope);
} else {
$node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $scope);
$node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $mutatingScope);
}
};
$this->decoratePHPStanNodeScopeResolverWithRenamedClassSourceLocator($this->nodeScopeResolver);

View File

@ -41,12 +41,12 @@ final class DocBlockNamespaceRenamer
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$phpDocNodeTraverser = new \RectorPrefix20220410\Symplify\Astral\PhpDocParser\PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (\PHPStan\PhpDocParser\Ast\Node $subNode) use($oldToNewNamespaces) : ?DocNode {
if (!$subNode instanceof \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode) {
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (\PHPStan\PhpDocParser\Ast\Node $docNode) use($oldToNewNamespaces) : ?DocNode {
if (!$docNode instanceof \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode) {
return null;
}
$name = $subNode->name;
$trimmedName = \ltrim($subNode->name, '\\');
$name = $docNode->name;
$trimmedName = \ltrim($docNode->name, '\\');
if ($name === $trimmedName) {
return null;
}

View File

@ -130,15 +130,15 @@ final class NodesToRemoveCollector implements \Rector\PostRector\Contract\Collec
}
$paramVariable = $node->var;
if ($paramVariable instanceof \PhpParser\Node\Expr\Variable) {
return (bool) $this->betterNodeFinder->findFirst((array) $parentNode->stmts, function (\PhpParser\Node $variable) use($paramVariable) : bool {
if (!$this->nodeComparator->areNodesEqual($variable, $paramVariable)) {
return (bool) $this->betterNodeFinder->findFirst((array) $parentNode->stmts, function (\PhpParser\Node $node) use($paramVariable) : bool {
if (!$this->nodeComparator->areNodesEqual($node, $paramVariable)) {
return \false;
}
$hasArgParent = (bool) $this->betterNodeFinder->findParentType($variable, \PhpParser\Node\Arg::class);
$hasArgParent = (bool) $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Arg::class);
if (!$hasArgParent) {
return \false;
}
return !(bool) $this->betterNodeFinder->findParentType($variable, \PhpParser\Node\Expr\StaticCall::class);
return !(bool) $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Expr\StaticCall::class);
});
}
return \false;

View File

@ -132,15 +132,15 @@ CODE_SAMPLE
*/
private function completeDefaultArrayToPropertyNames(\PhpParser\Node\Stmt\Class_ $class, array $propertyNames) : void
{
$this->traverseNodesWithCallable($class, function (\PhpParser\Node $class) use($propertyNames) : ?PropertyProperty {
if (!$class instanceof \PhpParser\Node\Stmt\PropertyProperty) {
$this->traverseNodesWithCallable($class, function (\PhpParser\Node $node) use($propertyNames) : ?PropertyProperty {
if (!$node instanceof \PhpParser\Node\Stmt\PropertyProperty) {
return null;
}
if (!$this->isNames($class, $propertyNames)) {
if (!$this->isNames($node, $propertyNames)) {
return null;
}
$class->default = new \PhpParser\Node\Expr\Array_();
return $class;
$node->default = new \PhpParser\Node\Expr\Array_();
return $node;
});
}
/**

View File

@ -102,7 +102,10 @@ final class BreakingVariableRenameGuard
}
return $this->isUsedInIfAndOtherBranches($variable, $currentName);
}
public function shouldSkipParam(string $currentName, string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Param $param) : bool
/**
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod
*/
public function shouldSkipParam(string $currentName, string $expectedName, $classMethod, \PhpParser\Node\Param $param) : bool
{
// is the suffix? → also accepted
$expectedNameCamelCase = \ucfirst($expectedName);
@ -116,7 +119,7 @@ final class BreakingVariableRenameGuard
if ($this->conflictingNameResolver->hasNameIsInFunctionLike($expectedName, $classMethod)) {
return \true;
}
if ($this->overridenExistingNamesResolver->hasNameInClassMethodForParam($expectedName, $classMethod)) {
if ($this->overridenExistingNamesResolver->hasNameInFunctionLikeForParam($expectedName, $classMethod)) {
return \true;
}
if ($this->isVariableAlreadyDefined($param->var, $currentName)) {

View File

@ -52,8 +52,9 @@ final class ConflictingNameResolver
}
/**
* @return string[]
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod
*/
public function resolveConflictingVariableNamesForParam(\PhpParser\Node\Stmt\ClassMethod $classMethod) : array
public function resolveConflictingVariableNamesForParam($classMethod) : array
{
$expectedNames = [];
foreach ($classMethod->params as $param) {

View File

@ -46,7 +46,10 @@ final class OverridenExistingNamesResolver
$overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike);
return \in_array($variableName, $overridenVariableNames, \true);
}
public function hasNameInClassMethodForParam(string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
/**
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod
*/
public function hasNameInFunctionLikeForParam(string $expectedName, $classMethod) : bool
{
/** @var Assign[] $assigns */
$assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, \PhpParser\Node\Expr\Assign::class);

View File

@ -4,8 +4,10 @@ declare (strict_types=1);
namespace Rector\Naming\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver;
@ -85,10 +87,10 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\ClassMethod::class];
return [\PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Expr\Closure::class];
}
/**
* @param ClassMethod $node
* @param ClassMethod|Function_|Closure $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
@ -117,13 +119,19 @@ CODE_SAMPLE
}
return $node;
}
private function shouldSkipParam(\PhpParser\Node\Param $param, string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
/**
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod
*/
private function shouldSkipParam(\PhpParser\Node\Param $param, string $expectedName, $classMethod) : bool
{
/** @var string $paramName */
$paramName = $this->getName($param);
if ($this->breakingVariableRenameGuard->shouldSkipParam($paramName, $expectedName, $classMethod, $param)) {
return \true;
}
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
return \false;
}
// promoted property
if (!$this->isName($classMethod, \Rector\Core\ValueObject\MethodName::CONSTRUCT)) {
return \false;

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '9b46906e39ded6bbf0a48d016f7b95ae1431ec29';
public const PACKAGE_VERSION = '76894e5c63cc76303b71458121c12a5666204bff';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-10 13:01:19';
public const RELEASE_DATE = '2022-04-10 10:22:55';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220410\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -34,15 +34,15 @@ final class VariableAnalyzer
if ($this->isParentStaticOrGlobal($variable)) {
return \true;
}
return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $n) use($variable) : bool {
if (!\in_array(\get_class($n), [\PhpParser\Node\Stmt\Static_::class, \PhpParser\Node\Stmt\Global_::class], \true)) {
return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $node) use($variable) : bool {
if (!\in_array(\get_class($node), [\PhpParser\Node\Stmt\Static_::class, \PhpParser\Node\Stmt\Global_::class], \true)) {
return \false;
}
/**
* @var Static_|Global_ $n
* @var Static_|Global_ $node
* @var StaticVar[]|Variable[] $vars
*/
$vars = $n->vars;
$vars = $node->vars;
foreach ($vars as $var) {
$staticVarVariable = $var instanceof \PhpParser\Node\Stmt\StaticVar ? $var->var : $var;
if ($this->nodeComparator->areNodesEqual($staticVarVariable, $variable)) {

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59::getLoader();
return ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59
class ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit114027d2a257abb219ed67ae013d23a3::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file);
composerRequire114027d2a257abb219ed67ae013d23a3($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59
* @param string $file
* @return void
*/
function composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file)
function composerRequire114027d2a257abb219ed67ae013d23a3($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59
class ComposerStaticInit114027d2a257abb219ed67ae013d23a3
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3858,9 +3858,9 @@ class ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220410\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !interface_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !trait_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false)) {
spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59');
if (!class_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false) && !interface_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false) && !trait_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false)) {
spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220410\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220410\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire77d63ece181c04c49904b82bbc0f8c59')) {
function composerRequire77d63ece181c04c49904b82bbc0f8c59() {
return \RectorPrefix20220410\composerRequire77d63ece181c04c49904b82bbc0f8c59(...func_get_args());
if (!function_exists('composerRequire114027d2a257abb219ed67ae013d23a3')) {
function composerRequire114027d2a257abb219ed67ae013d23a3() {
return \RectorPrefix20220410\composerRequire114027d2a257abb219ed67ae013d23a3(...func_get_args());
}
}
if (!function_exists('scanPath')) {