Updated Rector to commit fbcd7cf7e6c61be3ad014eebe50ff6c83e8a202e

fbcd7cf7e6 Remove resolveFromNodeWithScopeCountAndFallbackName() as unused (#4652)
This commit is contained in:
Tomas Votruba 2023-08-04 17:28:42 +00:00
parent 81777836bc
commit 92b9fdfd95
20 changed files with 49 additions and 74 deletions

View File

@ -12,7 +12,7 @@ final class FixtureFileFinder
*/
public static function yieldDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
{
$finder = (new Finder())->in($directory)->files()->name($suffix);
$finder = (new Finder())->in($directory)->files()->name($suffix)->sortByName();
foreach ($finder as $fileInfo) {
(yield [$fileInfo->getRealPath()]);
}

View File

@ -163,14 +163,14 @@ final class ExpectedNameResolver
}
$expectedNameFromType = $this->propertyNaming->getExpectedNameFromType($innerReturnedType ?? $returnedType);
if ($this->isReturnedTypeAnArrayAndExpectedNameFromTypeNotNull($returnedType, $expectedNameFromType)) {
return ($expectedNameFromType2 = $expectedNameFromType) ? $expectedNameFromType2->getSingularized() : null;
return ($nullsafeVariable1 = $expectedNameFromType) ? $nullsafeVariable1->getSingularized() : null;
}
$expectedNameFromMethodName = $this->propertyNaming->getExpectedNameFromMethodName($name);
if (!$expectedNameFromMethodName instanceof ExpectedName) {
return ($expectedNameFromType2 = $expectedNameFromType) ? $expectedNameFromType2->getSingularized() : null;
return ($nullsafeVariable2 = $expectedNameFromType) ? $nullsafeVariable2->getSingularized() : null;
}
if ($expectedNameFromMethodName->isSingular()) {
return ($expectedNameFromType2 = $expectedNameFromType) ? $expectedNameFromType2->getSingularized() : null;
return ($nullsafeVariable3 = $expectedNameFromType) ? $nullsafeVariable3->getSingularized() : null;
}
return $expectedNameFromMethodName->getSingularized();
}

View File

@ -3,10 +3,8 @@
declare (strict_types=1);
namespace Rector\Naming\Naming;
use RectorPrefix202308\Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
@ -14,7 +12,6 @@ use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
@ -46,21 +43,6 @@ final class VariableNaming
$this->nodeTypeResolver = $nodeTypeResolver;
$this->assignVariableNameResolvers = [$propertyFetchAssignVariableNameResolver, $newAssignVariableNameResolver];
}
/**
* @api
*/
public function resolveFromNodeWithScopeCountAndFallbackName(Expr $expr, MutatingScope $mutatingScope, string $fallbackName) : string
{
$name = $this->resolveFromNode($expr);
if ($name === null) {
$name = $fallbackName;
}
if (\strpos($name, '\\') !== \false) {
$name = (string) Strings::after($name, '\\', -1);
}
$countedValueName = $this->createCountedValueName($name, $mutatingScope);
return \lcfirst($countedValueName);
}
public function createCountedValueName(string $valueName, ?Scope $scope) : string
{
if (!$scope instanceof Scope) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'cbc026e3245d744eea5cf1fc48f3722f67b62173';
public const PACKAGE_VERSION = 'fbcd7cf7e6c61be3ad014eebe50ff6c83e8a202e';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-04 17:11:09';
public const RELEASE_DATE = '2023-08-04 18:25:09';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb
class ComposerAutoloaderInit26dd2f7c4e74ebe7862da0decf799cb6
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit26dd2f7c4e74ebe7862da0decf799cb6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit26dd2f7c4e74ebe7862da0decf799cb6', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6::$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 ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb
class ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3015,9 +3015,9 @@ class ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit26dd2f7c4e74ebe7862da0decf799cb6::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1986,12 +1986,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "38b84484d36f29b93cb51ff0c4dceb7753b9fb18"
"reference": "1f3414a9b5434e1371f351bd4354b8719a5e4d0c"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/38b84484d36f29b93cb51ff0c4dceb7753b9fb18",
"reference": "38b84484d36f29b93cb51ff0c4dceb7753b9fb18",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/1f3414a9b5434e1371f351bd4354b8719a5e4d0c",
"reference": "1f3414a9b5434e1371f351bd4354b8719a5e4d0c",
"shasum": ""
},
"require": {
@ -2017,7 +2017,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-08-04T16:28:55+00:00",
"time": "2023-08-04T17:18:50+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

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-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 dbc34e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38b8448'), '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 0438162'), '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 a0af12a'));
public const EXTENSIONS = array('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 dbc34e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1f3414a'), '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 0438162'), '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 a0af12a'));
private function __construct()
{
}

View File

@ -11,35 +11,25 @@ use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Naming\Naming\VariableNaming;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\DowngradePhp80\Rector\NullsafeMethodCall\DowngradeNullsafeToTernaryOperatorRector\DowngradeNullsafeToTernaryOperatorRectorTest
*/
final class DowngradeNullsafeToTernaryOperatorRector extends AbstractScopeAwareRector
final class DowngradeNullsafeToTernaryOperatorRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Naming\Naming\VariableNaming
* @var int
*/
private $variableNaming;
public function __construct(VariableNaming $variableNaming)
{
$this->variableNaming = $variableNaming;
}
private $counter = 0;
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change nullsafe operator to ternary operator rector', [new CodeSample(<<<'CODE_SAMPLE'
$dateAsString = $booking->getStartDate()?->asDateTimeString();
$dateAsString = $booking->startDate?->dateTimeString;
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$dateAsString = ($bookingGetStartDate = $booking->getStartDate()) ? $bookingGetStartDate->asDateTimeString() : null;
$dateAsString = ($bookingGetStartDate = $booking->startDate) ? $bookingGetStartDate->dateTimeString : null;
CODE_SAMPLE
)]);
}
@ -53,13 +43,16 @@ CODE_SAMPLE
/**
* @param NullsafeMethodCall|NullsafePropertyFetch $node
*/
public function refactorWithScope(Node $node, Scope $scope) : Ternary
public function refactor(Node $node) : Ternary
{
/** @var MutatingScope $scope */
$tempVarName = $this->variableNaming->resolveFromNodeWithScopeCountAndFallbackName($node->var, $scope, '_');
$variable = new Variable($tempVarName);
$called = $node instanceof NullsafeMethodCall ? new MethodCall($variable, $node->name, $node->getArgs()) : new PropertyFetch($variable, $node->name);
$assign = new Assign($variable, $node->var);
return new Ternary($assign, $called, $this->nodeFactory->createNull());
$nullsafeVariableName = $this->createNullsafeVariable();
$methodCallOrPropertyFetch = $node instanceof NullsafeMethodCall ? new MethodCall($nullsafeVariableName, $node->name, $node->getArgs()) : new PropertyFetch($nullsafeVariableName, $node->name);
$assign = new Assign($nullsafeVariableName, $node->var);
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
}
private function createNullsafeVariable() : Variable
{
$nullsafeVariableName = 'nullsafeVariable' . ++$this->counter;
return new Variable($nullsafeVariableName);
}
}

View File

@ -76,7 +76,7 @@ final class Parser
$type = Line::REMOVED;
}
$diffLines[] = new Line($type, $match['line']);
($chunk2 = $chunk) ? $chunk2->setLines($diffLines) : null;
($nullsafeVariable4 = $chunk) ? $nullsafeVariable4->setLines($diffLines) : null;
}
}
$diff->setChunks($chunks);

View File

@ -48,7 +48,7 @@ class DefinitionFileLoader extends FileLoader
$loader = $this;
$path = $this->locator->locate($resource);
$this->setCurrentDir(\dirname($path));
($container = $this->container) ? $container->fileExists($path) : null;
($nullsafeVariable5 = $this->container) ? $nullsafeVariable5->fileExists($path) : null;
// the closure forbids access to the private scope in the included file
$load = \Closure::bind(static function ($file) use($loader) {
return include $file;

View File

@ -559,7 +559,7 @@ class Application implements ResetInterface
public function has(string $name) : bool
{
$this->init();
return isset($this->commands[$name]) || (($commandLoader = $this->commandLoader) ? $commandLoader->has($name) : null) && $this->add($this->commandLoader->get($name));
return isset($this->commands[$name]) || (($nullsafeVariable6 = $this->commandLoader) ? $nullsafeVariable6->has($name) : null) && $this->add($this->commandLoader->get($name));
}
/**
* Returns an array of all unique namespaces used by currently registered commands.

View File

@ -459,7 +459,7 @@ class Command
throw new \TypeError(\sprintf('Argument 5 passed to "%s()" must be array or \\Closure, "%s" given.', __METHOD__, \get_debug_type($suggestedValues)));
}
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues));
($fullDefinition = $this->fullDefinition) ? $fullDefinition->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues)) : null;
($nullsafeVariable7 = $this->fullDefinition) ? $nullsafeVariable7->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues)) : null;
return $this;
}
/**
@ -483,7 +483,7 @@ class Command
throw new \TypeError(\sprintf('Argument 5 passed to "%s()" must be array or \\Closure, "%s" given.', __METHOD__, \get_debug_type($suggestedValues)));
}
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues));
($fullDefinition = $this->fullDefinition) ? $fullDefinition->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues)) : null;
($nullsafeVariable8 = $this->fullDefinition) ? $nullsafeVariable8->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues)) : null;
return $this;
}
/**
@ -582,7 +582,7 @@ class Command
public function getProcessedHelp() : string
{
$name = $this->name;
$isSingleCommand = ($application = $this->application) ? $application->isSingleCommand() : null;
$isSingleCommand = ($nullsafeVariable9 = $this->application) ? $nullsafeVariable9->isSingleCommand() : null;
$placeholders = ['%command.name%', '%command.full_name%'];
$replacements = [$name, $isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'] . ' ' . $name];
return \str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());

View File

@ -69,7 +69,7 @@ final class CompletionInput extends ArgvInput
$this->completionValue = $relevantToken;
return;
}
if (($option2 = $option) ? $option2->acceptValue() : null) {
if (($nullsafeVariable1 = $option) ? $nullsafeVariable1->acceptValue() : null) {
$this->completionType = self::TYPE_OPTION_VALUE;
$this->completionName = $option->getName();
$this->completionValue = $optionValue ?: (\strncmp($optionToken, '--', \strlen('--')) !== 0 ? \substr($optionToken, 2) : '');
@ -80,7 +80,7 @@ final class CompletionInput extends ArgvInput
if ('-' === $previousToken[0] && '' !== \trim($previousToken, '-')) {
// check if previous option accepted a value
$previousOption = $this->getOptionFromToken($previousToken);
if (($previousOption2 = $previousOption) ? $previousOption2->acceptValue() : null) {
if (($nullsafeVariable2 = $previousOption) ? $nullsafeVariable2->acceptValue() : null) {
$this->completionType = self::TYPE_OPTION_VALUE;
$this->completionName = $previousOption->getName();
$this->completionValue = $relevantToken;

View File

@ -115,9 +115,9 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass
if ($value instanceof Reference) {
$targetId = $this->getDefinitionId((string) $value);
$targetDefinition = null !== $targetId ? $this->container->getDefinition($targetId) : null;
$this->graph->connect($this->currentId, $this->currentDefinition, $targetId, $targetDefinition, $value, $this->lazy || $this->hasProxyDumper && (($targetDefinition2 = $targetDefinition) ? $targetDefinition2->isLazy() : null), ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(), $this->byConstructor);
$this->graph->connect($this->currentId, $this->currentDefinition, $targetId, $targetDefinition, $value, $this->lazy || $this->hasProxyDumper && (($nullsafeVariable10 = $targetDefinition) ? $nullsafeVariable10->isLazy() : null), ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(), $this->byConstructor);
if ($inExpression) {
$this->graph->connect('.internal.reference_in_expression', null, $targetId, $targetDefinition, $value, $this->lazy || (($targetDefinition2 = $targetDefinition) ? $targetDefinition2->isLazy() : null), \true);
$this->graph->connect('.internal.reference_in_expression', null, $targetId, $targetDefinition, $value, $this->lazy || (($nullsafeVariable11 = $targetDefinition) ? $nullsafeVariable11->isLazy() : null), \true);
}
return $value;
}

View File

@ -71,7 +71,7 @@ class DecoratorServicePass extends AbstractRecursivePass
} else {
throw new ServiceNotFoundException($inner, $id);
}
if (($decoratedDefinition2 = $decoratedDefinition) ? $decoratedDefinition2->isSynthetic() : null) {
if (($nullsafeVariable3 = $decoratedDefinition) ? $nullsafeVariable3->isSynthetic() : null) {
throw new InvalidArgumentException(\sprintf('A synthetic service cannot be decorated: service "%s" cannot decorate "%s".', $id, $inner));
}
if (isset($decoratingDefinitions[$inner])) {

View File

@ -1635,7 +1635,7 @@ EOF;
if ($value->hasErrors() && ($e = $value->getErrors())) {
return \sprintf('throw new RuntimeException(%s)', $this->export(\reset($e)));
}
if (($definitionVariables = $this->definitionVariables) ? $definitionVariables->contains($value) : null) {
if (($nullsafeVariable4 = $this->definitionVariables) ? $nullsafeVariable4->contains($value) : null) {
return $this->dumpValue($this->definitionVariables[$value], $interpolate);
}
if ($value->getMethodCalls()) {

View File

@ -421,7 +421,7 @@ XX
$skip[$refId] = \true;
}
foreach ($val as $k => $v) {
$refId = ($fromArrayElement = \ReflectionReference::fromArrayElement($val, $k)) ? $fromArrayElement->getId() : null;
$refId = ($nullsafeVariable5 = \ReflectionReference::fromArrayElement($val, $k)) ? $nullsafeVariable5->getId() : null;
self::traverseValue($v, $callback, $skip, $refId);
}
}