Updated Rector to commit 50bbdd1e93

50bbdd1e93 [DeadCode] Do not remove used parameter on RemoveUnusedPrivatePropertyRector (#1337)
This commit is contained in:
Tomas Votruba 2021-11-29 06:47:55 +00:00
parent ccc5a527cd
commit 34b0b39e5f
29 changed files with 217 additions and 96 deletions

View File

@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
@ -154,6 +155,8 @@ final class ComplexNodeRemover
}
$params = $constructClassMethod->getParams();
$paramKeysToBeRemoved = [];
/** @var Variable[] $variables */
$variables = $this->resolveVariables($constructClassMethod);
foreach ($params as $key => $param) {
$variable = $this->betterNodeFinder->findFirst((array) $constructClassMethod->stmts, function (\PhpParser\Node $node) use($param) : bool {
return $this->nodeComparator->areNodesEqual($param->var, $node);
@ -167,10 +170,37 @@ final class ComplexNodeRemover
if (!$this->nodeComparator->areNodesEqual($param->var, $assign->expr)) {
continue;
}
if ($this->isInVariables($variables, $assign)) {
continue;
}
$paramKeysToBeRemoved[] = $key;
}
$this->processRemoveParamWithKeys($params, $paramKeysToBeRemoved);
}
/**
* @return Variable[]
*/
private function resolveVariables(\PhpParser\Node\Stmt\ClassMethod $classMethod) : array
{
return $this->betterNodeFinder->find((array) $classMethod->stmts, function (\PhpParser\Node $subNode) : bool {
if (!$subNode instanceof \PhpParser\Node\Expr\Variable) {
return \false;
}
return $this->isExpressionVariableNotAssign($subNode);
});
}
/**
* @param Variable[] $variables
*/
private function isInVariables(array $variables, \PhpParser\Node\Expr\Assign $assign) : bool
{
foreach ($variables as $variable) {
if ($this->nodeComparator->areNodesEqual($assign->expr, $variable)) {
return \true;
}
}
return \false;
}
/**
* @param Param[] $params
* @param int[] $paramKeysToBeRemoved

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '4ad4d16ac63bd20127e23389c40e5cf7296c41ea';
public const PACKAGE_VERSION = '50bbdd1e934f3ae6cc808debf5059bf48bd8d3e2';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-28 23:53:11';
public const RELEASE_DATE = '2021-11-29 09:30:00';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211129\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 ComposerAutoloaderInitffe715fe221b8fc7fa75381e210607f6::getLoader();
return ComposerAutoloaderInit9a0804c2fa2b16f124e30b25ead868d5::getLoader();

View File

@ -2886,6 +2886,7 @@ return array(
'Rector\\Symfony\\Set\\TwigSetList' => $vendorDir . '/rector/rector-symfony/src/Set/TwigSetList.php',
'Rector\\Symfony\\TypeAnalyzer\\ArrayUnionResponseTypeAnalyzer' => $vendorDir . '/rector/rector-symfony/src/TypeAnalyzer/ArrayUnionResponseTypeAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\ContainerAwareAnalyzer' => $vendorDir . '/rector/rector-symfony/src/TypeAnalyzer/ContainerAwareAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\ControllerAnalyzer' => $vendorDir . '/rector/rector-symfony/src/TypeAnalyzer/ControllerAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\JMSDITypeResolver' => $vendorDir . '/rector/rector-symfony/src/TypeAnalyzer/JMSDITypeResolver.php',
'Rector\\Symfony\\TypeDeclaration\\ReturnTypeDeclarationUpdater' => $vendorDir . '/rector/rector-symfony/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php',
'Rector\\Symfony\\ValueObjectFactory\\ServiceMapFactory' => $vendorDir . '/rector/rector-symfony/src/ValueObjectFactory/ServiceMapFactory.php',

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitffe715fe221b8fc7fa75381e210607f6
class ComposerStaticInit9a0804c2fa2b16f124e30b25ead868d5
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3283,6 +3283,7 @@ class ComposerStaticInitffe715fe221b8fc7fa75381e210607f6
'Rector\\Symfony\\Set\\TwigSetList' => __DIR__ . '/..' . '/rector/rector-symfony/src/Set/TwigSetList.php',
'Rector\\Symfony\\TypeAnalyzer\\ArrayUnionResponseTypeAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/TypeAnalyzer/ArrayUnionResponseTypeAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\ContainerAwareAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/TypeAnalyzer/ContainerAwareAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\ControllerAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/TypeAnalyzer/ControllerAnalyzer.php',
'Rector\\Symfony\\TypeAnalyzer\\JMSDITypeResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/TypeAnalyzer/JMSDITypeResolver.php',
'Rector\\Symfony\\TypeDeclaration\\ReturnTypeDeclarationUpdater' => __DIR__ . '/..' . '/rector/rector-symfony/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php',
'Rector\\Symfony\\ValueObjectFactory\\ServiceMapFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObjectFactory/ServiceMapFactory.php',
@ -3770,9 +3771,9 @@ class ComposerStaticInitffe715fe221b8fc7fa75381e210607f6
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitffe715fe221b8fc7fa75381e210607f6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitffe715fe221b8fc7fa75381e210607f6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitffe715fe221b8fc7fa75381e210607f6::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit9a0804c2fa2b16f124e30b25ead868d5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9a0804c2fa2b16f124e30b25ead868d5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9a0804c2fa2b16f124e30b25ead868d5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2468,17 +2468,17 @@
},
{
"name": "rector\/rector-symfony",
"version": "0.11.42",
"version_normalized": "0.11.42.0",
"version": "0.11.43",
"version_normalized": "0.11.43.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "0c9c7fccf62f4150ceb94f9c344322cdd6bac62a"
"reference": "cb0a0d27190878e63d4851d257e1d97f0b78cae1"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/0c9c7fccf62f4150ceb94f9c344322cdd6bac62a",
"reference": "0c9c7fccf62f4150ceb94f9c344322cdd6bac62a",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/cb0a0d27190878e63d4851d257e1d97f0b78cae1",
"reference": "cb0a0d27190878e63d4851d257e1d97f0b78cae1",
"shasum": ""
},
"require": {
@ -2492,6 +2492,8 @@
"require-dev": {
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.1",
"phpstan\/phpstan-strict-rules": "^1.1",
"phpstan\/phpstan-webmozart-assert": "^1.0",
"phpunit\/phpunit": "^9.5",
"rector\/phpstan-rules": "^0.4.4",
"rector\/rector-src": "dev-main",
@ -2503,7 +2505,7 @@
"symplify\/phpstan-rules": "^10.0",
"symplify\/rule-doc-generator": "^10.0"
},
"time": "2021-11-23T11:15:50+00:00",
"time": "2021-11-29T00:04:04+00:00",
"type": "rector-extension",
"extra": {
"branch-alias": {
@ -2528,7 +2530,7 @@
"description": "Rector upgrades rules for Symfony Framework",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-symfony\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/0.11.42"
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/0.11.43"
},
"install-path": "..\/rector\/rector-symfony"
},

File diff suppressed because one or more lines are too long

View File

@ -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' => '0.11.7'), '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' => '0.11.40'), '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' => '0.11.13'), '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' => '0.11.54'), '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' => '0.11.7'), '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' => '0.11.23'), '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' => '0.11.42'), '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' => 'v0.11.31'));
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' => '0.11.7'), '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' => '0.11.40'), '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' => '0.11.13'), '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' => '0.11.54'), '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' => '0.11.7'), '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' => '0.11.23'), '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' => '0.11.43'), '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' => 'v0.11.31'));
private function __construct()
{
}

View File

@ -20,7 +20,9 @@
"symplify\/easy-coding-standard": "^10.0",
"symplify\/rule-doc-generator": "^10.0",
"phpstan\/extension-installer": "^1.1",
"rector\/phpstan-rules": "^0.4.4"
"rector\/phpstan-rules": "^0.4.4",
"phpstan\/phpstan-strict-rules": "^1.1",
"phpstan\/phpstan-webmozart-assert": "^1.0"
},
"autoload": {
"psr-4": {

View File

@ -8,7 +8,6 @@ use RectorPrefix20211129\Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagR
use RectorPrefix20211129\Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker;
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->defaults()->autowire();
// @see https://github.com/symplify/monorepo-builder#6-release-flow
$services->set(\RectorPrefix20211129\Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker::class);
$services->set(\RectorPrefix20211129\Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagReleaseWorker::class);

View File

@ -5,6 +5,8 @@ namespace RectorPrefix20211129;
use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
@ -17,8 +19,9 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
'*/Fixture/*',
'*/Source/*',
]);
$containerConfigurator->import(\Rector\Set\ValueObject\SetList::PHP_74);
$containerConfigurator->import(\Rector\Set\ValueObject\SetList::PHP_80);
$containerConfigurator->import(\Rector\Set\ValueObject\SetList::DEAD_CODE);
$services = $containerConfigurator->services();
$services->set(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class)->call('configure', [[\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::CLASSES_TO_SKIP => ['Symfony\\*', 'Twig_*', 'Swift_*']]]);
$containerConfigurator->import(\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_80);
$containerConfigurator->import(\Rector\Set\ValueObject\SetList::CODE_QUALITY);
$containerConfigurator->import(\Rector\Set\ValueObject\SetList::DEAD_CODE);
};

View File

@ -3,7 +3,7 @@
declare (strict_types=1);
namespace Rector\Symfony\ApplicationMetadata;
use RectorPrefix20211129\Nette\Utils\Strings;
use Rector\Core\Util\StringUtils;
use Rector\Symfony\DataProvider\ServiceMapProvider;
use Rector\Symfony\ValueObject\ServiceDefinition;
use Rector\Symfony\ValueObject\Tag\EventListenerTag;
@ -42,7 +42,7 @@ final class ListenerServiceDefinitionProvider
$eventListeners = $serviceMap->getServicesByTag('kernel.event_listener');
foreach ($eventListeners as $eventListener) {
// skip Symfony core listeners
if (\RectorPrefix20211129\Nette\Utils\Strings::match((string) $eventListener->getClass(), self::SYMFONY_FAMILY_REGEX)) {
if (\Rector\Core\Util\StringUtils::isMatch((string) $eventListener->getClass(), self::SYMFONY_FAMILY_REGEX)) {
continue;
}
foreach ($eventListener->getTags() as $tag) {

View File

@ -42,7 +42,7 @@ final class BundleClassResolver
$classReflection = $this->reflectionProvider->getClass($class);
// resolve bundle from existing ones
$fileName = $classReflection->getFileName();
if (!$fileName) {
if ($fileName === null) {
return null;
}
$controllerDirectory = \dirname($fileName);

View File

@ -101,7 +101,7 @@ final class TemplateGuesser
private function resolveController(string $class) : string
{
$match = \RectorPrefix20211129\Nette\Utils\Strings::match($class, self::CONTROLLER_NAME_MATCH_REGEX);
if (!$match) {
if ($match === null) {
return '';
}
$controller = \RectorPrefix20211129\Nette\Utils\Strings::replace($match['class_name_without_suffix'], self::SMALL_LETTER_BIG_LETTER_REGEX, '1_\\2');

View File

@ -93,9 +93,9 @@ final class GetSubscribedEventsClassMethodFactory
foreach ($eventsToMethods as $eventName => $methodNamesWithPriorities) {
$eventNameExpr = $this->eventReferenceFactory->createEventName($eventName, $eventNamesToClassConstants);
// just method name, without a priority
if (!\is_array($methodNamesWithPriorities)) {
$methodNamesWithPriorities = [$methodNamesWithPriorities];
}
// if (! is_array($methodNamesWithPriorities)) {
// $methodNamesWithPriorities = [$methodNamesWithPriorities];
// }
if (\count($methodNamesWithPriorities) === 1) {
$this->createSingleMethod($methodNamesWithPriorities, $eventName, $eventNameExpr, $eventsToMethodsArray);
} else {
@ -117,7 +117,7 @@ final class GetSubscribedEventsClassMethodFactory
if ($priority !== null && $priority !== 0) {
$methodNameWithPriorityArray = new \PhpParser\Node\Expr\Array_();
$methodNameWithPriorityArray->items[] = new \PhpParser\Node\Expr\ArrayItem(new \PhpParser\Node\Scalar\String_($methodName));
$methodNameWithPriorityArray->items[] = new \PhpParser\Node\Expr\ArrayItem(new \PhpParser\Node\Scalar\LNumber((int) $priority));
$methodNameWithPriorityArray->items[] = new \PhpParser\Node\Expr\ArrayItem(new \PhpParser\Node\Scalar\LNumber($priority));
return new \PhpParser\Node\Expr\ArrayItem($methodNameWithPriorityArray, $expr);
}
return new \PhpParser\Node\Expr\ArrayItem(new \PhpParser\Node\Scalar\String_($methodName), $expr);

View File

@ -7,12 +7,14 @@ use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use RectorPrefix20211129\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
final class OnSuccessLogoutClassMethodFactory
{
@ -81,6 +83,10 @@ final class OnSuccessLogoutClassMethodFactory
if (!$this->nodeNameResolver->isName($node, 'request')) {
return null;
}
$parent = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if ($parent instanceof \PhpParser\Node\Param) {
return null;
}
return new \PhpParser\Node\Expr\MethodCall(new \PhpParser\Node\Expr\Variable(self::LOGOUT_EVENT), 'getRequest');
});
}

View File

@ -70,8 +70,8 @@ final class ThisRenderFactory
}
private function resolveTemplateName(\PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : string
{
$template = $templateDoctrineAnnotationTagValueNode->getValue('template') ?: $templateDoctrineAnnotationTagValueNode->getSilentValue();
if ($template !== null) {
$template = $this->resolveTemplate($templateDoctrineAnnotationTagValueNode);
if (\is_string($template)) {
return $template;
}
return $this->templateGuesser->resolveFromClassMethodNode($classMethod);
@ -88,7 +88,7 @@ final class ThisRenderFactory
if ($return === null) {
return null;
}
if ($return->expr instanceof \PhpParser\Node\Expr\Array_ && \count($return->expr->items)) {
if ($return->expr instanceof \PhpParser\Node\Expr\Array_ && $return->expr->items !== []) {
return $return->expr;
}
if ($return->expr instanceof \PhpParser\Node\Expr\MethodCall) {
@ -119,4 +119,19 @@ final class ThisRenderFactory
}
return null;
}
/**
* @return string|null
*/
private function resolveTemplate(\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode)
{
$templateParameter = $doctrineAnnotationTagValueNode->getValue('template');
if (\is_string($templateParameter)) {
return $templateParameter;
}
$silentValue = $doctrineAnnotationTagValueNode->getSilentValue();
if (\is_string($silentValue)) {
return $silentValue;
}
return null;
}
}

View File

@ -172,7 +172,7 @@ CODE_SAMPLE
private function isSuccessfulRefactorTernaryReturn(\PhpParser\Node\Expr\Ternary $ternary) : bool
{
$hasChanged = \false;
if ($ternary->if && $this->valueResolver->isNull($ternary->if)) {
if ($ternary->if instanceof \PhpParser\Node\Expr && $this->valueResolver->isNull($ternary->if)) {
$ternary->if = new \PhpParser\Node\Scalar\LNumber(0);
$hasChanged = \true;
}

View File

@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer;
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -32,9 +33,14 @@ final class GetRequestRector extends \Rector\Core\Rector\AbstractRector
* @var \Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer
*/
private $controllerMethodAnalyzer;
public function __construct(\Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer $controllerMethodAnalyzer)
/**
* @var \Rector\Symfony\TypeAnalyzer\ControllerAnalyzer
*/
private $controllerAnalyzer;
public function __construct(\Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer $controllerMethodAnalyzer, \Rector\Symfony\TypeAnalyzer\ControllerAnalyzer $controllerAnalyzer)
{
$this->controllerMethodAnalyzer = $controllerMethodAnalyzer;
$this->controllerAnalyzer = $controllerAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -72,13 +78,11 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if (!$this->controllerAnalyzer->detect($node)) {
return null;
}
if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) {
$this->requestVariableAndParamName = $this->resolveUniqueName($node, 'request');
if ($this->isActionWithGetRequestInBody($node)) {
$fullyQualified = new \PhpParser\Node\Name\FullyQualified(self::REQUEST_CLASS);
$node->params[] = new \PhpParser\Node\Param(new \PhpParser\Node\Expr\Variable($this->getRequestVariableAndParamName()), null, $fullyQualified);
return $node;
}
return $this->refactorClassMethod($node);
}
if ($this->isGetRequestInAction($node)) {
return new \PhpParser\Node\Expr\Variable($this->getRequestVariableAndParamName());
@ -124,25 +128,19 @@ CODE_SAMPLE
}
return \false;
}
private function isGetRequestInAction(\PhpParser\Node $node) : bool
private function isGetRequestInAction(\PhpParser\Node\Expr\MethodCall $methodCall) : bool
{
if (!$node instanceof \PhpParser\Node\Expr\MethodCall) {
return \false;
}
if (!$node->var instanceof \PhpParser\Node\Expr\Variable) {
return \false;
}
// must be $this->getRequest() in controller
if (!$node->var instanceof \PhpParser\Node\Expr\Variable) {
if (!$methodCall->var instanceof \PhpParser\Node\Expr\Variable) {
return \false;
}
if (!$this->nodeNameResolver->isName($node->var, 'this')) {
if (!$this->nodeNameResolver->isName($methodCall->var, 'this')) {
return \false;
}
if (!$this->isName($node->name, 'getRequest') && !$this->isGetMethodCallWithRequestParameters($node)) {
if (!$this->isName($methodCall->name, 'getRequest') && !$this->isGetMethodCallWithRequestParameters($methodCall)) {
return \false;
}
$classMethod = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\ClassMethod::class);
$classMethod = $this->betterNodeFinder->findParentType($methodCall, \PhpParser\Node\Stmt\ClassMethod::class);
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
return \false;
}
@ -185,4 +183,17 @@ CODE_SAMPLE
}
return $this->requestVariableAndParamName;
}
/**
* @return \PhpParser\Node\Stmt\ClassMethod|null
*/
private function refactorClassMethod(\PhpParser\Node\Stmt\ClassMethod $classMethod)
{
$this->requestVariableAndParamName = $this->resolveUniqueName($classMethod, 'request');
if (!$this->isActionWithGetRequestInBody($classMethod)) {
return null;
}
$fullyQualified = new \PhpParser\Node\Name\FullyQualified(self::REQUEST_CLASS);
$classMethod->params[] = new \PhpParser\Node\Param(new \PhpParser\Node\Expr\Variable($this->getRequestVariableAndParamName()), null, $fullyQualified);
return $classMethod;
}
}

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -93,7 +94,7 @@ CODE_SAMPLE
if (!$symfonyDoctrineAnnotationTagValueNode instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
return null;
}
$methods = $sensioDoctrineAnnotationTagValueNode->getValue('methods') ?: $sensioDoctrineAnnotationTagValueNode->getSilentValue();
$methods = $this->resolveMethods($sensioDoctrineAnnotationTagValueNode);
if ($methods === null) {
return null;
}
@ -102,4 +103,25 @@ CODE_SAMPLE
$this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
return $node;
}
/**
* @return mixed[]|\Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode|null
*/
private function resolveMethods(\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode)
{
$methodsParameter = $doctrineAnnotationTagValueNode->getValue('methods');
if (\is_array($methodsParameter)) {
return $methodsParameter;
}
if ($methodsParameter instanceof \Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode) {
return $methodsParameter;
}
$silentValue = $doctrineAnnotationTagValueNode->getSilentValue();
if (\is_array($silentValue)) {
return $silentValue;
}
if ($silentValue instanceof \Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode) {
return $silentValue;
}
return null;
}
}

View File

@ -5,12 +5,10 @@ namespace Rector\Symfony\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -22,9 +20,14 @@ final class AddFlashRector extends \Rector\Core\Rector\AbstractRector
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
*/
private $fluentChainMethodCallNodeAnalyzer;
public function __construct(\Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer)
/**
* @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
{
@ -60,16 +63,7 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
// might be missing in a trait
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->detect($node)) {
return null;
}
if (!$this->fluentChainMethodCallNodeAnalyzer->isTypeAndChainCalls($node, new \PHPStan\Type\ObjectType('Symfony\\Component\\HttpFoundation\\Request'), ['getSession', 'getFlashBag', 'add'])) {

View File

@ -93,9 +93,10 @@ CODE_SAMPLE
}
// type analyzer
$activeValueType = $this->getType($activeArgValue);
if ($activeValueType instanceof \PHPStan\Type\StringType) {
$this->processStringType($node, $argumentPosition, $activeArgValue);
if (!$activeValueType instanceof \PHPStan\Type\StringType) {
return null;
}
$this->processStringType($node, $argumentPosition, $activeArgValue);
return $node;
}
private function shouldSkipProcessMethodCall(\PhpParser\Node\Expr\MethodCall $methodCall) : bool
@ -110,9 +111,7 @@ CODE_SAMPLE
{
if ($firstArgumentExpr instanceof \PhpParser\Node\Expr\BinaryOp\Concat) {
$arrayNode = $this->nodeTransformer->transformConcatToStringArray($firstArgumentExpr);
if ($arrayNode !== null) {
$expr->args[$argumentPosition] = new \PhpParser\Node\Arg($arrayNode);
}
$expr->args[$argumentPosition] = new \PhpParser\Node\Arg($arrayNode);
return;
}
if ($firstArgumentExpr instanceof \PhpParser\Node\Expr\FuncCall && $this->isName($firstArgumentExpr, 'sprintf')) {

View File

@ -96,10 +96,7 @@ CODE_SAMPLE
}
private function resolveServiceType(\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo, \PhpParser\Node\Stmt\Property $property) : \PHPStan\Type\Type
{
$serviceType = new \PHPStan\Type\MixedType();
if ($doctrineAnnotationTagValueNode !== null) {
$serviceType = $phpDocInfo->getVarType();
}
$serviceType = $phpDocInfo->getVarType();
if (!$serviceType instanceof \PHPStan\Type\MixedType) {
return $serviceType;
}

View File

@ -11,6 +11,7 @@ use PHPStan\Analyser\Scope;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\StringUtils;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -74,11 +75,11 @@ final class ParseFileRector extends \Rector\Core\Rector\AbstractRector
$possibleFileNode = $firstArg->value;
$possibleFileNodeAsString = $this->print($possibleFileNode);
// is yml/yaml file
if (\RectorPrefix20211129\Nette\Utils\Strings::match($possibleFileNodeAsString, self::YAML_SUFFIX_IN_QUOTE_REGEX)) {
if (\Rector\Core\Util\StringUtils::isMatch($possibleFileNodeAsString, self::YAML_SUFFIX_IN_QUOTE_REGEX)) {
return \true;
}
// is probably a file variable
if (\RectorPrefix20211129\Nette\Utils\Strings::match($possibleFileNodeAsString, self::FILE_SUFFIX_REGEX)) {
if (\Rector\Core\Util\StringUtils::isMatch($possibleFileNodeAsString, self::FILE_SUFFIX_REGEX)) {
return \true;
}
// try to detect current value

View File

@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\TypeAnalyzer;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ControllerAnalyzer
{
public function detect(\PhpParser\Node $node) : bool
{
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
// might be missing in a trait
if (!$scope instanceof \PHPStan\Analyser\Scope) {
return \false;
}
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
return \false;
}
if ($classReflection->isSubclassOf('Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller')) {
return \true;
}
return $classReflection->isSubclassOf('Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController');
}
}

View File

@ -50,12 +50,10 @@ final class JMSDITypeResolver
public function resolve(\PhpParser\Node\Stmt\Property $property, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : \PHPStan\Type\Type
{
$serviceMap = $this->serviceMapProvider->provide();
$serviceName = ($doctrineAnnotationTagValueNode->getValueWithoutQuotes('serviceName') ?: $doctrineAnnotationTagValueNode->getSilentValue()) ?: $this->nodeNameResolver->getName($property);
if ($serviceName) {
$serviceType = $this->resolveFromServiceName($serviceName, $serviceMap);
if (!$serviceType instanceof \PHPStan\Type\MixedType) {
return $serviceType;
}
$serviceName = $this->resolveServiceName($doctrineAnnotationTagValueNode, $property);
$serviceType = $this->resolveFromServiceName($serviceName, $serviceMap);
if (!$serviceType instanceof \PHPStan\Type\MixedType) {
return $serviceType;
}
// 3. service is in @var annotation
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
@ -96,4 +94,16 @@ final class JMSDITypeResolver
}
return new \PHPStan\Type\MixedType();
}
private function resolveServiceName(\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, \PhpParser\Node\Stmt\Property $property) : string
{
$serviceNameParameter = $doctrineAnnotationTagValueNode->getValueWithoutQuotes('serviceName');
if (\is_string($serviceNameParameter)) {
return $serviceNameParameter;
}
$silentValue = $doctrineAnnotationTagValueNode->getSilentValue();
if (\is_string($silentValue)) {
return $silentValue;
}
return $this->nodeNameResolver->getName($property);
}
}

View File

@ -31,7 +31,7 @@ final class ServiceMapFactory
$fileContents = $this->smartFileSystem->readFile($configFilePath);
// "@" intentionally
$xml = @\simplexml_load_string($fileContents);
if (!$xml) {
if ($xml === \false) {
throw new \Rector\Symfony\Exception\XmlContainerNotExistsException(\sprintf('Container "%s" cannot be parsed', $configFilePath));
}
/** @var ServiceDefinition[] $services */

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211129\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitffe715fe221b8fc7fa75381e210607f6', false) && !interface_exists('ComposerAutoloaderInitffe715fe221b8fc7fa75381e210607f6', false) && !trait_exists('ComposerAutoloaderInitffe715fe221b8fc7fa75381e210607f6', false)) {
spl_autoload_call('RectorPrefix20211129\ComposerAutoloaderInitffe715fe221b8fc7fa75381e210607f6');
if (!class_exists('ComposerAutoloaderInit9a0804c2fa2b16f124e30b25ead868d5', false) && !interface_exists('ComposerAutoloaderInit9a0804c2fa2b16f124e30b25ead868d5', false) && !trait_exists('ComposerAutoloaderInit9a0804c2fa2b16f124e30b25ead868d5', false)) {
spl_autoload_call('RectorPrefix20211129\ComposerAutoloaderInit9a0804c2fa2b16f124e30b25ead868d5');
}
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('RectorPrefix20211129\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211129\print_node(...func_get_args());
}
}
if (!function_exists('composerRequireffe715fe221b8fc7fa75381e210607f6')) {
function composerRequireffe715fe221b8fc7fa75381e210607f6() {
return \RectorPrefix20211129\composerRequireffe715fe221b8fc7fa75381e210607f6(...func_get_args());
if (!function_exists('composerRequire9a0804c2fa2b16f124e30b25ead868d5')) {
function composerRequire9a0804c2fa2b16f124e30b25ead868d5() {
return \RectorPrefix20211129\composerRequire9a0804c2fa2b16f124e30b25ead868d5(...func_get_args());
}
}
if (!function_exists('scanPath')) {