mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit fd7667b5aa8a17d28e61016463575eb4629744b1
fd7667b5aa
[CodeQuality] Skip ExplicitMethodCallOverMagicGetSetRector on method no param + variadic (#1768)
This commit is contained in:
parent
361d8f4a2f
commit
02632d1547
@ -157,16 +157,26 @@ CODE_SAMPLE
|
||||
if (!$propertyCallerType->hasMethod($setterMethodName)->yes()) {
|
||||
return null;
|
||||
}
|
||||
$scope = $propertyFetch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if ($scope instanceof \PHPStan\Analyser\Scope) {
|
||||
$methodReflection = $propertyCallerType->getMethod($setterMethodName, $scope);
|
||||
if ($methodReflection instanceof \PHPStan\Reflection\ResolvedMethodReflection) {
|
||||
$parametersAcceptor = \PHPStan\Reflection\ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
|
||||
if (\count($parametersAcceptor->getParameters()) > 1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($this->hasNoParamOrVariadic($propertyCallerType, $propertyFetch, $setterMethodName)) {
|
||||
return null;
|
||||
}
|
||||
return $this->nodeFactory->createMethodCall($propertyFetch->var, $setterMethodName, [$expr]);
|
||||
}
|
||||
private function hasNoParamOrVariadic(\PHPStan\Type\ObjectType $objectType, \PhpParser\Node\Expr\PropertyFetch $propertyFetch, string $setterMethodName) : bool
|
||||
{
|
||||
$scope = $propertyFetch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
||||
return \false;
|
||||
}
|
||||
$methodReflection = $objectType->getMethod($setterMethodName, $scope);
|
||||
if (!$methodReflection instanceof \PHPStan\Reflection\ResolvedMethodReflection) {
|
||||
return \false;
|
||||
}
|
||||
$parametersAcceptor = \PHPStan\Reflection\ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
|
||||
$parameters = $parametersAcceptor->getParameters();
|
||||
if (\count($parameters) !== 1) {
|
||||
return \true;
|
||||
}
|
||||
return $parameters[0]->isVariadic();
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f374b9faa834b5cceef16d99dd46e147ce753312';
|
||||
public const PACKAGE_VERSION = 'fd7667b5aa8a17d28e61016463575eb4629744b1';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-02-05 11:33:29';
|
||||
public const RELEASE_DATE = '2022-02-05 12:30:11';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20220205\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13::getLoader();
|
||||
return ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -2931,7 +2931,6 @@ return array(
|
||||
'Rector\\Symfony\\Rector\\Class_\\MakeCommandLazyRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/MakeCommandLazyRector.php',
|
||||
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => $vendorDir . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
|
||||
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => $vendorDir . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\AddFlashRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/AddFlashRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\CascadeValidationFormBuilderRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\ChangeStringCollectionOptionToConstantRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
class ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707', '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\ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitf39785332fd75ed91a3d1878ff255707::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,12 +42,12 @@ class ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitf39785332fd75ed91a3d1878ff255707::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire97206735baafd9ea9e5f49ff5efc1a13($fileIdentifier, $file);
|
||||
composerRequiref39785332fd75ed91a3d1878ff255707($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
@ -59,7 +59,7 @@ class ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire97206735baafd9ea9e5f49ff5efc1a13($fileIdentifier, $file)
|
||||
function composerRequiref39785332fd75ed91a3d1878ff255707($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
class ComposerStaticInitf39785332fd75ed91a3d1878ff255707
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
@ -3321,7 +3321,6 @@ class ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
'Rector\\Symfony\\Rector\\Class_\\MakeCommandLazyRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/MakeCommandLazyRector.php',
|
||||
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
|
||||
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\AddFlashRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/AddFlashRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\CascadeValidationFormBuilderRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\ChangeStringCollectionOptionToConstantRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php',
|
||||
@ -3865,9 +3864,9 @@ class ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit97206735baafd9ea9e5f49ff5efc1a13::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitf39785332fd75ed91a3d1878ff255707::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitf39785332fd75ed91a3d1878ff255707::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitf39785332fd75ed91a3d1878ff255707::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -2589,12 +2589,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "57743a8956c8cef8fb511b2d35aabbb49cba3161"
|
||||
"reference": "17e280a6328c6546f4054137277f7a8ff055b8e1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/57743a8956c8cef8fb511b2d35aabbb49cba3161",
|
||||
"reference": "57743a8956c8cef8fb511b2d35aabbb49cba3161",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/17e280a6328c6546f4054137277f7a8ff055b8e1",
|
||||
"reference": "17e280a6328c6546f4054137277f7a8ff055b8e1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2622,7 +2622,7 @@
|
||||
"symplify\/rule-doc-generator": "^10.0",
|
||||
"symplify\/vendor-patches": "^10.0"
|
||||
},
|
||||
"time": "2022-01-17T15:17:37+00:00",
|
||||
"time": "2022-02-05T11:04:37+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
||||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d1fa93d'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 81179de'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main df58e86'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6bee428'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main fbfa93c'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f23c4bf'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 49d312b'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 57743a8'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c08a83'));
|
||||
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d1fa93d'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 81179de'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main df58e86'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6bee428'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main fbfa93c'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f23c4bf'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 49d312b'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 17e280a'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c08a83'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -3,11 +3,9 @@
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix20220205;
|
||||
|
||||
use Rector\Symfony\Rector\MethodCall\AddFlashRector;
|
||||
use Rector\Symfony\Rector\MethodCall\RedirectToRouteRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(\Rector\Symfony\Rector\MethodCall\RedirectToRouteRector::class);
|
||||
$services->set(\Rector\Symfony\Rector\MethodCall\AddFlashRector::class);
|
||||
};
|
||||
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
|
||||
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Symfony\Tests\Rector\MethodCall\AddFlashRector\AddFlashRectorTest
|
||||
*/
|
||||
final class AddFlashRector extends \Rector\Core\Rector\AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
|
||||
*/
|
||||
private $fluentChainMethodCallNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\TypeAnalyzer\ControllerAnalyzer
|
||||
*/
|
||||
private $controllerAnalyzer;
|
||||
public function __construct(\Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer, \Rector\Symfony\TypeAnalyzer\ControllerAnalyzer $controllerAnalyzer)
|
||||
{
|
||||
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
|
||||
$this->controllerAnalyzer = $controllerAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Turns long flash adding to short helper method in Controller in Symfony', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeController extends Controller
|
||||
{
|
||||
public function some(Request $request)
|
||||
{
|
||||
$request->getSession()->getFlashBag()->add("success", "something");
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeController extends Controller
|
||||
{
|
||||
public function some(Request $request)
|
||||
{
|
||||
$this->addFlash("success", "something");
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Expr\MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if (!$this->controllerAnalyzer->isInsideController($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->fluentChainMethodCallNodeAnalyzer->isTypeAndChainCalls($node, new \PHPStan\Type\ObjectType('Symfony\\Component\\HttpFoundation\\Request'), ['getSession', 'getFlashBag', 'add'])) {
|
||||
return null;
|
||||
}
|
||||
return $this->nodeFactory->createMethodCall('this', 'addFlash', $node->args);
|
||||
}
|
||||
}
|
@ -7,9 +7,9 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
@ -17,6 +17,15 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class RedirectToRouteRector extends \Rector\Core\Rector\AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\TypeAnalyzer\ControllerAnalyzer
|
||||
*/
|
||||
private $controllerAnalyzer;
|
||||
public function __construct(\Rector\Symfony\TypeAnalyzer\ControllerAnalyzer $controllerAnalyzer)
|
||||
{
|
||||
$this->controllerAnalyzer = $controllerAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Turns redirect to route to short helper method in Controller in Symfony', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample('$this->redirect($this->generateUrl("homepage"));', '$this->redirectToRoute("homepage");')]);
|
||||
@ -37,11 +46,7 @@ final class RedirectToRouteRector extends \Rector\Core\Rector\AbstractRector
|
||||
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
||||
return null;
|
||||
}
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
if (!$classReflection->isSubclassOf('Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller') && !$classReflection->isSubclassOf('Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController')) {
|
||||
if (!$this->controllerAnalyzer->isInsideController($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, 'redirect')) {
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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('RectorPrefix20220205\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13', false) && !interface_exists('ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13', false) && !trait_exists('ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13', false)) {
|
||||
spl_autoload_call('RectorPrefix20220205\ComposerAutoloaderInit97206735baafd9ea9e5f49ff5efc1a13');
|
||||
if (!class_exists('ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707', false) && !interface_exists('ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707', false) && !trait_exists('ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707', false)) {
|
||||
spl_autoload_call('RectorPrefix20220205\ComposerAutoloaderInitf39785332fd75ed91a3d1878ff255707');
|
||||
}
|
||||
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('RectorPrefix20220205\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20220205\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire97206735baafd9ea9e5f49ff5efc1a13')) {
|
||||
function composerRequire97206735baafd9ea9e5f49ff5efc1a13() {
|
||||
return \RectorPrefix20220205\composerRequire97206735baafd9ea9e5f49ff5efc1a13(...func_get_args());
|
||||
if (!function_exists('composerRequiref39785332fd75ed91a3d1878ff255707')) {
|
||||
function composerRequiref39785332fd75ed91a3d1878ff255707() {
|
||||
return \RectorPrefix20220205\composerRequiref39785332fd75ed91a3d1878ff255707(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user