Updated Rector to commit f632fa095707095d9d43f0faf8a2a68d4619ed3f

f632fa0957 [DowngradePhp80] Add DowngradeStringReturnTypeOnToStringRector (#1750)
This commit is contained in:
Tomas Votruba 2022-01-31 17:52:49 +00:00
parent 9aee7e82f1
commit 3ebcd0c7ba
14 changed files with 169 additions and 41 deletions

View File

@ -13,6 +13,7 @@ use Rector\DowngradePhp80\Rector\ClassConstFetch\DowngradeClassOnObjectToGetClas
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeAbstractPrivateMethodInTraitRector;
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeRecursiveDirectoryIteratorHasChildrenRector;
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeStaticTypeDeclarationRector;
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeStringReturnTypeOnToStringRector;
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector;
@ -75,4 +76,5 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionClassGetConstantsFilterRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector::class);
$services->set(\Rector\DowngradePhp80\Rector\ClassMethod\DowngradeStringReturnTypeOnToStringRector::class);
};

View File

@ -4,7 +4,10 @@ declare (strict_types=1);
namespace Rector\FamilyTree\NodeAnalyzer;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\Php\PhpMethodReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
final class ClassChildAnalyzer
{
@ -52,6 +55,21 @@ final class ClassChildAnalyzer
}
return \false;
}
public function resolveParentClassMethodReturnType(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName) : \PHPStan\Type\Type
{
$parentClassMethods = $this->resolveParentClassMethods($classReflection, $methodName);
if ($parentClassMethods === []) {
return new \PHPStan\Type\MixedType();
}
foreach ($parentClassMethods as $parentClassMethod) {
$parametersAcceptor = \PHPStan\Reflection\ParametersAcceptorSelector::selectSingle($parentClassMethod->getVariants());
$nativeReturnType = $parametersAcceptor->getNativeReturnType();
if (!$nativeReturnType instanceof \PHPStan\Type\MixedType) {
return $nativeReturnType;
}
}
return new \PHPStan\Type\MixedType();
}
/**
* @return PhpMethodReflection[]
*/

View File

@ -0,0 +1,106 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp80\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use Rector\Core\Rector\AbstractRector;
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\DowngradePhp80\Rector\ClassMethod\DowngradeStringReturnTypeOnToStringRector\DowngradeStringReturnTypeOnToStringRectorTest
*/
final class DowngradeStringReturnTypeOnToStringRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer
*/
private $classChildAnalyzer;
public function __construct(\Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer $classChildAnalyzer)
{
$this->classChildAnalyzer = $classChildAnalyzer;
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\ClassMethod::class];
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Add "string" return on current __toString() method when parent method has string return on __toString() method', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
abstract class ParentClass
{
public function __toString(): string
{
return 'value';
}
}
class ChildClass extends ParentClass
{
public function __toString()
{
return 'value';
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
abstract class ParentClass
{
public function __toString(): string
{
return 'value';
}
}
class ChildClass extends ParentClass
{
public function __toString(): string
{
return 'value';
}
}
CODE_SAMPLE
)]);
}
/**
* @param ClassMethod $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkip($node)) {
return null;
}
$node->returnType = new \PhpParser\Node\Name('string');
return $node;
}
private function shouldSkip(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
{
if (!$this->nodeNameResolver->isName($classMethod, '__toString')) {
return \true;
}
if ($classMethod->returnType instanceof \PhpParser\Node) {
return \true;
}
$scope = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
if (!$scope instanceof \PHPStan\Analyser\Scope) {
return \true;
}
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
return \true;
}
$type = $this->classChildAnalyzer->resolveParentClassMethodReturnType($classReflection, '__toString');
return $type instanceof \PHPStan\Type\MixedType;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'b7b4dc07c8198719f8dda083f867446c1e89ac6a';
public const PACKAGE_VERSION = 'f632fa095707095d9d43f0faf8a2a68d4619ed3f';
/**
* @var string
*/
public const RELEASE_DATE = '2022-01-31 15:12:09';
public const RELEASE_DATE = '2022-02-01 00:44:50';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220131\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75::getLoader();
return ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db::getLoader();

View File

@ -2035,6 +2035,7 @@ return array(
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeAbstractPrivateMethodInTraitRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeRecursiveDirectoryIteratorHasChildrenRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeRecursiveDirectoryIteratorHasChildrenRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeStaticTypeDeclarationRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeStaticTypeDeclarationRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeStringReturnTypeOnToStringRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeStringReturnTypeOnToStringRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeTrailingCommasInParamUseRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradeAttributeToAnnotationRector' => $baseDir . '/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradePropertyPromotionRector' => $baseDir . '/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75
class ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite5728a483456fa7726fa2b4081d92d75::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInite5728a483456fa7726fa2b4081d92d75::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiree5728a483456fa7726fa2b4081d92d75($fileIdentifier, $file);
composerRequire288e24fa72ba4ed84e7fa4161dee99db($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75
* @param string $file
* @return void
*/
function composerRequiree5728a483456fa7726fa2b4081d92d75($fileIdentifier, $file)
function composerRequire288e24fa72ba4ed84e7fa4161dee99db($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 ComposerStaticInite5728a483456fa7726fa2b4081d92d75
class ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2425,6 +2425,7 @@ class ComposerStaticInite5728a483456fa7726fa2b4081d92d75
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeAbstractPrivateMethodInTraitRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeRecursiveDirectoryIteratorHasChildrenRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeRecursiveDirectoryIteratorHasChildrenRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeStaticTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeStaticTypeDeclarationRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeStringReturnTypeOnToStringRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeStringReturnTypeOnToStringRector.php',
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeTrailingCommasInParamUseRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradeAttributeToAnnotationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradePropertyPromotionRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php',
@ -3868,9 +3869,9 @@ class ComposerStaticInite5728a483456fa7726fa2b4081d92d75
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite5728a483456fa7726fa2b4081d92d75::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite5728a483456fa7726fa2b4081d92d75::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite5728a483456fa7726fa2b4081d92d75::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit288e24fa72ba4ed84e7fa4161dee99db::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1012,17 +1012,17 @@
},
{
"name": "phpstan\/phpstan",
"version": "1.4.3",
"version_normalized": "1.4.3.0",
"version": "1.4.4",
"version_normalized": "1.4.4.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
"reference": "89d10839dbfc95eeb7da656578b4a899ad2b59b1"
"reference": "f7409da1e26c6dee172cce744034b869a2f27a9e"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/89d10839dbfc95eeb7da656578b4a899ad2b59b1",
"reference": "89d10839dbfc95eeb7da656578b4a899ad2b59b1",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/f7409da1e26c6dee172cce744034b869a2f27a9e",
"reference": "f7409da1e26c6dee172cce744034b869a2f27a9e",
"shasum": ""
},
"require": {
@ -1031,7 +1031,7 @@
"conflict": {
"phpstan\/phpstan-shim": "*"
},
"time": "2022-01-28T16:27:17+00:00",
"time": "2022-01-31T16:50:49+00:00",
"bin": [
"phpstan",
"phpstan.phar"
@ -1055,7 +1055,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpstan\/issues",
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.4.3"
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.4.4"
},
"funding": [
{

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmH0GWQACgkQzxoQjQ56
5yD7fg/9ERSmuwYYxHdJjuHI93Iawb8rF9brBzUy2D0mhmAnTnJMxs4d5DwZCdTr
OLWF0tUQ+Dvci0IpqkHyWP2kJu3RC1QrSjAjB7ubD/xfBhGzk+6C2jpenzZcJrTy
DEbZj72ACoV3oouluj+iVqHhSNbRpIQyL2AoZzf3Tpe943GNkqfmxlJNRQH0fm/N
SP7yL/haSEyb+Z7N7vevl4s9PdDy+xpiRVbJfLh3NcITyaIhfqIiDrGOEezO41Fw
/PZd/XAr8C3hZv06ygZqhraptUmPqwjaVylyAL9Xm6YMzDxZw9c4l0xrTTVTDCU0
A3xcCLwuNeIxpjl/yp9YtZjqOmt9vYppH5y43jMD0qQG2RdLstswaPKtSo96dQXs
azA6rXMkH5R1xAFgbF/2/0F6+RHaPnRlfqCq8RIFCAWwgmAmwCmzlLWxDqQUFIFW
nH2AewWT86XRJz+t39F/bMePp1xttjxdSjNXmPyf+xGdsh5A5Hvc/84C7OeSiLrS
OED9OjLc49ZNXizfCTaOQa448nvyi7UJnSTkBqr2rHxrbB96h+mXH7df4qbh2b5M
FwDNiQcEGlqGNe1tGNMLsfaK2E9gc+R/kRl2LqNFQPS7EKhLg4tKWtn5QtEGYsbI
EpVArju1amm3qbVeLVlGxynvZopDW+xH7lmu0FVUTEI7TUj3jPc=
=S3UP
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmH4E2kACgkQzxoQjQ56
5yDoBw/+LOU99QnMCJHXvMbg+oBzc8FkBH/Q+ZBYg+XWbQyBaSohluEbGQtuLdoX
lMIMverJHQ79JCg8PSKpgD0gy94HvgYsK9dbKF6JEJ1G6hrtXTD9FBrIHlW/8yKD
N/IAXx8UYdFEfT5rc+fuSI6JVRDmGssM66UXBKnsNGmc2Iur3AJvSLhPCygRGkRw
GjRpAVqRz4MYT2BC+yF5j5QD6X6BvXLTUaGNdCkoMuMrRYgXUS18Nmqw5HkyFka2
E0cXThfa+uDlbuY/wd0beLB5RT7QyX7AQwNJTMDXcbdDARMtBtdSG2yTIRW3VsGO
Q0gtw5UhIvGTVyEZuBdTAI3xhmFR0ehZBi7lnn7qN6EbAvaHLpGW9WhIQuEvw3SY
VZmnVrNl/ioyMUH6OWeKjVwmBngVWdlrjibVHP0f+PqD2nU1pNgjkRm1aEBbPQ+g
dNB3uxKDW0qJECXpSm9zC9TRzvw695Oo5qxD+Vx2wOlaKzUBQfBvQRhza+tpDVwq
Y0GTZy/jYNl8PM7sRXKOrQqFV7OzuJNrZUzTsZ31gCAC3QqcNiF+OeuZB58KB/Va
Txz1r6EOOdm+pkKEfGouOzONpd7P3jv4fA6drpoIvfhUQ9fNcnLSJnf0pOuMmIgl
AGtPDu1f4IufnwUwh0/JhwHLW/BEmPfZt55XDaYII20z2/aW708=
=GoKy
-----END PGP SIGNATURE-----

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('RectorPrefix20220131\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75', false) && !interface_exists('ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75', false) && !trait_exists('ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75', false)) {
spl_autoload_call('RectorPrefix20220131\ComposerAutoloaderInite5728a483456fa7726fa2b4081d92d75');
if (!class_exists('ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db', false) && !interface_exists('ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db', false) && !trait_exists('ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db', false)) {
spl_autoload_call('RectorPrefix20220131\ComposerAutoloaderInit288e24fa72ba4ed84e7fa4161dee99db');
}
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('RectorPrefix20220131\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220131\print_node(...func_get_args());
}
}
if (!function_exists('composerRequiree5728a483456fa7726fa2b4081d92d75')) {
function composerRequiree5728a483456fa7726fa2b4081d92d75() {
return \RectorPrefix20220131\composerRequiree5728a483456fa7726fa2b4081d92d75(...func_get_args());
if (!function_exists('composerRequire288e24fa72ba4ed84e7fa4161dee99db')) {
function composerRequire288e24fa72ba4ed84e7fa4161dee99db() {
return \RectorPrefix20220131\composerRequire288e24fa72ba4ed84e7fa4161dee99db(...func_get_args());
}
}
if (!function_exists('scanPath')) {

View File

@ -195,7 +195,7 @@ final class CompletionInput extends \RectorPrefix20220131\Symfony\Component\Cons
}
return $this->currentIndex >= $nrOfTokens;
}
public function __toString()
public function __toString() : string
{
$str = '';
foreach ($this->tokens as $i => $token) {