Updated Rector to commit dd9ffc0bb174ef27169464008d16f300b782e157

dd9ffc0bb1 Fix in assign on DowngradePregUnmatchedAsNullConstantRector (#1873)
This commit is contained in:
Tomas Votruba 2022-02-26 05:06:29 +00:00
parent 598bce3f9d
commit 6f5f340b84
7 changed files with 28 additions and 48 deletions

View File

@ -5,7 +5,6 @@ namespace Rector\DowngradePhp72\Rector\FuncCall;
use RectorPrefix20220226\Nette\NotImplementedException;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
use PhpParser\Node\Expr\BinaryOp\Identical;
@ -13,7 +12,6 @@ use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\LNumber;
@ -99,9 +97,6 @@ final class DowngradePregUnmatchedAsNullConstantRector extends \Rector\Core\Rect
return null;
}
$node = $this->handleEmptyStringToNullMatch($node, $variable);
if ($node instanceof \PhpParser\Node\Expr\Ternary) {
return $node;
}
unset($node->args[3]);
return $node;
}
@ -146,10 +141,7 @@ CODE_SAMPLE
}
return null;
}
/**
* @return \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\Ternary
*/
private function handleEmptyStringToNullMatch(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\Variable $variable)
private function handleEmptyStringToNullMatch(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\Variable $variable) : \PhpParser\Node\Expr\FuncCall
{
$closure = new \PhpParser\Node\Expr\Closure();
$variablePass = new \PhpParser\Node\Expr\Variable('value');
@ -163,10 +155,7 @@ CODE_SAMPLE
$replaceEmptyStringToNull = $this->nodeFactory->createFuncCall('array_walk_recursive', $arguments);
return $this->processReplace($funcCall, $replaceEmptyStringToNull);
}
/**
* @return \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\Ternary
*/
private function processReplace(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\FuncCall $replaceEmptystringToNull)
private function processReplace(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\FuncCall $replaceEmptystringToNull) : \PhpParser\Node\Expr\FuncCall
{
$parent = $funcCall->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if ($parent instanceof \PhpParser\Node\Stmt\Expression) {
@ -194,16 +183,11 @@ CODE_SAMPLE
}
return $this->processInIf($if, $funcCall, $replaceEmptystringToNull);
}
private function processInAssign(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\FuncCall $replaceEmptyStringToNull) : \PhpParser\Node\Expr\Ternary
private function processInAssign(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\FuncCall $replaceEmptyStringToNull) : \PhpParser\Node\Expr\FuncCall
{
$matchesVariable = $funcCall->args[2]->value;
$identical = new \PhpParser\Node\Expr\BinaryOp\Identical($matchesVariable, new \PhpParser\Node\Expr\Array_([]));
$lNumber = new \PhpParser\Node\Scalar\LNumber(1);
$ternary = new \PhpParser\Node\Expr\Ternary($identical, $this->nodeFactory->createFalse(), $lNumber);
$currentStatement = $assign->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$expressions = [new \PhpParser\Node\Stmt\Expression($funcCall), new \PhpParser\Node\Stmt\Expression($replaceEmptyStringToNull)];
$this->nodesToAddCollector->addNodesBeforeNode($expressions, $currentStatement);
return $ternary;
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Expression($replaceEmptyStringToNull), $currentStatement);
return $funcCall;
}
private function processInIf(\PhpParser\Node\Stmt\If_ $if, \PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\FuncCall $replaceEmptyStringToNull) : \PhpParser\Node\Expr\FuncCall
{

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'f686cbac1cfba1808e8ce9fa9cc0b9c39e3ee079';
public const PACKAGE_VERSION = 'dd9ffc0bb174ef27169464008d16f300b782e157';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-26 04:16:57';
public const RELEASE_DATE = '2022-02-26 05:00:35';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220226\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e::getLoader();
return ComposerAutoloaderInit0f483e1582652742f7410a43002d7277::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e
class ComposerAutoloaderInit0f483e1582652742f7410a43002d7277
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0f483e1582652742f7410a43002d7277', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0f483e1582652742f7410a43002d7277', '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\ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit0f483e1582652742f7410a43002d7277::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit0f483e1582652742f7410a43002d7277::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire7cca083ac1fb6de172dd287644b40e7e($fileIdentifier, $file);
composerRequire0f483e1582652742f7410a43002d7277($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e
* @param string $file
* @return void
*/
function composerRequire7cca083ac1fb6de172dd287644b40e7e($fileIdentifier, $file)
function composerRequire0f483e1582652742f7410a43002d7277($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 ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e
class ComposerStaticInit0f483e1582652742f7410a43002d7277
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3848,9 +3848,9 @@ class ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit7cca083ac1fb6de172dd287644b40e7e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit0f483e1582652742f7410a43002d7277::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0f483e1582652742f7410a43002d7277::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0f483e1582652742f7410a43002d7277::$classMap;
}, null, ClassLoader::class);
}

View File

@ -27,13 +27,12 @@ class Preg
if (($flags & \PREG_OFFSET_CAPTURE) !== 0) {
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchWithOffsets() instead');
}
\preg_match($pattern, $subject, $matches, $flags, $offset);
$result = \preg_match($pattern, $subject, $matches, $flags, $offset);
\array_walk_recursive($matches, function (&$value) {
if ($value === '') {
$value = null;
}
});
$result = $matches === [] ? \false : 1;
if ($result === \false) {
throw \RectorPrefix20220226\Composer\Pcre\PcreException::fromFunction('preg_match', $pattern);
}
@ -51,13 +50,12 @@ class Preg
*/
public static function matchWithOffsets(string $pattern, string $subject, ?array &$matches, int $flags = 0, int $offset = 0) : int
{
\preg_match($pattern, $subject, $matches, $flags | \PREG_OFFSET_CAPTURE, $offset);
$result = \preg_match($pattern, $subject, $matches, $flags | \PREG_OFFSET_CAPTURE, $offset);
\array_walk_recursive($matches, function (&$value) {
if ($value === '') {
$value = null;
}
});
$result = $matches === [] ? \false : 1;
if ($result === \false) {
throw \RectorPrefix20220226\Composer\Pcre\PcreException::fromFunction('preg_match', $pattern);
}
@ -77,13 +75,12 @@ class Preg
if (($flags & \PREG_SET_ORDER) !== 0) {
throw new \InvalidArgumentException('PREG_SET_ORDER is not supported as it changes the type of $matches');
}
\preg_match_all($pattern, $subject, $matches, $flags, $offset);
$result = \preg_match_all($pattern, $subject, $matches, $flags, $offset);
\array_walk_recursive($matches, function (&$value) {
if ($value === '') {
$value = null;
}
});
$result = $matches === [] ? \false : 1;
if ($result === \false || $result === null) {
throw \RectorPrefix20220226\Composer\Pcre\PcreException::fromFunction('preg_match_all', $pattern);
}
@ -101,13 +98,12 @@ class Preg
*/
public static function matchAllWithOffsets(string $pattern, string $subject, ?array &$matches, int $flags = 0, int $offset = 0) : int
{
\preg_match_all($pattern, $subject, $matches, $flags | \PREG_OFFSET_CAPTURE, $offset);
$result = \preg_match_all($pattern, $subject, $matches, $flags | \PREG_OFFSET_CAPTURE, $offset);
\array_walk_recursive($matches, function (&$value) {
if ($value === '') {
$value = null;
}
});
$result = $matches === [] ? \false : 1;
if ($result === \false || $result === null) {
throw \RectorPrefix20220226\Composer\Pcre\PcreException::fromFunction('preg_match_all', $pattern);
}

View File

@ -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('RectorPrefix20220226\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e', false) && !interface_exists('ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e', false) && !trait_exists('ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e', false)) {
spl_autoload_call('RectorPrefix20220226\ComposerAutoloaderInit7cca083ac1fb6de172dd287644b40e7e');
if (!class_exists('ComposerAutoloaderInit0f483e1582652742f7410a43002d7277', false) && !interface_exists('ComposerAutoloaderInit0f483e1582652742f7410a43002d7277', false) && !trait_exists('ComposerAutoloaderInit0f483e1582652742f7410a43002d7277', false)) {
spl_autoload_call('RectorPrefix20220226\ComposerAutoloaderInit0f483e1582652742f7410a43002d7277');
}
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('RectorPrefix20220226\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220226\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire7cca083ac1fb6de172dd287644b40e7e')) {
function composerRequire7cca083ac1fb6de172dd287644b40e7e() {
return \RectorPrefix20220226\composerRequire7cca083ac1fb6de172dd287644b40e7e(...func_get_args());
if (!function_exists('composerRequire0f483e1582652742f7410a43002d7277')) {
function composerRequire0f483e1582652742f7410a43002d7277() {
return \RectorPrefix20220226\composerRequire0f483e1582652742f7410a43002d7277(...func_get_args());
}
}
if (!function_exists('scanPath')) {