mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-10 13:12:23 +00:00
Updated Rector to commit da3eb400a7a88c180869590fc6cbbcf0ba30ce11
da3eb400a7
[CodingStyle] Make EncapsedStringsToSprintfRector work with two string concat (#3515)
This commit is contained in:
parent
0b3c5d9bcc
commit
4218f60ee4
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\CodingStyle\Rector\Encapsed;
|
||||
|
||||
use RectorPrefix202303\Nette\Utils\Strings;
|
||||
use const PHP_EOL;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
|
@ -40,23 +39,11 @@ final class EncapsedStringsToSprintfRector extends AbstractRector
|
|||
private $argumentVariables = [];
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert enscaped {$string} to more readable sprintf', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(string $format)
|
||||
{
|
||||
return "Unsupported format {$format}";
|
||||
}
|
||||
}
|
||||
return new RuleDefinition('Convert enscaped {$string} to more readable sprintf or concat, if no mask is used', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
echo "Unsupported format {$format}";
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(string $format)
|
||||
{
|
||||
return sprintf('Unsupported format %s', $format);
|
||||
}
|
||||
}
|
||||
echo sprintf('Unsupported format %s', $format);
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
|
@ -129,37 +116,25 @@ CODE_SAMPLE
|
|||
}
|
||||
/**
|
||||
* @param Expr[] $argumentVariables
|
||||
* @return Concat|FuncCall|null
|
||||
* @return \PhpParser\Node\Expr\BinaryOp\Concat|\PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr|null
|
||||
*/
|
||||
private function createSprintfFuncCallOrConcat(string $string, array $argumentVariables) : ?Node
|
||||
private function createSprintfFuncCallOrConcat(string $mask, array $argumentVariables)
|
||||
{
|
||||
// special case for variable with PHP_EOL
|
||||
if ($string === '%s%s' && \count($argumentVariables) === 2 && $this->hasEndOfLine($argumentVariables)) {
|
||||
return new Concat($argumentVariables[0], $argumentVariables[1]);
|
||||
$bareMask = \str_repeat('%s', \count($argumentVariables));
|
||||
if ($mask === $bareMask) {
|
||||
if (\count($argumentVariables) === 1) {
|
||||
return $argumentVariables[0];
|
||||
}
|
||||
return $this->nodeFactory->createConcat($argumentVariables);
|
||||
}
|
||||
// checks for windows or linux line ending. \n is contained in both.
|
||||
if (\strpos($string, "\n") !== \false) {
|
||||
if (\strpos($mask, "\n") !== \false) {
|
||||
return null;
|
||||
}
|
||||
$arguments = [new Arg(new String_($string))];
|
||||
$arguments = [new Arg(new String_($mask))];
|
||||
foreach ($argumentVariables as $argumentVariable) {
|
||||
$arguments[] = new Arg($argumentVariable);
|
||||
}
|
||||
return new FuncCall(new Name('sprintf'), $arguments);
|
||||
}
|
||||
/**
|
||||
* @param Expr[] $argumentVariables
|
||||
*/
|
||||
private function hasEndOfLine(array $argumentVariables) : bool
|
||||
{
|
||||
foreach ($argumentVariables as $argumentVariable) {
|
||||
if (!$argumentVariable instanceof ConstFetch) {
|
||||
continue;
|
||||
}
|
||||
if ($this->isName($argumentVariable, 'PHP_EOL')) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f22ddc8f18ef345d5e9c99cbb667548c3c854d7d';
|
||||
public const PACKAGE_VERSION = 'da3eb400a7a88c180869590fc6cbbcf0ba30ce11';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-03-23 23:17:30';
|
||||
public const RELEASE_DATE = '2023-03-24 08:04:18';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit5a1aa4330716dc9c0330e52835fcb82b::getLoader();
|
||||
return ComposerAutoloaderInitcfc64ce27cb9dee1ff74afed2cee5d57::getLoader();
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit5a1aa4330716dc9c0330e52835fcb82b
|
||||
class ComposerAutoloaderInitcfc64ce27cb9dee1ff74afed2cee5d57
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5a1aa4330716dc9c0330e52835fcb82b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5a1aa4330716dc9c0330e52835fcb82b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcfc64ce27cb9dee1ff74afed2cee5d57', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5a1aa4330716dc9c0330e52835fcb82b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcfc64ce27cb9dee1ff74afed2cee5d57', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b
|
||||
class ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3127,9 +3127,9 @@ class ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5a1aa4330716dc9c0330e52835fcb82b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcfc64ce27cb9dee1ff74afed2cee5d57::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user