mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit cfcd16acc7620cf95de1d72edd12265c05e12f12
cfcd16acc7
[PHPStan 1.0] Use processNodes() over processNodeStmts() (#1111)
This commit is contained in:
parent
c90fff5b41
commit
87204a6592
@ -6,14 +6,14 @@ namespace Rector\ReadWrite\Guard;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\ParameterReflection;
|
||||
use PHPStan\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Reflection\Native\NativeFunctionReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use ReflectionFunction;
|
||||
use RectorPrefix20211030\Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
final class VariableToConstantGuard
|
||||
{
|
||||
/**
|
||||
@ -28,10 +28,15 @@ final class VariableToConstantGuard
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \PHPStan\Reflection\ReflectionProvider $reflectionProvider)
|
||||
/**
|
||||
* @var \Symplify\PackageBuilder\Reflection\PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \PHPStan\Reflection\ReflectionProvider $reflectionProvider, \RectorPrefix20211030\Symplify\PackageBuilder\Reflection\PrivatesAccessor $privatesAccessor)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
}
|
||||
public function isReadArg(\PhpParser\Node\Arg $arg) : bool
|
||||
{
|
||||
@ -50,7 +55,7 @@ final class VariableToConstantGuard
|
||||
return \true;
|
||||
}
|
||||
$functionReflection = $this->reflectionProvider->getFunction($functionName, $argScope);
|
||||
$referenceParametersPositions = $this->resolveFunctionReferencePositions($functionReflection, [$arg], $argScope);
|
||||
$referenceParametersPositions = $this->resolveFunctionReferencePositions($functionReflection);
|
||||
if ($referenceParametersPositions === []) {
|
||||
// no reference always only write
|
||||
return \true;
|
||||
@ -59,21 +64,31 @@ final class VariableToConstantGuard
|
||||
return !\in_array($argumentPosition, $referenceParametersPositions, \true);
|
||||
}
|
||||
/**
|
||||
* @param Arg[] $args
|
||||
* @return int[]
|
||||
*/
|
||||
private function resolveFunctionReferencePositions(\PHPStan\Reflection\FunctionReflection $functionReflection, array $args, \PHPStan\Analyser\Scope $scope) : array
|
||||
private function resolveFunctionReferencePositions(\PHPStan\Reflection\FunctionReflection $functionReflection) : array
|
||||
{
|
||||
if (isset($this->referencePositionsByFunctionName[$functionReflection->getName()])) {
|
||||
return $this->referencePositionsByFunctionName[$functionReflection->getName()];
|
||||
}
|
||||
// this is needed, as native function reflection does not have access to referenced parameters
|
||||
if ($functionReflection instanceof \PHPStan\Reflection\Native\NativeFunctionReflection) {
|
||||
$functionName = $functionReflection->getName();
|
||||
if (!\function_exists($functionName)) {
|
||||
return [];
|
||||
}
|
||||
$nativeFunctionReflection = new \ReflectionFunction($functionName);
|
||||
} else {
|
||||
$nativeFunctionReflection = $this->privatesAccessor->getPrivateProperty($functionReflection, 'reflection');
|
||||
}
|
||||
$referencePositions = [];
|
||||
$parametersAcceptor = \PHPStan\Reflection\ParametersAcceptorSelector::selectFromArgs($scope, $args, $functionReflection->getVariants());
|
||||
foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) {
|
||||
/** @var ParameterReflection $parameterReflection */
|
||||
if (!$parameterReflection->passedByReference()->yes()) {
|
||||
foreach ($nativeFunctionReflection->getParameters() as $position => $reflectionParameter) {
|
||||
if (!$reflectionParameter->isPassedByReference()) {
|
||||
continue;
|
||||
}
|
||||
if (!\is_int($position)) {
|
||||
throw new \Rector\Core\Exception\ShouldNotHappenException();
|
||||
}
|
||||
$referencePositions[] = $position;
|
||||
}
|
||||
$this->referencePositionsByFunctionName[$functionReflection->getName()] = $referencePositions;
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '95ad690d94aacddc72af7ab6c33be0d4d15db22c';
|
||||
public const PACKAGE_VERSION = 'cfcd16acc7620cf95de1d72edd12265c05e12f12';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-10-30 13:28:28';
|
||||
public const RELEASE_DATE = '2021-10-30 13:27:54';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211030\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 ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684::getLoader();
|
||||
return ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf::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 ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684
|
||||
class ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf', '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\ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire49e830dd306fc2dccafaebabb1a1a684($fileIdentifier, $file);
|
||||
composerRequire8752c41aa7fa8ef7deda5b25262ddbaf($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire49e830dd306fc2dccafaebabb1a1a684($fileIdentifier, $file)
|
||||
function composerRequire8752c41aa7fa8ef7deda5b25262ddbaf($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 ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684
|
||||
class ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -3889,9 +3889,9 @@ class ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit49e830dd306fc2dccafaebabb1a1a684::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit8752c41aa7fa8ef7deda5b25262ddbaf::$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('RectorPrefix20211030\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684', false) && !interface_exists('ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684', false) && !trait_exists('ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684', false)) {
|
||||
spl_autoload_call('RectorPrefix20211030\ComposerAutoloaderInit49e830dd306fc2dccafaebabb1a1a684');
|
||||
if (!class_exists('ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf', false) && !interface_exists('ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf', false) && !trait_exists('ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf', false)) {
|
||||
spl_autoload_call('RectorPrefix20211030\ComposerAutoloaderInit8752c41aa7fa8ef7deda5b25262ddbaf');
|
||||
}
|
||||
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('RectorPrefix20211030\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20211030\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire49e830dd306fc2dccafaebabb1a1a684')) {
|
||||
function composerRequire49e830dd306fc2dccafaebabb1a1a684() {
|
||||
return \RectorPrefix20211030\composerRequire49e830dd306fc2dccafaebabb1a1a684(...func_get_args());
|
||||
if (!function_exists('composerRequire8752c41aa7fa8ef7deda5b25262ddbaf')) {
|
||||
function composerRequire8752c41aa7fa8ef7deda5b25262ddbaf() {
|
||||
return \RectorPrefix20211030\composerRequire8752c41aa7fa8ef7deda5b25262ddbaf(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user