Updated Rector to commit 9a322af593a3ed9de20a535f613ed25e12ecc823

9a322af593 BC: Separated regex matching in NodeNameResolver->isName() (#4951)
This commit is contained in:
Tomas Votruba 2023-09-09 14:08:25 +00:00
parent c77e927087
commit 7540a5e283
13 changed files with 44 additions and 43 deletions

View File

@ -40,10 +40,6 @@ final class NodeNameResolver
* @readonly
*/
private $nodeNameResolvers = [];
/**
* Used to check if a string might contain a regex or fnmatch pattern
*/
private const REGEX_WILDCARD_CHARS = ['*', '#', '~', '/'];
/**
* @var array<string, NodeNameResolverInterface|null>
*/
@ -191,25 +187,23 @@ final class NodeNameResolver
if ($desiredName === 'Object') {
return $desiredName === $resolvedName;
}
$containsWildcard = \false;
foreach (self::REGEX_WILDCARD_CHARS as $char) {
if (\strpos($desiredName, $char) !== \false) {
$containsWildcard = \true;
break;
}
}
if ($containsWildcard) {
// is probably regex pattern
if ($this->regexPatternDetector->isRegexPattern($desiredName)) {
return StringUtils::isMatch($resolvedName, $desiredName);
}
// is probably fnmatch
if (\strpos($desiredName, '*') !== \false) {
return \fnmatch($desiredName, $resolvedName, \FNM_NOESCAPE);
}
}
return \strtolower($resolvedName) === \strtolower($desiredName);
}
/**
* @param string|\PhpParser\Node\Identifier $resolvedName
*/
public function matchesStringName($resolvedName, string $desiredNamePattern) : bool
{
if ($resolvedName instanceof Identifier) {
$resolvedName = $resolvedName->toString();
}
// is probably regex pattern
if ($this->regexPatternDetector->isRegexPattern($desiredNamePattern)) {
return StringUtils::isMatch($resolvedName, $desiredNamePattern);
}
// is probably fnmatch
return \fnmatch($desiredNamePattern, $resolvedName, \FNM_NOESCAPE);
}
/**
* @param \PhpParser\Node\Expr|\PhpParser\Node\Identifier $node
*/

View File

@ -46,6 +46,6 @@ final class ControllerClassMethodManipulator
if (!$class->extends instanceof Name) {
return \false;
}
return $this->nodeNameResolver->isName($class->extends, '#(Controller|Presenter)$#');
return $this->nodeNameResolver->matchesStringName($class->extends->toString(), '#(Controller|Presenter)$#');
}
}

View File

@ -153,6 +153,9 @@ CODE_SAMPLE
if ($this->nodeNameResolver->isStringName($classLikeName, $classToSkip)) {
return \true;
}
if ($this->nodeNameResolver->matchesStringName($classLikeName, $classToSkip)) {
return \true;
}
}
return \false;
}

View File

@ -103,7 +103,7 @@ CODE_SAMPLE
}
private function shouldSkipClassMethod(ClassMethod $classMethod) : bool
{
if ($this->isName($classMethod, 'createComponent*')) {
if ($this->nodeNameResolver->matchesStringName($classMethod->name->toString(), 'createComponent*')) {
return \true;
}
return !$classMethod->isProtected();

View File

@ -132,7 +132,10 @@ CODE_SAMPLE
if ($this->transformOnNamespaces !== []) {
$className = (string) $this->nodeNameResolver->getName($class);
foreach ($this->transformOnNamespaces as $transformOnNamespace) {
if (!$this->nodeNameResolver->isStringName($className, $transformOnNamespace)) {
if ($this->nodeNameResolver->isStringName($className, $transformOnNamespace)) {
continue;
}
if (!$this->nodeNameResolver->matchesStringName($className, $transformOnNamespace)) {
return \true;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b82ad4ca58ebb42307093858a1c3dd60ecee13aa';
public const PACKAGE_VERSION = '9a322af593a3ed9de20a535f613ed25e12ecc823';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-09-09 15:55:50';
public const RELEASE_DATE = '2023-09-09 16:05:54';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite95c6c7d17839ce4d51f5550de0205a1::getLoader();
return ComposerAutoloaderInit2c4eb4dde5e28350050ca68006bbd2ae::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite95c6c7d17839ce4d51f5550de0205a1
class ComposerAutoloaderInit2c4eb4dde5e28350050ca68006bbd2ae
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInite95c6c7d17839ce4d51f5550de0205a1
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInite95c6c7d17839ce4d51f5550de0205a1', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit2c4eb4dde5e28350050ca68006bbd2ae', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite95c6c7d17839ce4d51f5550de0205a1', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit2c4eb4dde5e28350050ca68006bbd2ae', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1
class ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2599,9 +2599,9 @@ class ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite95c6c7d17839ce4d51f5550de0205a1::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2c4eb4dde5e28350050ca68006bbd2ae::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1943,12 +1943,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "647657345f0a4573ff8fccbfaf6dd666bdb3cff7"
"reference": "1a713897eb0998232c3182a1165c0f6f337ec32a"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/647657345f0a4573ff8fccbfaf6dd666bdb3cff7",
"reference": "647657345f0a4573ff8fccbfaf6dd666bdb3cff7",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/1a713897eb0998232c3182a1165c0f6f337ec32a",
"reference": "1a713897eb0998232c3182a1165c0f6f337ec32a",
"shasum": ""
},
"require": {
@ -1981,7 +1981,7 @@
"tomasvotruba\/unused-public": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2023-09-09T13:41:51+00:00",
"time": "2023-09-09T14:02:57+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main aecc9c7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main fa41cc7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 7b173b9'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 6476573'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main aecc9c7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main fa41cc7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 7b173b9'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 1a71389'));
private function __construct()
{
}

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\LNumber;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
@ -99,7 +100,7 @@ CODE_SAMPLE
}
private function processMethodCall(MethodCall $methodCall) : ?\PhpParser\Node\Expr\CallLike
{
if ($this->nodeNameResolver->matchesStringName($methodCall->name, 'assert*')) {
if ($methodCall->name instanceof Identifier && $this->nodeNameResolver->matchesStringName($methodCall->name, 'assert*')) {
return $this->processAssertMethodCall($methodCall);
}
if ($this->isName($methodCall->name, 'redirect')) {