Updated Rector to commit e380cf8fdb65fe9929ed047dafdd49fadb00e01c

e380cf8fdb [DX] Make MoneyFormatToNumberFormatRector wrap func call directly to keep simple (#4653)
This commit is contained in:
Tomas Votruba 2023-08-04 17:46:10 +00:00
parent 92b9fdfd95
commit 1814d573d8
13 changed files with 46 additions and 82 deletions

View File

@ -21,6 +21,9 @@ use Rector\Naming\Contract\AssignVariableNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
use RectorPrefix202308\Symfony\Component\String\UnicodeString;
/**
* @api used in downgrade
*/
final class VariableNaming
{
/**
@ -43,6 +46,9 @@ final class VariableNaming
$this->nodeTypeResolver = $nodeTypeResolver;
$this->assignVariableNameResolvers = [$propertyFetchAssignVariableNameResolver, $newAssignVariableNameResolver];
}
/**
* @api used in downgrade
*/
public function createCountedValueName(string $valueName, ?Scope $scope) : string
{
if (!$scope instanceof Scope) {

View File

@ -6,21 +6,14 @@ namespace Rector\Php74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Naming\VariableNaming;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -29,22 +22,16 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*
* @see \Rector\Tests\Php74\Rector\FuncCall\MoneyFormatToNumberFormatRector\MoneyFormatToNumberFormatRectorTest
*/
final class MoneyFormatToNumberFormatRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
final class MoneyFormatToNumberFormatRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
/**
* @readonly
* @var \Rector\Naming\Naming\VariableNaming
*/
private $variableNaming;
public function __construct(ArgsAnalyzer $argsAnalyzer, VariableNaming $variableNaming)
public function __construct(ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
$this->variableNaming = $variableNaming;
}
public function provideMinPhpVersion() : int
{
@ -56,8 +43,7 @@ final class MoneyFormatToNumberFormatRector extends AbstractScopeAwareRector imp
$value = money_format('%i', $value);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$roundedValue = round($value, 2, PHP_ROUND_HALF_ODD);
$value = number_format($roundedValue, 2, '.', '');
$value = number_format(round($value, 2, PHP_ROUND_HALF_ODD), 2, '.', '');
CODE_SAMPLE
)]);
}
@ -66,25 +52,20 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [Expression::class, Return_::class];
return [FuncCall::class];
}
/**
* @param Expression|Return_ $node
* @return Stmt[]|null
* @param FuncCall $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?array
public function refactor(Node $node) : ?FuncCall
{
$funcCall = $this->matchFunCall($node);
if (!$funcCall instanceof FuncCall) {
if (!$this->isName($node, 'money_format')) {
return null;
}
if (!$this->isName($funcCall, 'money_format')) {
if ($node->isFirstClassCallable()) {
return null;
}
if ($funcCall->isFirstClassCallable()) {
return null;
}
$args = $funcCall->getArgs();
$args = $node->getArgs();
if ($this->argsAnalyzer->hasNamedArg($args)) {
return null;
}
@ -92,36 +73,13 @@ CODE_SAMPLE
if (!$this->valueResolver->isValue($formatValue, '%i')) {
return null;
}
return $this->resolveNumberFormat($funcCall, $args[1]->value, $scope, $node);
return $this->warpInNumberFormatFuncCall($node, $args[1]->value);
}
/**
* @return Stmt[]
* @param \PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $stmt
*/
private function resolveNumberFormat(FuncCall $funcCall, Expr $expr, Scope $scope, $stmt) : array
private function warpInNumberFormatFuncCall(FuncCall $funcCall, Expr $expr) : FuncCall
{
$newValue = $this->nodeFactory->createFuncCall('round', [$expr, new LNumber(2), new ConstFetch(new Name('PHP_ROUND_HALF_ODD'))]);
$countedVariableName = $this->variableNaming->createCountedValueName('roundedValue', $scope);
$variable = new Variable($countedVariableName);
$roundFuncCall = $this->nodeFactory->createFuncCall('round', [$expr, new LNumber(2), new ConstFetch(new Name('PHP_ROUND_HALF_ODD'))]);
$funcCall->name = new Name('number_format');
$funcCall->args = [new Arg($variable), new Arg(new LNumber(2)), new Arg(new String_('.')), new Arg(new String_(''))];
return [new Expression(new Assign($variable, $newValue)), $stmt];
}
/**
* @param \PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $node
*/
private function matchFunCall($node) : ?\PhpParser\Node\Expr\FuncCall
{
if ($node->expr instanceof Assign) {
$assign = $node->expr;
if ($assign->expr instanceof FuncCall) {
return $assign->expr;
}
return null;
}
if ($node->expr instanceof FuncCall) {
return $node->expr;
}
return null;
$funcCall->args = [new Arg($roundFuncCall), new Arg(new LNumber(2)), new Arg(new String_('.')), new Arg(new String_(''))];
return $funcCall;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'fbcd7cf7e6c61be3ad014eebe50ff6c83e8a202e';
public const PACKAGE_VERSION = 'e380cf8fdb65fe9929ed047dafdd49fadb00e01c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-04 18:25:09';
public const RELEASE_DATE = '2023-08-04 17:41:55';
/**
* @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 ComposerAutoloaderInit26dd2f7c4e74ebe7862da0decf799cb6::getLoader();
return ComposerAutoloaderInit15f3e70791108ba750c465057c7145d0::getLoader();

View File

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

View File

@ -1986,12 +1986,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "1f3414a9b5434e1371f351bd4354b8719a5e4d0c"
"reference": "254b63f1f03de37ebe347b2399ae416f8465d82d"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/1f3414a9b5434e1371f351bd4354b8719a5e4d0c",
"reference": "1f3414a9b5434e1371f351bd4354b8719a5e4d0c",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/254b63f1f03de37ebe347b2399ae416f8465d82d",
"reference": "254b63f1f03de37ebe347b2399ae416f8465d82d",
"shasum": ""
},
"require": {
@ -2017,7 +2017,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-08-04T17:18:50+00:00",
"time": "2023-08-04T17:27:37+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 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'));
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 254b63f'), '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

@ -45,9 +45,9 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : Ternary
{
$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);
$nullsafeVariable = $this->createNullsafeVariable();
$methodCallOrPropertyFetch = $node instanceof NullsafeMethodCall ? new MethodCall($nullsafeVariable, $node->name, $node->getArgs()) : new PropertyFetch($nullsafeVariable, $node->name);
$assign = new Assign($nullsafeVariable, $node->var);
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
}
private function createNullsafeVariable() : Variable

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 && (($nullsafeVariable10 = $targetDefinition) ? $nullsafeVariable10->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 && (($nullsafeVariable3 = $targetDefinition) ? $nullsafeVariable3->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 || (($nullsafeVariable11 = $targetDefinition) ? $nullsafeVariable11->isLazy() : null), \true);
$this->graph->connect('.internal.reference_in_expression', null, $targetId, $targetDefinition, $value, $this->lazy || (($nullsafeVariable4 = $targetDefinition) ? $nullsafeVariable4->isLazy() : null), \true);
}
return $value;
}

View File

@ -71,7 +71,7 @@ class DecoratorServicePass extends AbstractRecursivePass
} else {
throw new ServiceNotFoundException($inner, $id);
}
if (($nullsafeVariable3 = $decoratedDefinition) ? $nullsafeVariable3->isSynthetic() : null) {
if (($nullsafeVariable10 = $decoratedDefinition) ? $nullsafeVariable10->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 (($nullsafeVariable4 = $this->definitionVariables) ? $nullsafeVariable4->contains($value) : null) {
if (($nullsafeVariable11 = $this->definitionVariables) ? $nullsafeVariable11->contains($value) : null) {
return $this->dumpValue($this->definitionVariables[$value], $interpolate);
}
if ($value->getMethodCalls()) {