Updated Rector to commit 0d7e293404176c8bd305644a02482ba5116d224e

0d7e293404 [CodingStyle] Handle Non-string specifier for EncapsedStringsToSprintfRector (#622)
This commit is contained in:
Tomas Votruba 2021-08-08 17:03:07 +00:00
parent 1567f66690
commit 990fd729ae
6 changed files with 36 additions and 20 deletions

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Name;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\EncapsedStringPart;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\Type;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -25,6 +26,10 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class EncapsedStringsToSprintfRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var array<string, array<class-string<Type>>>
*/
private const FORMAT_SPECIFIERS = ['%s' => ['PHPStan\\Type\\StringType'], '%d' => ['PHPStan\\Type\\Constant\\ConstantIntegerType', 'PHPStan\\Type\\IntegerRangeType', 'PHPStan\\Type\\IntegerType']];
/**
* @var string
*/
@ -90,7 +95,18 @@ CODE_SAMPLE
}
private function collectExpr(\PhpParser\Node\Expr $expr) : void
{
$this->sprintfFormat .= '%s';
$type = $this->nodeTypeResolver->resolve($expr);
$found = \false;
foreach (self::FORMAT_SPECIFIERS as $key => $types) {
if (\in_array(\get_class($type), $types, \true)) {
$this->sprintfFormat .= $key;
$found = \true;
break;
}
}
if (!$found) {
$this->sprintfFormat .= '%s';
}
// remove: ${wrap} → $wrap
if ($expr instanceof \PhpParser\Node\Expr\Variable) {
$expr->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null);

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'a71fbfab1445899040cb34f30abdc1ffc0d2ebb3';
public const PACKAGE_VERSION = '0d7e293404176c8bd305644a02482ba5116d224e';
/**
* @var string
*/
public const RELEASE_DATE = '2021-08-08 18:48:23';
public const RELEASE_DATE = '2021-08-08 18:52:26';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210808\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 ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4::getLoader();
return ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1::getLoader();

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitc0940edcc096f9a0fc9ec343fad367a4
class ComposerStaticInit70647b4bafeb9da8b562589fb44171f1
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3847,9 +3847,9 @@ class ComposerStaticInitc0940edcc096f9a0fc9ec343fad367a4
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc0940edcc096f9a0fc9ec343fad367a4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc0940edcc096f9a0fc9ec343fad367a4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc0940edcc096f9a0fc9ec343fad367a4::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit70647b4bafeb9da8b562589fb44171f1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit70647b4bafeb9da8b562589fb44171f1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit70647b4bafeb9da8b562589fb44171f1::$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('RectorPrefix20210808\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4', false) && !interface_exists('ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4', false) && !trait_exists('ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4', false)) {
spl_autoload_call('RectorPrefix20210808\ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4');
if (!class_exists('ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1', false) && !interface_exists('ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1', false) && !trait_exists('ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1', false)) {
spl_autoload_call('RectorPrefix20210808\ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1');
}
if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) {
spl_autoload_call('RectorPrefix20210808\AjaxLogin');
@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210808\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirec0940edcc096f9a0fc9ec343fad367a4')) {
function composerRequirec0940edcc096f9a0fc9ec343fad367a4() {
return \RectorPrefix20210808\composerRequirec0940edcc096f9a0fc9ec343fad367a4(...func_get_args());
if (!function_exists('composerRequire70647b4bafeb9da8b562589fb44171f1')) {
function composerRequire70647b4bafeb9da8b562589fb44171f1() {
return \RectorPrefix20210808\composerRequire70647b4bafeb9da8b562589fb44171f1(...func_get_args());
}
}
if (!function_exists('parseArgs')) {