Updated Rector to commit cab8299093

cab8299093 [DX] Remove SingleToManyMethodRector, rather one time job useful for PHPStorm (#1831)
This commit is contained in:
Tomas Votruba 2022-02-18 00:56:23 +00:00
parent ede8f558b7
commit 9b0ea31152
9 changed files with 21 additions and 240 deletions

View File

@ -1,4 +1,4 @@
# 519 Rules Overview
# 518 Rules Overview
<br>
@ -94,7 +94,7 @@
- [Strict](#strict) (5)
- [Transform](#transform) (37)
- [Transform](#transform) (36)
- [TypeDeclaration](#typedeclaration) (22)
@ -11373,46 +11373,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br>
### SingleToManyMethodRector
Change method that returns single value to multiple values
:wrench: **configure it!**
- class: [`Rector\Transform\Rector\ClassMethod\SingleToManyMethodRector`](../rules/Transform/Rector/ClassMethod/SingleToManyMethodRector.php)
```php
use Rector\Transform\Rector\ClassMethod\SingleToManyMethodRector;
use Rector\Transform\ValueObject\SingleToManyMethod;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(SingleToManyMethodRector::class)
->configure([new SingleToManyMethod('SomeClass', 'getNode', 'getNodes')]);
};
```
```diff
class SomeClass
{
- public function getNode(): string
+ /**
+ * @return string[]
+ */
+ public function getNodes(): array
{
- return 'Echo_';
+ return ['Echo_'];
}
}
```
<br>
### StaticCallToFuncCallRector
Turns static call to function call.

View File

@ -1,131 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Transform\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Transform\ValueObject\SingleToManyMethod;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix20220218\Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\Transform\Rector\ClassMethod\SingleToManyMethodRector\SingleToManyMethodRectorTest
*/
final class SingleToManyMethodRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
{
/**
* @api
* @deprecated
* @var string
*/
public const SINGLES_TO_MANY_METHODS = 'singles_to_many_methods';
/**
* @var SingleToManyMethod[]
*/
private $singleToManyMethods = [];
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
*/
private $phpDocTypeChanger;
public function __construct(\Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger)
{
$this->phpDocTypeChanger = $phpDocTypeChanger;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change method that returns single value to multiple values', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function getNode(): string
{
return 'Echo_';
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
/**
* @return string[]
*/
public function getNodes(): array
{
return ['Echo_'];
}
}
CODE_SAMPLE
, [new \Rector\Transform\ValueObject\SingleToManyMethod('SomeClass', 'getNode', 'getNodes')])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$classLike = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\ClassLike::class);
if (!$classLike instanceof \PhpParser\Node\Stmt\ClassLike) {
return null;
}
foreach ($this->singleToManyMethods as $singleToManyMethod) {
if (!$this->isObjectType($classLike, $singleToManyMethod->getObjectType())) {
continue;
}
if (!$this->isName($node, $singleToManyMethod->getSingleMethodName())) {
continue;
}
$node->name = new \PhpParser\Node\Identifier($singleToManyMethod->getManyMethodName());
$this->keepOldReturnTypeInDocBlock($node);
$node->returnType = new \PhpParser\Node\Identifier('array');
$this->wrapReturnValueToArray($node);
return $node;
}
return null;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
$singleToManyMethods = $configuration[self::SINGLES_TO_MANY_METHODS] ?? $configuration;
\RectorPrefix20220218\Webmozart\Assert\Assert::allIsAOf($singleToManyMethods, \Rector\Transform\ValueObject\SingleToManyMethod::class);
$this->singleToManyMethods = $singleToManyMethods;
}
private function keepOldReturnTypeInDocBlock(\PhpParser\Node\Stmt\ClassMethod $classMethod) : void
{
// keep old return type in the docblock
$oldReturnType = $classMethod->returnType;
if ($oldReturnType === null) {
return;
}
$staticType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($oldReturnType);
$arrayType = new \PHPStan\Type\ArrayType(new \PHPStan\Type\MixedType(), $staticType);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $arrayType);
}
private function wrapReturnValueToArray(\PhpParser\Node\Stmt\ClassMethod $classMethod) : void
{
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (\PhpParser\Node $node) {
if (!$node instanceof \PhpParser\Node\Stmt\Return_) {
return null;
}
$node->expr = $this->nodeFactory->createArray([$node->expr]);
return null;
});
}
}

View File

@ -1,44 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Transform\ValueObject;
use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;
final class SingleToManyMethod
{
/**
* @readonly
* @var string
*/
private $class;
/**
* @readonly
* @var string
*/
private $singleMethodName;
/**
* @readonly
* @var string
*/
private $manyMethodName;
public function __construct(string $class, string $singleMethodName, string $manyMethodName)
{
$this->class = $class;
$this->singleMethodName = $singleMethodName;
$this->manyMethodName = $manyMethodName;
\Rector\Core\Validation\RectorAssert::className($class);
}
public function getObjectType() : \PHPStan\Type\ObjectType
{
return new \PHPStan\Type\ObjectType($this->class);
}
public function getSingleMethodName() : string
{
return $this->singleMethodName;
}
public function getManyMethodName() : string
{
return $this->manyMethodName;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'f022c20446fdac2e08cfeb46ffa1442af9c97bb5';
public const PACKAGE_VERSION = 'cab829909370c582441afaf59225d48eb9a86be1';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-18 00:34:08';
public const RELEASE_DATE = '2022-02-18 01:49:31';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220218\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 ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e::getLoader();
return ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6::getLoader();

View File

@ -3019,7 +3019,6 @@ return array(
'Rector\\Transform\\Rector\\Assign\\PropertyFetchToMethodCallRector' => $baseDir . '/rules/Transform/Rector/Assign/PropertyFetchToMethodCallRector.php',
'Rector\\Transform\\Rector\\Attribute\\AttributeKeyToClassConstFetchRector' => $baseDir . '/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\ReturnTypeWillChangeRector' => $baseDir . '/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\SingleToManyMethodRector' => $baseDir . '/rules/Transform/Rector/ClassMethod/SingleToManyMethodRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\WrapReturnRector' => $baseDir . '/rules/Transform/Rector/ClassMethod/WrapReturnRector.php',
'Rector\\Transform\\Rector\\Class_\\AddAllowDynamicPropertiesAttributeRector' => $baseDir . '/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php',
'Rector\\Transform\\Rector\\Class_\\AddInterfaceByParentRector' => $baseDir . '/rules/Transform/Rector/Class_/AddInterfaceByParentRector.php',
@ -3070,7 +3069,6 @@ return array(
'Rector\\Transform\\ValueObject\\PropertyFetchToMethodCall' => $baseDir . '/rules/Transform/ValueObject/PropertyFetchToMethodCall.php',
'Rector\\Transform\\ValueObject\\ReplaceParentCallByPropertyCall' => $baseDir . '/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php',
'Rector\\Transform\\ValueObject\\ServiceGetterToConstructorInjection' => $baseDir . '/rules/Transform/ValueObject/ServiceGetterToConstructorInjection.php',
'Rector\\Transform\\ValueObject\\SingleToManyMethod' => $baseDir . '/rules/Transform/ValueObject/SingleToManyMethod.php',
'Rector\\Transform\\ValueObject\\StaticCallToFuncCall' => $baseDir . '/rules/Transform/ValueObject/StaticCallToFuncCall.php',
'Rector\\Transform\\ValueObject\\StaticCallToMethodCall' => $baseDir . '/rules/Transform/ValueObject/StaticCallToMethodCall.php',
'Rector\\Transform\\ValueObject\\StaticCallToNew' => $baseDir . '/rules/Transform/ValueObject/StaticCallToNew.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e
class ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6', '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\ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit0df88c7745440821c3aae20346ab83d6::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit0df88c7745440821c3aae20346ab83d6::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire0a560f6a4ef102a1bb62767624b1e73e($fileIdentifier, $file);
composerRequire0df88c7745440821c3aae20346ab83d6($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e
* @param string $file
* @return void
*/
function composerRequire0a560f6a4ef102a1bb62767624b1e73e($fileIdentifier, $file)
function composerRequire0df88c7745440821c3aae20346ab83d6($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 ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e
class ComposerStaticInit0df88c7745440821c3aae20346ab83d6
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3408,7 +3408,6 @@ class ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e
'Rector\\Transform\\Rector\\Assign\\PropertyFetchToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Assign/PropertyFetchToMethodCallRector.php',
'Rector\\Transform\\Rector\\Attribute\\AttributeKeyToClassConstFetchRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\ReturnTypeWillChangeRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\SingleToManyMethodRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/ClassMethod/SingleToManyMethodRector.php',
'Rector\\Transform\\Rector\\ClassMethod\\WrapReturnRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/ClassMethod/WrapReturnRector.php',
'Rector\\Transform\\Rector\\Class_\\AddAllowDynamicPropertiesAttributeRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php',
'Rector\\Transform\\Rector\\Class_\\AddInterfaceByParentRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/AddInterfaceByParentRector.php',
@ -3459,7 +3458,6 @@ class ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e
'Rector\\Transform\\ValueObject\\PropertyFetchToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/PropertyFetchToMethodCall.php',
'Rector\\Transform\\ValueObject\\ReplaceParentCallByPropertyCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php',
'Rector\\Transform\\ValueObject\\ServiceGetterToConstructorInjection' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/ServiceGetterToConstructorInjection.php',
'Rector\\Transform\\ValueObject\\SingleToManyMethod' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/SingleToManyMethod.php',
'Rector\\Transform\\ValueObject\\StaticCallToFuncCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StaticCallToFuncCall.php',
'Rector\\Transform\\ValueObject\\StaticCallToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StaticCallToMethodCall.php',
'Rector\\Transform\\ValueObject\\StaticCallToNew' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StaticCallToNew.php',
@ -3875,9 +3873,9 @@ class ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0a560f6a4ef102a1bb62767624b1e73e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit0df88c7745440821c3aae20346ab83d6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0df88c7745440821c3aae20346ab83d6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0df88c7745440821c3aae20346ab83d6::$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('RectorPrefix20220218\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e', false) && !interface_exists('ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e', false) && !trait_exists('ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit0a560f6a4ef102a1bb62767624b1e73e');
if (!class_exists('ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6', false) && !interface_exists('ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6', false) && !trait_exists('ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit0df88c7745440821c3aae20346ab83d6');
}
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('RectorPrefix20220218\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220218\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire0a560f6a4ef102a1bb62767624b1e73e')) {
function composerRequire0a560f6a4ef102a1bb62767624b1e73e() {
return \RectorPrefix20220218\composerRequire0a560f6a4ef102a1bb62767624b1e73e(...func_get_args());
if (!function_exists('composerRequire0df88c7745440821c3aae20346ab83d6')) {
function composerRequire0df88c7745440821c3aae20346ab83d6() {
return \RectorPrefix20220218\composerRequire0df88c7745440821c3aae20346ab83d6(...func_get_args());
}
}
if (!function_exists('scanPath')) {