mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-10 13:12:23 +00:00
Updated Rector to commit 6f164da439
6f164da439
[Php55] Handle crash on concat variable single quote on PregReplaceEModifierRector (#2483)
This commit is contained in:
parent
a1d7c79c1b
commit
446e9f7d20
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
/** @var Arg $secondArgument */
|
||||
$secondArgument = $node->args[1];
|
||||
$secondArgumentValue = $secondArgument->value;
|
||||
$anonymousFunction = $this->anonymousFunctionFactory->createAnonymousFunctionFromString($secondArgumentValue);
|
||||
$anonymousFunction = $this->anonymousFunctionFactory->createAnonymousFunctionFromExpr($secondArgumentValue);
|
||||
if (!$anonymousFunction instanceof Closure) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ use PHPStan\Type\MixedType;
|
|||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Core\PhpParser\Parser\InlineCodeParser;
|
||||
use Rector\Core\PhpParser\Parser\SimplePhpParser;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
@ -108,7 +108,12 @@ final class AnonymousFunctionFactory
|
|||
* @var \Symplify\PackageBuilder\Reflection\PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, NodeFactory $nodeFactory, StaticTypeMapper $staticTypeMapper, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, NodeComparator $nodeComparator, AstResolver $astResolver, NodePrinterInterface $nodePrinter, PrivatesAccessor $privatesAccessor)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Parser\InlineCodeParser
|
||||
*/
|
||||
private $inlineCodeParser;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, NodeFactory $nodeFactory, StaticTypeMapper $staticTypeMapper, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, NodeComparator $nodeComparator, AstResolver $astResolver, NodePrinterInterface $nodePrinter, PrivatesAccessor $privatesAccessor, InlineCodeParser $inlineCodeParser)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
|
@ -120,6 +125,7 @@ final class AnonymousFunctionFactory
|
|||
$this->astResolver = $astResolver;
|
||||
$this->nodePrinter = $nodePrinter;
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
$this->inlineCodeParser = $inlineCodeParser;
|
||||
}
|
||||
/**
|
||||
* @param Param[] $params
|
||||
|
@ -166,13 +172,10 @@ final class AnonymousFunctionFactory
|
|||
}
|
||||
return $anonymousFunction;
|
||||
}
|
||||
public function createAnonymousFunctionFromString(Expr $expr) : ?Closure
|
||||
public function createAnonymousFunctionFromExpr(Expr $expr) : ?Closure
|
||||
{
|
||||
if (!$expr instanceof String_) {
|
||||
// not supported yet
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
$phpCode = '<?php ' . $expr->value . ';';
|
||||
$stringValue = $this->inlineCodeParser->stringify($expr);
|
||||
$phpCode = '<?php ' . $stringValue . ';';
|
||||
$contentStmts = $this->simplePhpParser->parseString($phpCode);
|
||||
$anonymousFunction = new Closure();
|
||||
$firstNode = $contentStmts[0] ?? null;
|
||||
|
@ -193,6 +196,10 @@ final class AnonymousFunctionFactory
|
|||
});
|
||||
$anonymousFunction->stmts[] = new Return_($stmt);
|
||||
$anonymousFunction->params[] = new Param(new Variable('matches'));
|
||||
$variables = $expr instanceof Variable ? [] : $this->betterNodeFinder->findInstanceOf($expr, Variable::class);
|
||||
$anonymousFunction->uses = \array_map(function (Variable $variable) : ClosureUse {
|
||||
return new ClosureUse($variable);
|
||||
}, $variables);
|
||||
return $anonymousFunction;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '28ed5cf91639d0edf384fcf0d52ea02266b21657';
|
||||
public const PACKAGE_VERSION = '6f164da43933c1fa957b1cf62c23e4ceed4839f8';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-06-12 00:29:50';
|
||||
public const RELEASE_DATE = '2022-06-13 08:53:39';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,11 @@ final class InlineCodeParser
|
|||
* @see https://regex101.com/r/TUWwKw/1/
|
||||
*/
|
||||
private const ENDING_SEMI_COLON_REGEX = '#;(\\s+)?$#';
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/8fDjnR/1
|
||||
*/
|
||||
private const VARIABLE_IN_SINGLE_QUOTED_REGEX = '#\'(?<variable>\\$.*)\'#U';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Contract\PhpParser\NodePrinterInterface
|
||||
|
@ -91,7 +96,10 @@ final class InlineCodeParser
|
|||
return Strings::replace($expr, self::CURLY_BRACKET_WRAPPER_REGEX, '$1');
|
||||
}
|
||||
if ($expr instanceof Concat) {
|
||||
return $this->stringify($expr->left) . $this->stringify($expr->right);
|
||||
$string = $this->stringify($expr->left) . $this->stringify($expr->right);
|
||||
return Strings::replace($string, self::VARIABLE_IN_SINGLE_QUOTED_REGEX, function (array $match) {
|
||||
return $match['variable'];
|
||||
});
|
||||
}
|
||||
return $this->nodePrinter->print($expr);
|
||||
}
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe::getLoader();
|
||||
return ComposerAutoloaderIniteb03e77712ef13e2bcc24d638473397d::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 ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe
|
||||
class ComposerAutoloaderIniteb03e77712ef13e2bcc24d638473397d
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderIniteb03e77712ef13e2bcc24d638473397d', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderIniteb03e77712ef13e2bcc24d638473397d', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticIniteb03e77712ef13e2bcc24d638473397d::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticIniteb03e77712ef13e2bcc24d638473397d::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirece304557a03ed74efcfbea7c64bdecfe($fileIdentifier, $file);
|
||||
composerRequireeb03e77712ef13e2bcc24d638473397d($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitce304557a03ed74efcfbea7c64bdecfe
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequirece304557a03ed74efcfbea7c64bdecfe($fileIdentifier, $file)
|
||||
function composerRequireeb03e77712ef13e2bcc24d638473397d($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 ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe
|
||||
class ComposerStaticIniteb03e77712ef13e2bcc24d638473397d
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -3397,9 +3397,9 @@ class ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitce304557a03ed74efcfbea7c64bdecfe::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticIniteb03e77712ef13e2bcc24d638473397d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticIniteb03e77712ef13e2bcc24d638473397d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticIniteb03e77712ef13e2bcc24d638473397d::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user