Updated Rector to commit ba2888f667

ba2888f667 Extract ControllerClassMethodAnalyzer (#365)
This commit is contained in:
Tomas Votruba 2021-07-02 21:24:16 +00:00
parent e3c7d5c703
commit 3d37eb7f17
9 changed files with 58 additions and 41 deletions

View File

@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace Rector\DependencyInjection\NodeAnalyzer;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ControllerClassMethodAnalyzer
{
public function isInControllerActionMethod(\PhpParser\Node\Expr\Variable $variable) : bool
{
/** @var string|null $className */
$className = $variable->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NAME);
if ($className === null) {
return \false;
}
if (\substr_compare($className, 'Controller', -\strlen('Controller')) !== 0) {
return \false;
}
$classMethod = $variable->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NODE);
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
return \false;
}
// is probably in controller action
return $classMethod->isPublic();
}
}

View File

@ -5,11 +5,10 @@ namespace Rector\DependencyInjection\Rector\Variable;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\DependencyInjection\Collector\VariablesToPropertyFetchCollection;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\DependencyInjection\NodeAnalyzer\ControllerClassMethodAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -21,9 +20,14 @@ final class ReplaceVariableByPropertyFetchRector extends \Rector\Core\Rector\Abs
* @var \Rector\DependencyInjection\Collector\VariablesToPropertyFetchCollection
*/
private $variablesToPropertyFetchCollection;
public function __construct(\Rector\DependencyInjection\Collector\VariablesToPropertyFetchCollection $variablesToPropertyFetchCollection)
/**
* @var \Rector\DependencyInjection\NodeAnalyzer\ControllerClassMethodAnalyzer
*/
private $controllerClassMethodAnalyzer;
public function __construct(\Rector\DependencyInjection\Collector\VariablesToPropertyFetchCollection $variablesToPropertyFetchCollection, \Rector\DependencyInjection\NodeAnalyzer\ControllerClassMethodAnalyzer $controllerClassMethodAnalyzer)
{
$this->variablesToPropertyFetchCollection = $variablesToPropertyFetchCollection;
$this->controllerClassMethodAnalyzer = $controllerClassMethodAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -79,7 +83,7 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if (!$this->isInControllerActionMethod($node)) {
if (!$this->controllerClassMethodAnalyzer->isInControllerActionMethod($node)) {
return null;
}
foreach ($this->variablesToPropertyFetchCollection->getVariableNamesAndTypes() as $name => $type) {
@ -94,21 +98,4 @@ CODE_SAMPLE
}
return null;
}
private function isInControllerActionMethod(\PhpParser\Node\Expr\Variable $variable) : bool
{
/** @var string|null $className */
$className = $variable->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NAME);
if ($className === null) {
return \false;
}
if (\substr_compare($className, 'Controller', -\strlen('Controller')) !== 0) {
return \false;
}
$classMethod = $variable->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::METHOD_NODE);
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
return \false;
}
// is probably in controller action
return $classMethod->isPublic();
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '2a0cae550788d85e58b1b603899c121e5df519b8';
public const PACKAGE_VERSION = 'ba2888f66784a9898ccd53feae4facadc6302f13';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-02 22:45:25';
public const RELEASE_DATE = '2021-07-02 23:15:46';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210702\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 ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882::getLoader();
return ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8::getLoader();

View File

@ -2043,6 +2043,7 @@ return array(
'Rector\\Defluent\\ValueObject\\FluentMethodCalls' => $baseDir . '/rules/Defluent/ValueObject/FluentMethodCalls.php',
'Rector\\Defluent\\ValueObject\\NormalToFluent' => $baseDir . '/rules/Defluent/ValueObject/NormalToFluent.php',
'Rector\\DependencyInjection\\Collector\\VariablesToPropertyFetchCollection' => $baseDir . '/rules/DependencyInjection/Collector/VariablesToPropertyFetchCollection.php',
'Rector\\DependencyInjection\\NodeAnalyzer\\ControllerClassMethodAnalyzer' => $baseDir . '/rules/DependencyInjection/NodeAnalyzer/ControllerClassMethodAnalyzer.php',
'Rector\\DependencyInjection\\NodeFactory\\InjectMethodFactory' => $baseDir . '/rules/DependencyInjection/NodeFactory/InjectMethodFactory.php',
'Rector\\DependencyInjection\\NodeManipulator\\PropertyConstructorInjectionManipulator' => $baseDir . '/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php',
'Rector\\DependencyInjection\\NodeRemover\\ClassMethodNodeRemover' => $baseDir . '/rules/DependencyInjection/NodeRemover/ClassMethodNodeRemover.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882
class ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8', '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\ComposerStaticInitf490057658a548a4f3c4a64f6c05a882::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitf490057658a548a4f3c4a64f6c05a882::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiref490057658a548a4f3c4a64f6c05a882($fileIdentifier, $file);
composerRequire3fdfa6bca686bb37b70e1d60bcfc21a8($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequiref490057658a548a4f3c4a64f6c05a882($fileIdentifier, $file)
function composerRequire3fdfa6bca686bb37b70e1d60bcfc21a8($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitf490057658a548a4f3c4a64f6c05a882
class ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2398,6 +2398,7 @@ class ComposerStaticInitf490057658a548a4f3c4a64f6c05a882
'Rector\\Defluent\\ValueObject\\FluentMethodCalls' => __DIR__ . '/../..' . '/rules/Defluent/ValueObject/FluentMethodCalls.php',
'Rector\\Defluent\\ValueObject\\NormalToFluent' => __DIR__ . '/../..' . '/rules/Defluent/ValueObject/NormalToFluent.php',
'Rector\\DependencyInjection\\Collector\\VariablesToPropertyFetchCollection' => __DIR__ . '/../..' . '/rules/DependencyInjection/Collector/VariablesToPropertyFetchCollection.php',
'Rector\\DependencyInjection\\NodeAnalyzer\\ControllerClassMethodAnalyzer' => __DIR__ . '/../..' . '/rules/DependencyInjection/NodeAnalyzer/ControllerClassMethodAnalyzer.php',
'Rector\\DependencyInjection\\NodeFactory\\InjectMethodFactory' => __DIR__ . '/../..' . '/rules/DependencyInjection/NodeFactory/InjectMethodFactory.php',
'Rector\\DependencyInjection\\NodeManipulator\\PropertyConstructorInjectionManipulator' => __DIR__ . '/../..' . '/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php',
'Rector\\DependencyInjection\\NodeRemover\\ClassMethodNodeRemover' => __DIR__ . '/../..' . '/rules/DependencyInjection/NodeRemover/ClassMethodNodeRemover.php',
@ -3845,9 +3846,9 @@ class ComposerStaticInitf490057658a548a4f3c4a64f6c05a882
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf490057658a548a4f3c4a64f6c05a882::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf490057658a548a4f3c4a64f6c05a882::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf490057658a548a4f3c4a64f6c05a882::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3fdfa6bca686bb37b70e1d60bcfc21a8::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1679,7 +1679,7 @@
"description": "Instant fixes for your TYPO3 code by using Rector.",
"support": {
"issues": "https:\/\/github.com\/sabbelasichon\/typo3-rector\/issues",
"source": "https:\/\/github.com\/sabbelasichon\/typo3-rector\/tree\/main"
"source": "https:\/\/github.com\/sabbelasichon\/typo3-rector\/tree\/v0.11.20"
},
"funding": [
{

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('RectorPrefix20210702\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882', false) && !interface_exists('ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882', false) && !trait_exists('ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882', false)) {
spl_autoload_call('RectorPrefix20210702\ComposerAutoloaderInitf490057658a548a4f3c4a64f6c05a882');
if (!class_exists('ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8', false) && !interface_exists('ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8', false) && !trait_exists('ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8', false)) {
spl_autoload_call('RectorPrefix20210702\ComposerAutoloaderInit3fdfa6bca686bb37b70e1d60bcfc21a8');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210702\Doctrine\Inflector\Inflector');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210702\print_node(...func_get_args());
}
}
if (!function_exists('composerRequiref490057658a548a4f3c4a64f6c05a882')) {
function composerRequiref490057658a548a4f3c4a64f6c05a882() {
return \RectorPrefix20210702\composerRequiref490057658a548a4f3c4a64f6c05a882(...func_get_args());
if (!function_exists('composerRequire3fdfa6bca686bb37b70e1d60bcfc21a8')) {
function composerRequire3fdfa6bca686bb37b70e1d60bcfc21a8() {
return \RectorPrefix20210702\composerRequire3fdfa6bca686bb37b70e1d60bcfc21a8(...func_get_args());
}
}
if (!function_exists('parseArgs')) {