mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 15:00:50 +00:00
Prepare NamedToUnnamedArgs for PhpParameterReflection change in PHPStan 1.7 (#2305)
This commit is contained in:
parent
1ec5e2d35b
commit
28dc9cebb2
|
@ -7,7 +7,7 @@
|
|||
],
|
||||
"require": {
|
||||
"php": "^7.2|^8.0",
|
||||
"phpstan/phpstan": "^1.6.8"
|
||||
"phpstan/phpstan": "^1.6.8 || <1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"nikic/php-parser": "^4.13.2",
|
||||
"ondram/ci-detector": "^4.1",
|
||||
"phpstan/phpdoc-parser": "^1.5.1",
|
||||
"phpstan/phpstan": "^1.6.8",
|
||||
"phpstan/phpstan": "^1.6.8 || <1.7",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"psr/log": "^2.0",
|
||||
"react/child-process": "^0.6.4",
|
||||
|
|
13
phpstan.neon
13
phpstan.neon
|
@ -365,7 +365,6 @@ parameters:
|
|||
|
||||
# many internal cases
|
||||
- '#Calling (.*?) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version#'
|
||||
- '#Creating (.*?) is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#'
|
||||
|
||||
# generated content - not reliable values
|
||||
-
|
||||
|
@ -679,3 +678,15 @@ parameters:
|
|||
-
|
||||
message: '#Do not compare call directly, use a variable assign#'
|
||||
path: bin/rector.php
|
||||
|
||||
# use of internal phpstan classes
|
||||
-
|
||||
message: '#Creating new PHPStan\\Reflection\\BetterReflection\\SourceLocator\\Optimized(.*?)SourceLocator is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#'
|
||||
path: packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php
|
||||
-
|
||||
message: '#Creating new PHPStan\\Reflection\\Native\\NativeFunctionReflection is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#'
|
||||
path: src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver
|
||||
|
||||
-
|
||||
message: '#Creating new PHPStan\\Reflection\\Php\\PhpParameterReflection is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#'
|
||||
path: rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php
|
||||
|
|
|
@ -19,7 +19,7 @@ final class NamedToUnnamedArgs
|
|||
{
|
||||
public function __construct(
|
||||
private readonly NodeNameResolver $nodeNameResolver,
|
||||
private readonly DefaultParameterValueResolver $defaultParameterValueResolver
|
||||
private readonly DefaultParameterValueResolver $defaultParameterValueResolver,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ final class NamedToUnnamedArgs
|
|||
public function fillFromJumpedNamedArgs(
|
||||
FunctionReflection | MethodReflection | ReflectionFunction $functionLikeReflection,
|
||||
array $unnamedArgs,
|
||||
bool $isNativeFunctionReflection,
|
||||
array $parameters
|
||||
): array {
|
||||
$keys = array_keys($unnamedArgs);
|
||||
|
@ -92,8 +91,8 @@ final class NamedToUnnamedArgs
|
|||
}
|
||||
|
||||
/** @var ParameterReflection|PhpParameterReflection $parameterReflection */
|
||||
if ($isNativeFunctionReflection) {
|
||||
/** @var ReflectionFunction $functionLikeReflection */
|
||||
if ($functionLikeReflection instanceof ReflectionFunction) {
|
||||
// @todo since PHPStan 1.7.* add new InitializerExprTypeResolver() service as 1st arg - https://github.com/phpstan/phpstan-src/commit/c8b3926f005d008178d6d8c62aaca0200a6359a2#diff-ce65c81a2653b1f53bc416082582e248f629d65c066440d9c4edc5005d16af32
|
||||
$parameterReflection = new PhpParameterReflection(
|
||||
$functionLikeReflection->getParameters()[$i],
|
||||
null,
|
||||
|
@ -103,16 +102,13 @@ final class NamedToUnnamedArgs
|
|||
$parameterReflection = $parameters[$i];
|
||||
}
|
||||
|
||||
$defaulValue = $this->defaultParameterValueResolver->resolveFromParameterReflection(
|
||||
$parameterReflection
|
||||
);
|
||||
|
||||
if (! $defaulValue instanceof Expr) {
|
||||
$defaultValue = $this->defaultParameterValueResolver->resolveFromParameterReflection($parameterReflection);
|
||||
if (! $defaultValue instanceof Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$unnamedArgs[$i] = new Arg(
|
||||
$defaulValue,
|
||||
$defaultValue,
|
||||
$parameterReflection->passedByReference()
|
||||
->yes(),
|
||||
$parameterReflection->isVariadic(),
|
||||
|
|
|
@ -29,11 +29,10 @@ final class UnnamedArgumentResolver
|
|||
array $currentArgs
|
||||
): array {
|
||||
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionLikeReflection->getVariants());
|
||||
$unnamedArgs = [];
|
||||
$parameters = $parametersAcceptor->getParameters();
|
||||
$isNativeFunctionReflection = $functionLikeReflection instanceof NativeFunctionReflection;
|
||||
|
||||
if ($isNativeFunctionReflection) {
|
||||
$parameters = $parametersAcceptor->getParameters();
|
||||
|
||||
if ($functionLikeReflection instanceof NativeFunctionReflection) {
|
||||
$functionLikeReflection = new ReflectionFunction($functionLikeReflection->getName());
|
||||
}
|
||||
|
||||
|
@ -61,7 +60,6 @@ final class UnnamedArgumentResolver
|
|||
$unnamedArgs = $this->namedToUnnamedArgs->fillFromJumpedNamedArgs(
|
||||
$functionLikeReflection,
|
||||
$unnamedArgs,
|
||||
$isNativeFunctionReflection,
|
||||
$parameters
|
||||
);
|
||||
ksort($unnamedArgs);
|
||||
|
|
|
@ -8,10 +8,7 @@ use PhpParser\BuilderHelpers;
|
|||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ParameterReflection;
|
||||
use PHPStan\Reflection\ParametersAcceptor;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\Constant\ConstantBooleanType;
|
||||
use PHPStan\Type\ConstantType;
|
||||
|
@ -35,23 +32,6 @@ final class DefaultParameterValueResolver
|
|||
return $this->resolveValueFromType($defaultValue);
|
||||
}
|
||||
|
||||
public function resolveFromFunctionLikeAndPosition(
|
||||
MethodReflection | FunctionReflection $functionLikeReflection,
|
||||
int $position
|
||||
): ?Expr {
|
||||
$parametersAcceptor = $functionLikeReflection->getVariants()[0] ?? null;
|
||||
if (! $parametersAcceptor instanceof ParametersAcceptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parameterReflection = $parametersAcceptor->getParameters()[$position] ?? null;
|
||||
if (! $parameterReflection instanceof ParameterReflection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveFromParameterReflection($parameterReflection);
|
||||
}
|
||||
|
||||
private function resolveValueFromType(ConstantType $constantType): ConstFetch | Expr
|
||||
{
|
||||
if ($constantType instanceof ConstantBooleanType) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user