Updated Rector to commit 57e2712bd04d491826cc60afa9e003c54e8add96

57e2712bd0 Move AddMethodParentCallRector to Symfony Rector (#4301)
This commit is contained in:
Tomas Votruba 2023-06-20 08:35:19 +00:00
parent ba7a1a55c4
commit 577f0343f5
9 changed files with 13 additions and 180 deletions

View File

@ -1,4 +1,4 @@
# 370 Rules Overview
# 369 Rules Overview
<br>
@ -12,8 +12,6 @@
- [DeadCode](#deadcode) (43)
- [DependencyInjection](#dependencyinjection) (1)
- [EarlyReturn](#earlyreturn) (10)
- [MysqlToMysqli](#mysqltomysqli) (4)
@ -3236,47 +3234,6 @@ Remove php version checks if they are passed
<br>
## DependencyInjection
### AddMethodParentCallRector
Add method parent call, in case new parent method is added
:wrench: **configure it!**
- class: [`Rector\DependencyInjection\Rector\ClassMethod\AddMethodParentCallRector`](../rules/DependencyInjection/Rector/ClassMethod/AddMethodParentCallRector.php)
```php
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\DependencyInjection\Rector\ClassMethod\AddMethodParentCallRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(AddMethodParentCallRector::class, [
'ParentClassWithNewConstructor' => '__construct',
]);
};
```
```diff
class SunshineCommand extends ParentClassWithNewConstructor
{
public function __construct()
{
$value = 5;
+
+ parent::__construct();
}
}
```
<br>
## EarlyReturn
### ChangeAndIfToEarlyReturnRector

View File

@ -1,120 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\DependencyInjection\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\MethodName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202306\Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\DependencyInjection\Rector\ClassMethod\AddMethodParentCallRector\AddMethodParentCallRectorTest
*/
final class AddMethodParentCallRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
{
/**
* @var array<string, string>
*/
private $methodByParentTypes = [];
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add method parent call, in case new parent method is added', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
class SunshineCommand extends ParentClassWithNewConstructor
{
public function __construct()
{
$value = 5;
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SunshineCommand extends ParentClassWithNewConstructor
{
public function __construct()
{
$value = 5;
parent::__construct();
}
}
CODE_SAMPLE
, ['ParentClassWithNewConstructor' => MethodName::CONSTRUCT])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
if (!$scope->isInClass()) {
return null;
}
$classReflection = $scope->getClassReflection();
foreach ($this->methodByParentTypes as $type => $method) {
// not itself
if ($classReflection->getName() === $type) {
continue;
}
if ($this->shouldSkipMethod($node, $method)) {
continue;
}
if (!$classReflection->isSubclassOf($type)) {
continue;
}
$node->stmts[] = $this->createParentStaticCall($method);
return $node;
}
return null;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
Assert::allString(\array_keys($configuration));
Assert::allString($configuration);
/** @var array<string, string> $configuration */
$this->methodByParentTypes = $configuration;
}
private function shouldSkipMethod(ClassMethod $classMethod, string $method) : bool
{
if (!$this->isName($classMethod, $method)) {
return \true;
}
return $this->hasParentCallOfMethod($classMethod, $method);
}
private function createParentStaticCall(string $method) : Expression
{
$staticCall = $this->nodeFactory->createStaticCall(ObjectReference::PARENT, $method);
return new Expression($staticCall);
}
/**
* Looks for "parent::<methodName>
*/
private function hasParentCallOfMethod(ClassMethod $classMethod, string $method) : bool
{
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use($method) : bool {
if (!$node instanceof StaticCall) {
return \false;
}
if (!$this->isName($node->class, ObjectReference::PARENT)) {
return \false;
}
return $this->isName($node->name, $method);
});
}
}

View File

@ -13,7 +13,6 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'c20828965125f2afbde8367f68dab0f9ae983cf1';
public const PACKAGE_VERSION = '57e2712bd04d491826cc60afa9e003c54e8add96';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-20 09:26:36';
public const RELEASE_DATE = '2023-06-20 08:30:58';
/**
* @var int
*/

View File

@ -4,7 +4,6 @@ declare (strict_types=1);
namespace Rector\Core\Console\Formatter;
use RectorPrefix202306\SebastianBergmann\Diff\Differ;
use RectorPrefix202306\SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder;
use RectorPrefix202306\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
final class ConsoleDiffer
{

2
vendor/autoload.php vendored
View File

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

View File

@ -1740,7 +1740,6 @@ return array(
'Rector\\DeadCode\\ValueObject\\BinaryToVersionCompareCondition' => $baseDir . '/rules/DeadCode/ValueObject/BinaryToVersionCompareCondition.php',
'Rector\\DeadCode\\ValueObject\\VariableAndPropertyFetchAssign' => $baseDir . '/rules/DeadCode/ValueObject/VariableAndPropertyFetchAssign.php',
'Rector\\DeadCode\\ValueObject\\VersionCompareCondition' => $baseDir . '/rules/DeadCode/ValueObject/VersionCompareCondition.php',
'Rector\\DependencyInjection\\Rector\\ClassMethod\\AddMethodParentCallRector' => $baseDir . '/rules/DependencyInjection/Rector/ClassMethod/AddMethodParentCallRector.php',
'Rector\\Doctrine\\NodeAnalyzer\\AssignPropertyFetchAnalyzer' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AssignPropertyFetchAnalyzer.php',
'Rector\\Doctrine\\NodeAnalyzer\\AttributeCleaner' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeCleaner.php',
'Rector\\Doctrine\\NodeAnalyzer\\AttributeFinder' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeFinder.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitabca27656ffe000cef73b9542e589554
class ComposerAutoloaderInite43434694c102827ca61c8b125ba1969
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitabca27656ffe000cef73b9542e589554
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitabca27656ffe000cef73b9542e589554', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInite43434694c102827ca61c8b125ba1969', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitabca27656ffe000cef73b9542e589554', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInite43434694c102827ca61c8b125ba1969', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitabca27656ffe000cef73b9542e589554::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInite43434694c102827ca61c8b125ba1969::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitabca27656ffe000cef73b9542e589554::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInite43434694c102827ca61c8b125ba1969::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInitabca27656ffe000cef73b9542e589554
class ComposerStaticInite43434694c102827ca61c8b125ba1969
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1991,7 +1991,6 @@ class ComposerStaticInitabca27656ffe000cef73b9542e589554
'Rector\\DeadCode\\ValueObject\\BinaryToVersionCompareCondition' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/BinaryToVersionCompareCondition.php',
'Rector\\DeadCode\\ValueObject\\VariableAndPropertyFetchAssign' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/VariableAndPropertyFetchAssign.php',
'Rector\\DeadCode\\ValueObject\\VersionCompareCondition' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/VersionCompareCondition.php',
'Rector\\DependencyInjection\\Rector\\ClassMethod\\AddMethodParentCallRector' => __DIR__ . '/../..' . '/rules/DependencyInjection/Rector/ClassMethod/AddMethodParentCallRector.php',
'Rector\\Doctrine\\NodeAnalyzer\\AssignPropertyFetchAnalyzer' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AssignPropertyFetchAnalyzer.php',
'Rector\\Doctrine\\NodeAnalyzer\\AttributeCleaner' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeCleaner.php',
'Rector\\Doctrine\\NodeAnalyzer\\AttributeFinder' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeFinder.php',
@ -3098,9 +3097,9 @@ class ComposerStaticInitabca27656ffe000cef73b9542e589554
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitabca27656ffe000cef73b9542e589554::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitabca27656ffe000cef73b9542e589554::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitabca27656ffe000cef73b9542e589554::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInite43434694c102827ca61c8b125ba1969::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite43434694c102827ca61c8b125ba1969::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite43434694c102827ca61c8b125ba1969::$classMap;
}, null, ClassLoader::class);
}