mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 11:50:51 +00:00
Updated Rector to commit 5f915d861b
5f915d861b
handle cases where strlen arg is a Stringable object (#981)
This commit is contained in:
parent
c6a9b6bdf0
commit
dbec2c82cd
|
@ -10,6 +10,8 @@ use PhpParser\Node\Expr\BinaryOp\Identical;
|
|||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
||||
use PhpParser\Node\Expr\BinaryOp\Equal;
|
||||
use PHPStan\Type\StringType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -31,7 +33,7 @@ final class StrlenZeroToIdenticalEmptyStringRector extends \Rector\Core\Rector\A
|
|||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes strlen comparison to 0 to direct empty string compare', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($value)
|
||||
public function run(string $value)
|
||||
{
|
||||
$empty = strlen($value) === 0;
|
||||
}
|
||||
|
@ -40,7 +42,7 @@ CODE_SAMPLE
|
|||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($value)
|
||||
public function run(string $value)
|
||||
{
|
||||
$empty = $value === '';
|
||||
}
|
||||
|
@ -61,19 +63,19 @@ CODE_SAMPLE
|
|||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($node->left instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
return $this->processLeftIdentical($node, $node->left);
|
||||
return $this->processIdentical($node->right, $node->left);
|
||||
}
|
||||
if ($node->right instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
return $this->processRightIdentical($node, $node->right);
|
||||
return $this->processIdentical($node->left, $node->right);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function processLeftIdentical(\PhpParser\Node\Expr\BinaryOp\Identical $identical, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\BinaryOp\Identical
|
||||
private function processIdentical(\PhpParser\Node\Expr $value, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\BinaryOp\Identical
|
||||
{
|
||||
if (!$this->isName($funcCall, 'strlen')) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->valueResolver->isValue($identical->right, 0)) {
|
||||
if (!$this->valueResolver->isValue($value, 0)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
|
||||
|
@ -83,23 +85,12 @@ CODE_SAMPLE
|
|||
$firstArg = $funcCall->args[0];
|
||||
/** @var Expr $variable */
|
||||
$variable = $firstArg->value;
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical($variable, new \PhpParser\Node\Scalar\String_(''));
|
||||
}
|
||||
private function processRightIdentical(\PhpParser\Node\Expr\BinaryOp\Identical $identical, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\BinaryOp\Identical
|
||||
{
|
||||
if (!$this->isName($funcCall, 'strlen')) {
|
||||
return null;
|
||||
// Needs string cast if variable type is not string
|
||||
// see https://github.com/rectorphp/rector/issues/6700
|
||||
$isStringType = $this->nodeTypeResolver->getNativeType($variable) instanceof \PHPStan\Type\StringType;
|
||||
if (!$isStringType) {
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical(new \PhpParser\Node\Expr\Cast\String_($variable), new \PhpParser\Node\Scalar\String_(''));
|
||||
}
|
||||
if (!$this->valueResolver->isValue($identical->left, 0)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg $firstArg */
|
||||
$firstArg = $funcCall->args[0];
|
||||
/** @var Expr $variable */
|
||||
$variable = $firstArg->value;
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical($variable, new \PhpParser\Node\Scalar\String_(''));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '65c3a44c638f203cb2c10affa6dcc70af920e6f8';
|
||||
public const PACKAGE_VERSION = '5f915d861b2a48043d8783568f4b825560b0a00b';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-10-11 08:31:02';
|
||||
public const RELEASE_DATE = '2021-10-12 06:08:52';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211011\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4::getLoader();
|
||||
return ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f::getLoader();
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4
|
||||
class ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f', '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\ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit86b67970e057798250bb7d712a4d5e0f::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit86b67970e057798250bb7d712a4d5e0f::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirebd7b4ae0bb0524bad8e1548e61ab79c4($fileIdentifier, $file);
|
||||
composerRequire86b67970e057798250bb7d712a4d5e0f($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequirebd7b4ae0bb0524bad8e1548e61ab79c4($fileIdentifier, $file)
|
||||
function composerRequire86b67970e057798250bb7d712a4d5e0f($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4
|
||||
class ComposerStaticInit86b67970e057798250bb7d712a4d5e0f
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3896,9 +3896,9 @@ class ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitbd7b4ae0bb0524bad8e1548e61ab79c4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit86b67970e057798250bb7d712a4d5e0f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit86b67970e057798250bb7d712a4d5e0f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit86b67970e057798250bb7d712a4d5e0f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -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('RectorPrefix20211011\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4', false) && !interface_exists('ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4', false) && !trait_exists('ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4', false)) {
|
||||
spl_autoload_call('RectorPrefix20211011\ComposerAutoloaderInitbd7b4ae0bb0524bad8e1548e61ab79c4');
|
||||
if (!class_exists('ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f', false) && !interface_exists('ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f', false) && !trait_exists('ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f', false)) {
|
||||
spl_autoload_call('RectorPrefix20211011\ComposerAutoloaderInit86b67970e057798250bb7d712a4d5e0f');
|
||||
}
|
||||
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('RectorPrefix20211011\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20211011\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequirebd7b4ae0bb0524bad8e1548e61ab79c4')) {
|
||||
function composerRequirebd7b4ae0bb0524bad8e1548e61ab79c4() {
|
||||
return \RectorPrefix20211011\composerRequirebd7b4ae0bb0524bad8e1548e61ab79c4(...func_get_args());
|
||||
if (!function_exists('composerRequire86b67970e057798250bb7d712a4d5e0f')) {
|
||||
function composerRequire86b67970e057798250bb7d712a4d5e0f() {
|
||||
return \RectorPrefix20211011\composerRequire86b67970e057798250bb7d712a4d5e0f(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user