mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-30 07:50:53 +00:00
Updated Rector to commit 4f4dce928e
4f4dce928e
Improve reflection for Variadic analyzer (#310)
This commit is contained in:
parent
7d23c365ed
commit
ba438584ff
|
@ -1,4 +1,4 @@
|
|||
# 495 Rules Overview
|
||||
# 494 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
|||
|
||||
- [Composer](#composer) (6)
|
||||
|
||||
- [DeadCode](#deadcode) (46)
|
||||
- [DeadCode](#deadcode) (48)
|
||||
|
||||
- [Defluent](#defluent) (9)
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
|||
|
||||
- [MysqlToMysqli](#mysqltomysqli) (4)
|
||||
|
||||
- [Naming](#naming) (9)
|
||||
- [Naming](#naming) (7)
|
||||
|
||||
- [Order](#order) (1)
|
||||
|
||||
|
@ -96,7 +96,7 @@
|
|||
|
||||
- [Transform](#transform) (36)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (19)
|
||||
- [TypeDeclaration](#typedeclaration) (18)
|
||||
|
||||
- [Visibility](#visibility) (3)
|
||||
|
||||
|
@ -3586,6 +3586,45 @@ Remove unused parent call with no parent class
|
|||
|
||||
<br>
|
||||
|
||||
### RemovePhpVersionIdCheckRector
|
||||
|
||||
Remove unneded PHP_VERSION_ID check
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector`](../rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php)
|
||||
|
||||
```php
|
||||
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RemovePhpVersionIdCheckRector::class)
|
||||
->call('configure', [[
|
||||
RemovePhpVersionIdCheckRector::PHP_VERSION_CONSTRAINT => 80000,
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- if (PHP_VERSION_ID < 80000) {
|
||||
- return;
|
||||
- }
|
||||
echo 'do something';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveUnreachableStatementRector
|
||||
|
||||
Remove unreachable statements
|
||||
|
@ -3769,6 +3808,30 @@ Remove unused private properties
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveUnusedPromotedPropertyRector
|
||||
|
||||
Remove unused promoted property
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector`](../rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function __construct(
|
||||
- private $someUnusedDependency,
|
||||
private $usedDependency
|
||||
) {
|
||||
}
|
||||
|
||||
public function getUsedDependency()
|
||||
{
|
||||
return $this->usedDependency;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveUnusedVariableAssignRector
|
||||
|
||||
Remove unused assigns to variables
|
||||
|
@ -5183,10 +5246,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(DowngradeAttributeToAnnotationRector::class)
|
||||
->call('configure', [[
|
||||
DowngradeAttributeToAnnotationRector::ATTRIBUTE_TO_ANNOTATION => ValueObjectInliner::inline([
|
||||
new DowngradeAttributeToAnnotation(
|
||||
'Symfony\Component\Routing\Annotation\Route',
|
||||
'Symfony\Component\Routing\Annotation\Route'
|
||||
),
|
||||
new DowngradeAttributeToAnnotation('Symfony\Component\Routing\Annotation\Route', null),
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
|
@ -6007,54 +6067,6 @@ Renames property to respect is/has/was method naming
|
|||
|
||||
<br>
|
||||
|
||||
### MakeGetterClassMethodNameStartWithGetRector
|
||||
|
||||
Change getter method names to start with get/provide
|
||||
|
||||
- class: [`Rector\Naming\Rector\ClassMethod\MakeGetterClassMethodNameStartWithGetRector`](../rules/Naming/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
- public function name(): string
|
||||
+ public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MakeIsserClassMethodNameStartWithIsRector
|
||||
|
||||
Change is method names to start with is/has/was
|
||||
|
||||
- class: [`Rector\Naming\Rector\ClassMethod\MakeIsserClassMethodNameStartWithIsRector`](../rules/Naming/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isActive = false;
|
||||
|
||||
- public function getIsActive()
|
||||
+ public function isActive()
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RenameForeachValueVariableToMatchExprVariableRector
|
||||
|
||||
Renames value variable name in foreach loop to match expression variable
|
||||
|
@ -11900,8 +11912,26 @@ Add known return type to functions
|
|||
|
||||
Change param type to strict type of passed expression
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector`](../rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php)
|
||||
|
||||
```php
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(AddMethodCallBasedStrictParamTypeRector::class)
|
||||
->call('configure', [[
|
||||
AddMethodCallBasedStrictParamTypeRector::TRUST_DOC_BLOCKS => false,
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
|
@ -11968,29 +11998,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
<br>
|
||||
|
||||
### AddParamTypeFromCallersRector
|
||||
|
||||
Add param type based on called types in that particular method
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeFromCallersRector`](../rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeFromCallersRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(Return_ $return)
|
||||
{
|
||||
$this->print($return);
|
||||
}
|
||||
|
||||
- public function print($return)
|
||||
+ public function print(Return_ $return)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AddReturnTypeDeclarationRector
|
||||
|
||||
Changes defined return typehint of method and class.
|
||||
|
|
|
@ -30,7 +30,8 @@ final class SpacingAwareArrayTypeNode extends \PHPStan\PhpDocParser\Ast\Type\Arr
|
|||
}
|
||||
private function isGenericArrayCandidate(\PHPStan\PhpDocParser\Ast\Type\TypeNode $typeNode) : bool
|
||||
{
|
||||
if (!$this->getAttribute(\Rector\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapper::HAS_GENERIC_TYPE_PARENT)) {
|
||||
$hasGenericTypeParent = (bool) $this->getAttribute(\Rector\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapper::HAS_GENERIC_TYPE_PARENT);
|
||||
if (!$hasGenericTypeParent) {
|
||||
return \false;
|
||||
}
|
||||
return $typeNode instanceof \PHPStan\PhpDocParser\Ast\Type\UnionTypeNode || $typeNode instanceof \PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
|
|
|
@ -83,7 +83,8 @@ CODE_SAMPLE
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
if (\is_a($this->getStaticType($node->expr), \PHPStan\Type\ObjectType::class)) {
|
||||
$exprType = $this->getStaticType($node->expr);
|
||||
if ($exprType instanceof \PHPStan\Type\ObjectType) {
|
||||
return null;
|
||||
}
|
||||
$this->removeForeachValueAndUseArrayKeys($node);
|
||||
|
|
|
@ -109,7 +109,8 @@ CODE_SAMPLE
|
|||
if (!$this->valueResolver->isFalse($returnedExpr)) {
|
||||
return !$this->valueResolver->isTrueOrFalse($nextNode->expr);
|
||||
}
|
||||
if (\strpos($this->print($if->cond), '!=') === \false) {
|
||||
$condString = $this->print($if->cond);
|
||||
if (\strpos($condString, '!=') === \false) {
|
||||
return !$this->valueResolver->isTrueOrFalse($nextNode->expr);
|
||||
}
|
||||
return \true;
|
||||
|
|
|
@ -133,7 +133,8 @@ CODE_SAMPLE
|
|||
continue;
|
||||
}
|
||||
// refactor here
|
||||
if ($this->refactorClassMethod($classMethod, $classReflection, $ancestors, $interfaces) !== null) {
|
||||
$changedClassMethod = $this->refactorClassMethod($classMethod, $classReflection, $ancestors, $interfaces);
|
||||
if ($changedClassMethod !== null) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ use PHPStan\Reflection\FunctionReflection;
|
|||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\Php\PhpMethodReflection;
|
||||
use PHPStan\Reflection\Type\UnionTypeMethodReflection;
|
||||
use Rector\Core\NodeAnalyzer\VariadicAnalyzer;
|
||||
use Rector\Core\PHPStan\Reflection\CallReflectionResolver;
|
||||
use Rector\Core\PHPStan\Reflection\VariadicAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -30,10 +30,10 @@ final class RemoveExtraParametersRector extends \Rector\Core\Rector\AbstractRect
|
|||
*/
|
||||
private $callReflectionResolver;
|
||||
/**
|
||||
* @var \Rector\Core\PHPStan\Reflection\VariadicAnalyzer
|
||||
* @var \Rector\Core\NodeAnalyzer\VariadicAnalyzer
|
||||
*/
|
||||
private $variadicAnalyzer;
|
||||
public function __construct(\Rector\Core\PHPStan\Reflection\CallReflectionResolver $callReflectionResolver, \Rector\Core\PHPStan\Reflection\VariadicAnalyzer $variadicAnalyzer)
|
||||
public function __construct(\Rector\Core\PHPStan\Reflection\CallReflectionResolver $callReflectionResolver, \Rector\Core\NodeAnalyzer\VariadicAnalyzer $variadicAnalyzer)
|
||||
{
|
||||
$this->callReflectionResolver = $callReflectionResolver;
|
||||
$this->variadicAnalyzer = $variadicAnalyzer;
|
||||
|
@ -82,37 +82,30 @@ final class RemoveExtraParametersRector extends \Rector\Core\Rector\AbstractRect
|
|||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param FuncCall|MethodCall|StaticCall $node
|
||||
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $call
|
||||
*/
|
||||
private function shouldSkip(\PhpParser\Node $node) : bool
|
||||
private function shouldSkip($call) : bool
|
||||
{
|
||||
if ($node->args === []) {
|
||||
if ($call->args === []) {
|
||||
return \true;
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Expr\StaticCall) {
|
||||
if (!$node->class instanceof \PhpParser\Node\Name) {
|
||||
if ($call instanceof \PhpParser\Node\Expr\StaticCall) {
|
||||
if (!$call->class instanceof \PhpParser\Node\Name) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->isName($node->class, 'parent')) {
|
||||
if ($this->isName($call->class, 'parent')) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
$functionReflection = $this->callReflectionResolver->resolveCall($node);
|
||||
if ($functionReflection === null) {
|
||||
return \true;
|
||||
}
|
||||
if ($functionReflection->getVariants() === []) {
|
||||
return \true;
|
||||
}
|
||||
return $this->variadicAnalyzer->hasVariadicParameters($functionReflection);
|
||||
return $this->variadicAnalyzer->hasVariadicParameters($call);
|
||||
}
|
||||
/**
|
||||
* @param MethodReflection|FunctionReflection $reflection
|
||||
* @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $functionLikeReflection
|
||||
*/
|
||||
private function resolveMaximumAllowedParameterCount($reflection) : int
|
||||
private function resolveMaximumAllowedParameterCount($functionLikeReflection) : int
|
||||
{
|
||||
$parameterCounts = [0];
|
||||
foreach ($reflection->getVariants() as $parametersAcceptor) {
|
||||
foreach ($functionLikeReflection->getVariants() as $parametersAcceptor) {
|
||||
$parameterCounts[] = \count($parametersAcceptor->getParameters());
|
||||
}
|
||||
return (int) \max($parameterCounts);
|
||||
|
|
|
@ -54,7 +54,8 @@ CODE_SAMPLE
|
|||
if (!$this->isName($node, 'array_key_exists')) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->getStaticType($node->args[1]->value) instanceof \PHPStan\Type\ObjectType) {
|
||||
$firstArgStaticType = $this->getStaticType($node->args[1]->value);
|
||||
if (!$firstArgStaticType instanceof \PHPStan\Type\ObjectType) {
|
||||
return null;
|
||||
}
|
||||
$node->name = new \PhpParser\Node\Name('property_exists');
|
||||
|
|
|
@ -43,7 +43,8 @@ final class MbStrrposEncodingArgumentPositionRector extends \Rector\Core\Rector\
|
|||
if (isset($node->args[3])) {
|
||||
return null;
|
||||
}
|
||||
if ($this->getStaticType($node->args[2]->value) instanceof \PHPStan\Type\IntegerType) {
|
||||
$secondArgType = $this->getStaticType($node->args[2]->value);
|
||||
if ($secondArgType instanceof \PHPStan\Type\IntegerType) {
|
||||
return null;
|
||||
}
|
||||
$node->args[3] = $node->args[2];
|
||||
|
|
|
@ -67,9 +67,13 @@ final class PhpSpecMethodToPHPUnitMethodRector extends \Rector\PhpSpecToPHPUnit\
|
|||
// reorder instantiation + expected exception
|
||||
$previousStmt = null;
|
||||
foreach ((array) $classMethod->stmts as $key => $stmt) {
|
||||
if ($previousStmt && \strpos($this->print($stmt), 'duringInstantiation') !== \false && \strpos($this->print($previousStmt), 'beConstructedThrough') !== \false) {
|
||||
$classMethod->stmts[$key - 1] = $stmt;
|
||||
$classMethod->stmts[$key] = $previousStmt;
|
||||
$printedStmt = $this->print($stmt);
|
||||
if ($previousStmt && \strpos($printedStmt, 'duringInstantiation') !== \false) {
|
||||
$printedPreviousStmt = $this->print($previousStmt);
|
||||
if (\strpos($printedPreviousStmt, 'beConstructedThrough') !== \false) {
|
||||
$classMethod->stmts[$key - 1] = $stmt;
|
||||
$classMethod->stmts[$key] = $previousStmt;
|
||||
}
|
||||
}
|
||||
$previousStmt = $stmt;
|
||||
}
|
||||
|
|
|
@ -70,9 +70,10 @@ CODE_SAMPLE
|
|||
if (!$class instanceof \PhpParser\Node\Stmt\Class_) {
|
||||
return null;
|
||||
}
|
||||
$printedClass = $this->print($class);
|
||||
foreach ($this->useImportsToRestore as $useImportToRestore) {
|
||||
$annotationToSeek = '#\\*\\s+\\@' . $useImportToRestore->getAlias() . '#';
|
||||
if (!\RectorPrefix20210627\Nette\Utils\Strings::match($this->print($class), $annotationToSeek)) {
|
||||
if (!\RectorPrefix20210627\Nette\Utils\Strings::match($printedClass, $annotationToSeek)) {
|
||||
continue;
|
||||
}
|
||||
$node = $this->addImportToNamespaceIfMissing($node, $useImportToRestore);
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '65547506989043585ff332ce5c5cd8383cc5f629';
|
||||
public const PACKAGE_VERSION = '4f4dce928e5d6534caaf904349740f1d2a9bf1b1';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-06-27 13:59:11';
|
||||
public const RELEASE_DATE = '2021-06-27 13:55:32';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210627\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
82
src/NodeAnalyzer/VariadicAnalyzer.php
Normal file
82
src/NodeAnalyzer/VariadicAnalyzer.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\Php\PhpFunctionReflection;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class VariadicAnalyzer
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\AstResolver
|
||||
*/
|
||||
private $astResolver;
|
||||
/**
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\AstResolver $astResolver, \Rector\Core\Reflection\ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->astResolver = $astResolver;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
|
||||
*/
|
||||
public function hasVariadicParameters($call) : bool
|
||||
{
|
||||
$functionLikeReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($call);
|
||||
if ($functionLikeReflection === null) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->hasVariadicVariant($functionLikeReflection)) {
|
||||
return \true;
|
||||
}
|
||||
if ($functionLikeReflection instanceof \PHPStan\Reflection\Php\PhpFunctionReflection) {
|
||||
$function = $this->astResolver->resolveFunctionFromFunctionReflection($functionLikeReflection);
|
||||
if (!$function instanceof \PhpParser\Node\Stmt\Function_) {
|
||||
return \false;
|
||||
}
|
||||
return (bool) $this->betterNodeFinder->findFirst($function->stmts, function (\PhpParser\Node $node) : bool {
|
||||
if (!$node instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isNames($node, ['func_get_args', 'func_num_args', 'func_get_arg']);
|
||||
});
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $functionLikeReflection
|
||||
*/
|
||||
private function hasVariadicVariant($functionLikeReflection) : bool
|
||||
{
|
||||
foreach ($functionLikeReflection->getVariants() as $parametersAcceptor) {
|
||||
// can be any number of arguments → nothing to limit here
|
||||
if ($parametersAcceptor->isVariadic()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\PHPStan\Reflection;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Parser;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\Php\PhpFunctionReflection;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use RectorPrefix20210627\Symplify\SmartFileSystem\SmartFileSystem;
|
||||
final class VariadicAnalyzer
|
||||
{
|
||||
/**
|
||||
* @var \PhpParser\Parser
|
||||
*/
|
||||
private $parser;
|
||||
/**
|
||||
* @var \Symplify\SmartFileSystem\SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(\PhpParser\Parser $parser, \RectorPrefix20210627\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem, \Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->smartFileSystem = $smartFileSystem;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $functionReflection
|
||||
*/
|
||||
public function hasVariadicParameters($functionReflection) : bool
|
||||
{
|
||||
$variants = $functionReflection->getVariants();
|
||||
foreach ($variants as $variant) {
|
||||
// can be any number of arguments → nothing to limit here
|
||||
if ($variant->isVariadic()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
if ($functionReflection instanceof \PHPStan\Reflection\Php\PhpFunctionReflection) {
|
||||
$pathsFunctionName = \explode('\\', $functionReflection->getName());
|
||||
$functionName = \array_pop($pathsFunctionName);
|
||||
$fileName = (string) $functionReflection->getFileName();
|
||||
/** @var Node[] $contentNodes */
|
||||
$contentNodes = $this->parser->parse($this->smartFileSystem->readFile($fileName));
|
||||
/** @var Function_ $function */
|
||||
$function = $this->betterNodeFinder->findFirst($contentNodes, function (\PhpParser\Node $node) use($functionName) : bool {
|
||||
if (!$node instanceof \PhpParser\Node\Stmt\Function_) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($node, $functionName);
|
||||
});
|
||||
return (bool) $this->betterNodeFinder->findFirst($function->stmts, function (\PhpParser\Node $node) : bool {
|
||||
if (!$node instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isNames($node, ['func_get_args', 'func_num_args', 'func_get_arg']);
|
||||
});
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -214,9 +214,15 @@ final class AstResolver
|
|||
if (isset($this->classesByName[$classReflection->getName()])) {
|
||||
return $this->classesByName[$classReflection->getName()];
|
||||
}
|
||||
/** @var string $fileName */
|
||||
$fileName = $classReflection->getFileName();
|
||||
$nodes = $this->parser->parse($this->smartFileSystem->readFile($fileName));
|
||||
// probably internal class
|
||||
if ($fileName === \false) {
|
||||
// avoid parsing falsy-file again
|
||||
$this->classesByName[$classReflection->getName()] = null;
|
||||
return null;
|
||||
}
|
||||
$fileContent = $this->smartFileSystem->readFile($fileName);
|
||||
$nodes = $this->parser->parse($fileContent);
|
||||
if ($nodes === null) {
|
||||
// avoid parsing falsy-file again
|
||||
$this->classesByName[$classReflection->getName()] = null;
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Core\Reflection;
|
||||
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\TypeUtils;
|
||||
|
@ -91,6 +94,20 @@ final class ReflectionResolver
|
|||
}
|
||||
return $this->resolveMethodReflection($callerType->getClassName(), $methodName);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $call
|
||||
* @return \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection|null
|
||||
*/
|
||||
public function resolveFunctionLikeReflectionFromCall($call)
|
||||
{
|
||||
if ($call instanceof \PhpParser\Node\Expr\MethodCall) {
|
||||
return $this->resolveMethodReflectionFromMethodCall($call);
|
||||
}
|
||||
if ($call instanceof \PhpParser\Node\Expr\StaticCall) {
|
||||
return $this->resolveMethodReflectionFromStaticCall($call);
|
||||
}
|
||||
return $this->resolveFunctionReflectionFromFuncCall($call);
|
||||
}
|
||||
public function resolveMethodReflectionFromClassMethod(\PhpParser\Node\Stmt\ClassMethod $classMethod) : ?\PHPStan\Reflection\MethodReflection
|
||||
{
|
||||
$class = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NAME);
|
||||
|
@ -108,4 +125,16 @@ final class ReflectionResolver
|
|||
}
|
||||
return $this->resolveMethodReflection($newClassType->getClassName(), \Rector\Core\ValueObject\MethodName::CONSTRUCT);
|
||||
}
|
||||
private function resolveFunctionReflectionFromFuncCall(\PhpParser\Node\Expr\FuncCall $funcCall) : ?\PHPStan\Reflection\FunctionReflection
|
||||
{
|
||||
$functionName = $this->nodeNameResolver->getName($funcCall);
|
||||
if ($functionName === null) {
|
||||
return null;
|
||||
}
|
||||
$functionNameFullyQualified = new \PhpParser\Node\Name\FullyQualified($functionName);
|
||||
if (!$this->reflectionProvider->hasFunction($functionNameFullyQualified, null)) {
|
||||
return null;
|
||||
}
|
||||
return $this->reflectionProvider->getFunction($functionNameFullyQualified, null);
|
||||
}
|
||||
}
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143::getLoader();
|
||||
return ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056::getLoader();
|
||||
|
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
|
@ -1838,6 +1838,7 @@ return array(
|
|||
'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => $baseDir . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => $baseDir . '/src/NodeAnalyzer/PropertyPresenceChecker.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => $baseDir . '/src/NodeAnalyzer/VariadicAnalyzer.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => $baseDir . '/src/NodeManipulator/ArrayManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\AssignManipulator' => $baseDir . '/src/NodeManipulator/AssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => $baseDir . '/src/NodeManipulator/BinaryOpManipulator.php',
|
||||
|
@ -1868,7 +1869,6 @@ return array(
|
|||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ConstantStringTypeToCallReflectionResolver' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ObjectTypeToCallReflectionResolver' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverRegistry' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverRegistry.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\VariadicAnalyzer' => $baseDir . '/src/PHPStan/Reflection/VariadicAnalyzer.php',
|
||||
'Rector\\Core\\PhpParser\\AstResolver' => $baseDir . '/src/PhpParser/AstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\ConditionSearcher' => $baseDir . '/src/PhpParser/Comparing/ConditionSearcher.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\NodeComparator' => $baseDir . '/src/PhpParser/Comparing/NodeComparator.php',
|
||||
|
|
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 ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143
|
||||
class ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056', '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\ComposerStaticInit6693f5945971950a6cec17f9d7687143::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit447df124c12b5b1fa5e21ef362c75056::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit6693f5945971950a6cec17f9d7687143::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit447df124c12b5b1fa5e21ef362c75056::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire6693f5945971950a6cec17f9d7687143($fileIdentifier, $file);
|
||||
composerRequire447df124c12b5b1fa5e21ef362c75056($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire6693f5945971950a6cec17f9d7687143($fileIdentifier, $file)
|
||||
function composerRequire447df124c12b5b1fa5e21ef362c75056($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit6693f5945971950a6cec17f9d7687143
|
||||
class ComposerStaticInit447df124c12b5b1fa5e21ef362c75056
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -2188,6 +2188,7 @@ class ComposerStaticInit6693f5945971950a6cec17f9d7687143
|
|||
'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyPresenceChecker.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/VariadicAnalyzer.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\AssignManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/AssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/BinaryOpManipulator.php',
|
||||
|
@ -2218,7 +2219,6 @@ class ComposerStaticInit6693f5945971950a6cec17f9d7687143
|
|||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ConstantStringTypeToCallReflectionResolver' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ObjectTypeToCallReflectionResolver' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverRegistry' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverRegistry.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\VariadicAnalyzer' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/VariadicAnalyzer.php',
|
||||
'Rector\\Core\\PhpParser\\AstResolver' => __DIR__ . '/../..' . '/src/PhpParser/AstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\ConditionSearcher' => __DIR__ . '/../..' . '/src/PhpParser/Comparing/ConditionSearcher.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\NodeComparator' => __DIR__ . '/../..' . '/src/PhpParser/Comparing/NodeComparator.php',
|
||||
|
@ -3834,9 +3834,9 @@ class ComposerStaticInit6693f5945971950a6cec17f9d7687143
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6693f5945971950a6cec17f9d7687143::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6693f5945971950a6cec17f9d7687143::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6693f5945971950a6cec17f9d7687143::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit447df124c12b5b1fa5e21ef362c75056::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit447df124c12b5b1fa5e21ef362c75056::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit447df124c12b5b1fa5e21ef362c75056::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -21,8 +21,8 @@ if (!class_exists('SomeTestCase', false) && !interface_exists('SomeTestCase', fa
|
|||
if (!class_exists('CheckoutEntityFactory', false) && !interface_exists('CheckoutEntityFactory', false) && !trait_exists('CheckoutEntityFactory', false)) {
|
||||
spl_autoload_call('RectorPrefix20210627\CheckoutEntityFactory');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143', false) && !interface_exists('ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143', false) && !trait_exists('ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143', false)) {
|
||||
spl_autoload_call('RectorPrefix20210627\ComposerAutoloaderInit6693f5945971950a6cec17f9d7687143');
|
||||
if (!class_exists('ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056', false) && !interface_exists('ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056', false) && !trait_exists('ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056', false)) {
|
||||
spl_autoload_call('RectorPrefix20210627\ComposerAutoloaderInit447df124c12b5b1fa5e21ef362c75056');
|
||||
}
|
||||
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
|
||||
spl_autoload_call('RectorPrefix20210627\Doctrine\Inflector\Inflector');
|
||||
|
@ -3320,9 +3320,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210627\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire6693f5945971950a6cec17f9d7687143')) {
|
||||
function composerRequire6693f5945971950a6cec17f9d7687143() {
|
||||
return \RectorPrefix20210627\composerRequire6693f5945971950a6cec17f9d7687143(...func_get_args());
|
||||
if (!function_exists('composerRequire447df124c12b5b1fa5e21ef362c75056')) {
|
||||
function composerRequire447df124c12b5b1fa5e21ef362c75056() {
|
||||
return \RectorPrefix20210627\composerRequire447df124c12b5b1fa5e21ef362c75056(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user