diff --git a/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php b/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php index 51bb585a8f2..b4a27c22c02 100644 --- a/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php +++ b/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php @@ -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>> + */ + 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); diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 34e5cd68039..ee40a936998 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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__); diff --git a/vendor/autoload.php b/vendor/autoload.php index 6ae4f7aed32..d050600be40 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitc0940edcc096f9a0fc9ec343fad367a4::getLoader(); +return ComposerAutoloaderInit70647b4bafeb9da8b562589fb44171f1::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 1e6310ab15a..37ef6c81a99 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 8882f24f2b6..d85bae252aa 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 02ee6b12001..a48f7155b75 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -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')) {