Updated Rector to commit 1dc94831c504b3f99936f12d140401aeb10835d2

704b1bec11 [DowngradePhp80] Add DowngradeNumberFormatNoFourthArgRector 37e2e84500 [ci-review] Rector Rectify c6f84fa033 [ci-review] Rector Rectify 31b5cbf4b2 skip named arg 490dbb6365 skip different func call 05854d69d0 skip has fourth arg d7bf81e064 skip no third arg 8f18542a00 add failing test case 7df7bcae20 implemented 7702d5df1f register efcd01a961 phpstan 6f7b8a2788 phpstan d54672face phpstan 2fd995c396 [ci-review] Rector Rectify 3c2abcb79d [ci-review] Rector Rectify 2b16ac9761 phpstan 58f3574328 phpstan 620d2b3125 [ci-review] Rector Rectify ec364cbd03 [ci-review] Rector Rectify 0355abcde2 rectify fix 1dc94831c5 Merge pull request #1649 from rectorphp/downgrade-php80-numberformat
This commit is contained in:
Tomas Votruba 2022-01-08 17:02:43 +00:00
parent d60e53c3ca
commit d799d58c0e
10 changed files with 123 additions and 20 deletions

View File

@ -17,6 +17,7 @@ use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRe
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrEndsWithRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrStartsWithRector;
@ -73,4 +74,5 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionPropertyGetDefaultValueRector::class);
$services->set(\Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionClassGetConstantsFilterRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector::class);
};

View File

@ -0,0 +1,86 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp80\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use ReflectionFunction;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://www.php.net/manual/en/function.number-format.php#refsect1-function.number-format-changelog
*
* @see Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector\DowngradeNumberFormatNoFourthArgRectorTest
*/
final class DowngradeNumberFormatNoFourthArgRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Downgrade number_format arg to fill 4th arg when only 3rd arg filled', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
return number_format(1000, 2, ',');
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
return number_format(1000, 2, ',', ',');
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkip($node)) {
return null;
}
$reflectionFunction = new \ReflectionFunction('number_format');
$node->args[3] = new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\String_($reflectionFunction->getParameters()[3]->getDefaultValue()));
return $node;
}
private function shouldSkip(\PhpParser\Node\Expr\FuncCall $funcCall) : bool
{
if (!$this->nodeNameResolver->isName($funcCall, 'number_format')) {
return \true;
}
$args = $funcCall->getArgs();
if ($this->argsAnalyzer->hasNamedArg($args)) {
return \true;
}
if (isset($args[3])) {
return \true;
}
return !isset($args[2]);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '1f7170df9efc5c67107e7b9cd4b4c4e692c198c4';
public const PACKAGE_VERSION = '1dc94831c504b3f99936f12d140401aeb10835d2';
/**
* @var string
*/
public const RELEASE_DATE = '2022-01-08 07:22:39';
public const RELEASE_DATE = '2022-01-08 17:56:30';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220108\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Core\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Identifier;
use PhpParser\Node\VariadicPlaceholder;
final class ArgsAnalyzer
{
@ -34,4 +35,16 @@ final class ArgsAnalyzer
}
return \true;
}
/**
* @param Arg[] $args
*/
public function hasNamedArg(array $args) : bool
{
foreach ($args as $arg) {
if ($arg->name instanceof \PhpParser\Node\Identifier) {
return \true;
}
}
return \false;
}
}

View File

@ -222,7 +222,7 @@ final class BetterNodeFinder
}
/**
* @param mixed[]|\PhpParser\Node $nodes
* @param callable(Node $node): bool $filter
* @param callable(Node $filter): bool $filter
*/
public function findFirst($nodes, callable $filter) : ?\PhpParser\Node
{

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6::getLoader();
return ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c::getLoader();

View File

@ -2033,6 +2033,7 @@ return array(
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeMatchToSwitchRector' => $baseDir . '/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeThrowExprRector' => $baseDir . '/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeArrayFilterNullableCallbackRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeNumberFormatNoFourthArgRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeNumberFormatNoFourthArgRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrContainsRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrEndsWithRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrStartsWithRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6
class ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c', '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\ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInita7a8411bdece195aa5569e989a707d6c::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6::$files;
$includeFiles = Composer\Autoload\ComposerStaticInita7a8411bdece195aa5569e989a707d6c::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirefd77a297439f825b1bab95e0fa014bb6($fileIdentifier, $file);
composerRequirea7a8411bdece195aa5569e989a707d6c($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6
* @param string $file
* @return void
*/
function composerRequirefd77a297439f825b1bab95e0fa014bb6($fileIdentifier, $file)
function composerRequirea7a8411bdece195aa5569e989a707d6c($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 ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6
class ComposerStaticInita7a8411bdece195aa5569e989a707d6c
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2428,6 +2428,7 @@ class ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeMatchToSwitchRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeThrowExprRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeArrayFilterNullableCallbackRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeNumberFormatNoFourthArgRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeNumberFormatNoFourthArgRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrContainsRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrEndsWithRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeStrStartsWithRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php',
@ -3852,9 +3853,9 @@ class ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfd77a297439f825b1bab95e0fa014bb6::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInita7a8411bdece195aa5569e989a707d6c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita7a8411bdece195aa5569e989a707d6c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita7a8411bdece195aa5569e989a707d6c::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220108\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6', false) && !interface_exists('ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6', false) && !trait_exists('ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6', false)) {
spl_autoload_call('RectorPrefix20220108\ComposerAutoloaderInitfd77a297439f825b1bab95e0fa014bb6');
if (!class_exists('ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c', false) && !interface_exists('ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c', false) && !trait_exists('ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c', false)) {
spl_autoload_call('RectorPrefix20220108\ComposerAutoloaderInita7a8411bdece195aa5569e989a707d6c');
}
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('RectorPrefix20220108\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220108\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirefd77a297439f825b1bab95e0fa014bb6')) {
function composerRequirefd77a297439f825b1bab95e0fa014bb6() {
return \RectorPrefix20220108\composerRequirefd77a297439f825b1bab95e0fa014bb6(...func_get_args());
if (!function_exists('composerRequirea7a8411bdece195aa5569e989a707d6c')) {
function composerRequirea7a8411bdece195aa5569e989a707d6c() {
return \RectorPrefix20220108\composerRequirea7a8411bdece195aa5569e989a707d6c(...func_get_args());
}
}
if (!function_exists('scanPath')) {