[PHP 8.0] Run union types for filled param type too (#331)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tomas Votruba 2021-06-29 16:11:40 +02:00 committed by GitHub
parent 2a394c750f
commit dfd048342b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
77 changed files with 220 additions and 466 deletions

View File

@ -6,7 +6,6 @@ namespace Rector\NodeCollector\NodeCollector;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
use Rector\Core\Exception\ShouldNotHappenException;
@ -100,10 +99,7 @@ final class ParsedNodeCollector
$this->classes[$className] = $class;
}
/**
* @param Interface_|Trait_ $classLike
*/
private function collectInterfaceOrTrait(ClassLike $classLike): void
private function collectInterfaceOrTrait(Interface_ | Trait_ $classLike): void
{
$name = $this->nodeNameResolver->getName($classLike);
if ($name === null) {

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\NodeNameResolver\Error;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Core\Contract\Rector\RectorInterface;
@ -27,10 +26,7 @@ final class InvalidNameNodeReporter
) {
}
/**
* @param MethodCall|StaticCall $node
*/
public function reportInvalidNodeForName(Node $node): void
public function reportInvalidNodeForName(MethodCall | StaticCall $node): void
{
$message = sprintf('Pick more specific node than "%s", e.g. "$node->name"', $node::class);

View File

@ -89,10 +89,7 @@ final class NodeRemover
unset($classMethod->params[$key]);
}
/**
* @param FuncCall|MethodCall|StaticCall $node
*/
public function removeArg(Node $node, int $key): void
public function removeArg(FuncCall | MethodCall | StaticCall $node, int $key): void
{
if ($node->args === null) {
throw new ShouldNotHappenException();

View File

@ -146,10 +146,7 @@ final class NodesToAddCollector implements NodeCollectorInterface
return spl_object_hash($foundNode);
}
/**
* @param Expr|Stmt $node
*/
private function wrapToExpression(Node $node): Stmt
private function wrapToExpression(Expr | Stmt $node): Stmt
{
return $node instanceof Stmt ? $node : new Expression($node);
}

View File

@ -6,7 +6,6 @@ namespace Rector\PostRector\Collector;
use PhpParser\Node;
use PhpParser\Node\Stmt\Use_;
use PHPStan\Type\ObjectType;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -42,10 +41,7 @@ final class UseNodesToAddCollector implements NodeCollectorInterface
return $this->useImportTypesInFilePath !== [] || $this->functionUseImportTypesInFilePath !== [];
}
/**
* @param FullyQualifiedObjectType|AliasedObjectType $objectType
*/
public function addUseImport(ObjectType $objectType): void
public function addUseImport(FullyQualifiedObjectType | AliasedObjectType $objectType): void
{
$file = $this->currentFileProvider->getFile();
$smartFileInfo = $file->getSmartFileInfo();

View File

@ -35,10 +35,7 @@ final class AliasedObjectType extends ObjectType
return $this->getClassName();
}
/**
* @param AliasedObjectType|FullyQualifiedObjectType $comparedObjectType
*/
public function areShortNamesEqual(ObjectType $comparedObjectType): bool
public function areShortNamesEqual(self | FullyQualifiedObjectType $comparedObjectType): bool
{
return $this->getShortName() === $comparedObjectType->getShortName();
}

View File

@ -18,11 +18,9 @@ final class FullyQualifiedObjectType extends ObjectType
return new ShortenedObjectType($this->getShortName(), $this->getClassName());
}
/**
* @param AliasedObjectType|FullyQualifiedObjectType $comparedObjectType
*/
public function areShortNamesEqual(ObjectType $comparedObjectType): bool
{
public function areShortNamesEqual(
AliasedObjectType | \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $comparedObjectType
): bool {
return $this->getShortName() === $comparedObjectType->getShortName();
}

View File

@ -0,0 +1,40 @@
<?php
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
final class ParamDoc
{
/**
* @param ClassMethod|Property|ClassConst|ClassMethod $stmt
*/
public function addAsFirstMethod(Class_ $class, Stmt $stmt): void
{
}
}
?>
-----
<?php
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
final class ParamDoc
{
public function addAsFirstMethod(Class_ $class, \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $stmt): void
{
}
}
?>

View File

@ -2,10 +2,15 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php80\Rector\FunctionLike\UnionTypesRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(UnionTypesRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES);
};

View File

@ -7,7 +7,6 @@ namespace Rector\Arguments;
use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
@ -39,11 +38,10 @@ final class ArgumentDefaultValueReplacer
return $node;
}
/**
* @param MethodCall|StaticCall|FuncCall $expr
*/
private function processArgs(Expr $expr, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue): void
{
private function processArgs(
MethodCall | StaticCall | FuncCall $expr,
ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue
): void {
$position = $replaceArgumentDefaultValue->getPosition();
$argValue = $this->valueResolver->getValue($expr->args[$position]->value);

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\Arguments\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
@ -33,10 +32,7 @@ final class ArgumentAddingScope
) {
}
/**
* @param MethodCall|StaticCall $expr
*/
public function isInCorrectScope(Expr $expr, ArgumentAdder $argumentAdder): bool
public function isInCorrectScope(MethodCall | StaticCall $expr, ArgumentAdder $argumentAdder): bool
{
if ($argumentAdder->getScope() === null) {
return true;

View File

@ -134,10 +134,7 @@ CODE_SAMPLE
$this->addedArguments = $addedArguments;
}
/**
* @param MethodCall|StaticCall|ClassMethod $node
*/
private function isObjectTypeMatch(Node $node, ObjectType $objectType): bool
private function isObjectTypeMatch(MethodCall | StaticCall | ClassMethod $node, ObjectType $objectType): bool
{
if ($node instanceof MethodCall) {
return $this->isObjectType($node->var, $objectType);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\CodeQuality\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
@ -103,10 +102,9 @@ CODE_SAMPLE
}
/**
* @param Array_|List_ $expr
* @return Assign[]
*/
private function createStandaloneAssigns(Expr $expr, Array_ $rightArray): array
private function createStandaloneAssigns(Array_ | List_ $expr, Array_ $rightArray): array
{
$standaloneAssigns = [];
foreach ($expr->items as $key => $leftArrayItem) {
@ -126,10 +124,7 @@ CODE_SAMPLE
return $standaloneAssigns;
}
/**
* @param Array_|List_ $expr
*/
private function isValueSwap(Expr $expr, Array_ $secondArray): bool
private function isValueSwap(Array_ | List_ $expr, Array_ $secondArray): bool
{
$firstArrayItemsHash = $this->getArrayItemsHash($expr);
$secondArrayItemsHash = $this->getArrayItemsHash($secondArray);
@ -137,10 +132,7 @@ CODE_SAMPLE
return $firstArrayItemsHash === $secondArrayItemsHash;
}
/**
* @param Array_|List_ $node
*/
private function getArrayItemsHash(Node $node): string
private function getArrayItemsHash(Array_ | List_ $node): string
{
$arrayItemsHashes = [];
foreach ($node->items as $arrayItem) {

View File

@ -198,10 +198,7 @@ CODE_SAMPLE
return $this->valueResolver->isTrueOrFalse($ifStatment->expr);
}
/**
* @param Identical|Equal $binaryOp
*/
private function createInArrayFunction(Expr $expr, BinaryOp $binaryOp, Foreach_ $foreach): FuncCall
private function createInArrayFunction(Expr $expr, Identical | Equal $binaryOp, Foreach_ $foreach): FuncCall
{
$arguments = $this->nodeFactory->createArgs([$expr, $foreach->expr]);

View File

@ -169,10 +169,7 @@ CODE_SAMPLE
return ! $this->nodeComparator->areNodesEqual($if->cond->vars[0], $firstElseStmt->expr->var);
}
/**
* @param If_|Else_ $node
*/
private function hasOnlyStatementAssign(Node $node): bool
private function hasOnlyStatementAssign(If_ | Else_ $node): bool
{
if (count($node->stmts) !== 1) {
return false;

View File

@ -161,11 +161,10 @@ CODE_SAMPLE
return ! $phpDocInfo->getVarType() instanceof MixedType;
}
/**
* @param AssignOp|Assign $previousNode
*/
private function isPreviousExpressionVisuallySimilar(Expression $previousExpression, Node $previousNode): bool
{
private function isPreviousExpressionVisuallySimilar(
Expression $previousExpression,
AssignOp | Assign $previousNode
): bool {
$prePreviousExpression = $previousExpression->getAttribute(AttributeKey::PREVIOUS_STATEMENT);
if (! $prePreviousExpression instanceof Expression) {
return false;

View File

@ -7,7 +7,6 @@ namespace Rector\CodeQualityStrict\NodeFactory;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\Core\Exception\ShouldNotHappenException;
@ -16,10 +15,9 @@ use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
final class ClassConstFetchFactory
{
/**
* @param ObjectType|UnionType $type
* @return ClassConstFetch[]
*/
public function createFromType(Type $type): array
public function createFromType(ObjectType | UnionType $type): array
{
$classConstTypes = [];
if ($type instanceof ShortenedObjectType) {

View File

@ -128,10 +128,9 @@ CODE_SAMPLE
/**
* @param Param[] $params
* @param ObjectType|UnionType $type
* @return ObjectType|UnionType
*/
private function getToBeProcessedTypes(array $params, string $key, Type $type): ?Type
private function getToBeProcessedTypes(array $params, string $key, ObjectType | UnionType $type): ?Type
{
foreach ($params as $param) {
$paramName = ltrim($key, '$');

View File

@ -68,10 +68,7 @@ final class NameRenamer
}
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameTraitUse(string $lastName, TraitUse $traitUse, Node $usedNameNode): void
private function renameTraitUse(string $lastName, TraitUse $traitUse, Name | Identifier $usedNameNode): void
{
foreach ($traitUse->traits as $key => $traitName) {
if (! $this->nodeNameResolver->areNamesEqual($traitName, $usedNameNode)) {
@ -82,10 +79,7 @@ final class NameRenamer
}
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameClass(string $lastName, Class_ $class, Node $usedNameNode): void
private function renameClass(string $lastName, Class_ $class, Name | Identifier $usedNameNode): void
{
if ($class->name !== null && $this->nodeNameResolver->areNamesEqual($class->name, $usedNameNode)) {
$class->name = new Identifier($lastName);
@ -102,10 +96,7 @@ final class NameRenamer
}
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameParam(string $lastName, Param $param, Node $usedNameNode): void
private function renameParam(string $lastName, Param $param, Name | Identifier $usedNameNode): void
{
if ($param->type === null) {
return;
@ -133,21 +124,18 @@ final class NameRenamer
}
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameNew(string $lastName, New_ $new, Node $usedNameNode): void
private function renameNew(string $lastName, New_ $new, Name | Identifier $usedNameNode): void
{
if ($this->nodeNameResolver->areNamesEqual($new->class, $usedNameNode)) {
$new->class = new Name($lastName);
}
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameClassMethod(string $lastName, ClassMethod $classMethod, Node $usedNameNode): void
{
private function renameClassMethod(
string $lastName,
ClassMethod $classMethod,
Name | Identifier $usedNameNode
): void {
if ($classMethod->returnType === null) {
return;
}
@ -159,10 +147,7 @@ final class NameRenamer
$classMethod->returnType = new Name($lastName);
}
/**
* @param Name|Identifier $usedNameNode
*/
private function renameInterface(string $lastName, Interface_ $interface, Node $usedNameNode): void
private function renameInterface(string $lastName, Interface_ $interface, Name | Identifier $usedNameNode): void
{
foreach ($interface->extends as $key => $extendInterfaceName) {
if (! $this->nodeNameResolver->areNamesEqual($extendInterfaceName, $usedNameNode)) {

View File

@ -239,11 +239,10 @@ CODE_SAMPLE
return $this->jsonEncodeStaticCallFactory->createFromArray($assign->var, $jsonArray);
}
/**
* @param Assign|ConcatAssign $currentNode
*/
private function matchNextExprAssignConcatToSameVariable(Expr $expr, Node $currentNode): ?NodeToRemoveAndConcatItem
{
private function matchNextExprAssignConcatToSameVariable(
Expr $expr,
Assign | ConcatAssign | Expression | Node $currentNode
): ?NodeToRemoveAndConcatItem {
$nextExpression = $this->getNextExpression($currentNode);
if (! $nextExpression instanceof Expression) {
return null;

View File

@ -139,10 +139,7 @@ CODE_SAMPLE
return ! $this->isPrecededByEmptyLine($node, $key);
}
/**
* @param Assign|MethodCall $node
*/
private function shouldSkipLeftVariable(Node $node): bool
private function shouldSkipLeftVariable(Assign | MethodCall $node): bool
{
if (! $node->var instanceof Variable) {
return false;

View File

@ -109,10 +109,7 @@ CODE_SAMPLE
$this->typeToPreference = $typeToPreference;
}
/**
* @param MethodCall|StaticCall $node
*/
private function processToSelf(Node $node): ?StaticCall
private function processToSelf(MethodCall | StaticCall $node): ?StaticCall
{
if ($node instanceof StaticCall && ! $this->isNames($node->class, [self::SELF, 'static'])) {
return null;
@ -130,10 +127,7 @@ CODE_SAMPLE
return $this->nodeFactory->createStaticCall(self::SELF, $name, $node->args);
}
/**
* @param MethodCall|StaticCall $node
*/
private function processToThis(Node $node): ?MethodCall
private function processToThis(MethodCall | StaticCall $node): ?MethodCall
{
if ($node instanceof MethodCall) {
return null;

View File

@ -118,10 +118,7 @@ CODE_SAMPLE
return $arrayDimFetch->dim;
}
/**
* @param PostInc|PostDec $node
*/
private function processPreFor(Node $node, For_ $for): PreDec | PreInc
private function processPreFor(PostInc | PostDec $node, For_ $for): PreDec | PreInc
{
$for->loop = [$this->processPrePost($node)];
return $for->loop[0];

View File

@ -49,10 +49,7 @@ final class VarTagRemover
$phpDocInfo->removeByType(VarTagValueNode::class);
}
/**
* @param Expression|Property|Param $node
*/
public function removeVarPhpTagValueNodeIfNotComment(Node $node, Type $type): void
public function removeVarPhpTagValueNodeIfNotComment(Expression | Property | Param $node, Type $type): void
{
// keep doctrine collection narrow type
if ($this->doctrineTypeAnalyzer->isDoctrineCollectionWithIterableUnionType($type)) {
@ -84,10 +81,7 @@ final class VarTagRemover
$phpDocInfo->removeByType(VarTagValueNode::class);
}
/**
* @param Expression|Param|Property $node
*/
private function isNonBasicArrayType(Node $node, VarTagValueNode $varTagValueNode): bool
private function isNonBasicArrayType(Expression | Param | Property $node, VarTagValueNode $varTagValueNode): bool
{
if ($varTagValueNode->type instanceof BracketsAwareUnionTypeNode) {
foreach ($varTagValueNode->type->types as $type) {

View File

@ -183,11 +183,10 @@ CODE_SAMPLE
});
}
/**
* @param FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $expr
*/
private function isUsedInAssignExpr(Expr $expr, Assign $assign): bool
{
private function isUsedInAssignExpr(
FuncCall | MethodCall | New_ | NullsafeMethodCall | StaticCall $expr,
Assign $assign
): bool {
foreach ($expr->args as $arg) {
$variable = $arg->value;
if (! $variable instanceof Variable) {

View File

@ -153,11 +153,9 @@ CODE_SAMPLE
return null;
}
/**
* @param Plus|Minus $binaryOp
*/
private function processBinaryPlusAndMinus(BinaryOp $binaryOp): ?Expr
{
private function processBinaryPlusAndMinus(
\PhpParser\Node\Expr\BinaryOp\Plus | \PhpParser\Node\Expr\BinaryOp\Minus $binaryOp
): ?Expr {
if ($this->valueResolver->isValue($binaryOp->left, 0) && $this->nodeTypeResolver->isNumberType(
$binaryOp->right
)) {
@ -178,11 +176,9 @@ CODE_SAMPLE
return $binaryOp->left;
}
/**
* @param Mul|Div $binaryOp
*/
private function processBinaryMulAndDiv(BinaryOp $binaryOp): ?Expr
{
private function processBinaryMulAndDiv(
\PhpParser\Node\Expr\BinaryOp\Mul | \PhpParser\Node\Expr\BinaryOp\Div $binaryOp
): ?Expr {
if ($binaryOp instanceof Mul && $this->valueResolver->isValue(
$binaryOp->left,
1

View File

@ -6,7 +6,6 @@ namespace Rector\DeadCode;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\NotEqual;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
@ -71,10 +70,7 @@ final class UselessIfCondBeforeForeachDetector
return $this->isMatchingNotBinaryOp($notIdentical, $foreachExpr);
}
/**
* @param NotIdentical|NotEqual $binaryOp
*/
private function isMatchingNotBinaryOp(BinaryOp $binaryOp, Expr $foreachExpr): bool
private function isMatchingNotBinaryOp(NotIdentical | NotEqual $binaryOp, Expr $foreachExpr): bool
{
if ($this->isEmptyArrayAndForeachedVariable($binaryOp->left, $binaryOp->right, $foreachExpr)) {
return true;

View File

@ -5,16 +5,12 @@ declare(strict_types=1);
namespace Rector\Defluent\NodeResolver;
use PhpParser\Node\Expr;
use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface;
use Rector\Defluent\ValueObject\AssignAndRootExpr;
use Rector\Defluent\ValueObject\FirstAssignFluentCall;
final class FirstMethodCallVarResolver
{
/**
* @param FirstAssignFluentCall|AssignAndRootExpr $firstCallFactoryAware
*/
public function resolve(FirstCallFactoryAwareInterface $firstCallFactoryAware, int $key): Expr
public function resolve(FirstAssignFluentCall | AssignAndRootExpr $firstCallFactoryAware, int $key): Expr
{
if (! $firstCallFactoryAware->isFirstCallFactory()) {
return $firstCallFactoryAware->getCallerExpr();

View File

@ -13,7 +13,6 @@ use PhpParser\Node\Expr\Cast\Int_;
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
@ -114,10 +113,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param Function_|ClassMethod $functionLike
*/
private function resolveRecastAssign(Param $param, FunctionLike $functionLike): ?Expression
private function resolveRecastAssign(Param $param, Function_ | ClassMethod | Closure $functionLike): ?Expression
{
if ($functionLike->stmts === null) {
return null;

View File

@ -125,10 +125,9 @@ CODE_SAMPLE
}
/**
* @param List_|Array_ $node
* @return Expression[]
*/
private function processExtractToItsOwnVariable(Node $node, Node $parent, Node $parentExpression): array
private function processExtractToItsOwnVariable(List_ | Array_ $node, Node $parent, Node $parentExpression): array
{
$items = $node->items;
$assignExpressions = [];

View File

@ -66,11 +66,9 @@ CODE_SAMPLE
return $this->processForStringOrVariableOrProperty($node);
}
/**
* @param String_|Variable|PropertyFetch|StaticPropertyFetch $expr
*/
private function processForStringOrVariableOrProperty(Expr $expr): ?Expr
{
private function processForStringOrVariableOrProperty(
String_ | Variable | PropertyFetch | StaticPropertyFetch $expr
): ?Expr {
$nextNode = $expr->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof UnaryMinus) {
return null;

View File

@ -119,10 +119,9 @@ CODE_SAMPLE
* Remove the right-side-most params by reference or empty from `list()`,
* since they are not needed anymore.
* If all of them can be removed, then directly remove `list()`.
* @param List_|Array_ $node
* @return List_|Array_|null
*/
public function removeStaleParams(Node $node, int $rightSideRemovableParamsCount): ?Node
public function removeStaleParams(List_ | Array_ $node, int $rightSideRemovableParamsCount): ?Node
{
$nodeItemsCount = count($node->items);
if ($rightSideRemovableParamsCount === $nodeItemsCount) {
@ -138,10 +137,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param List_|Array_ $node
*/
private function shouldRefactor(Node $node): bool
private function shouldRefactor(List_ | Array_ $node): bool
{
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
// Check it follows `list(...) = $foo`

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\DowngradePhp74\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\ClassMethod;
@ -131,11 +132,10 @@ CODE_SAMPLE
return $node;
}
/**
* @param UnionType|NullableType|Name|Node\Identifier $returnTypeNode
*/
private function resolveDifferentAncestorReturnType(ClassMethod $classMethod, Node $returnTypeNode): Type
{
private function resolveDifferentAncestorReturnType(
ClassMethod $classMethod,
UnionType | NullableType | Name | Identifier $returnTypeNode
): Type {
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
// possibly trait

View File

@ -6,7 +6,6 @@ namespace Rector\DowngradePhp74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
@ -154,11 +153,9 @@ CODE_SAMPLE
return ! $this->valueResolver->isNull($allowableTagsParam);
}
/**
* @param Array_|Variable|PropertyFetch|ConstFetch|ClassConstFetch $expr
*/
private function createArrayFromString(Expr $expr): Concat
{
private function createArrayFromString(
Array_ | Variable | PropertyFetch | ConstFetch | ClassConstFetch $expr
): Concat {
$args = [new Arg(new String_('><')), new Arg($expr)];
$implodeFuncCall = new FuncCall(new Name('implode'), $args);
@ -166,11 +163,9 @@ CODE_SAMPLE
return new Concat($concat, new String_('>'));
}
/**
* @param Variable|PropertyFetch|ConstFetch|ClassConstFetch $expr
*/
private function createIsArrayTernaryFromExpression(Expr $expr): Ternary
{
private function createIsArrayTernaryFromExpression(
Variable | PropertyFetch | ConstFetch | ClassConstFetch $expr
): Ternary {
$isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($expr)]);
$nullNotIdentical = new NotIdentical($expr, $this->nodeFactory->createNull());
$booleanAnd = new BooleanAnd($nullNotIdentical, $isArrayFuncCall);

View File

@ -89,10 +89,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param LNumber|DNumber $node
*/
public function shouldRefactor(Node $node): bool
public function shouldRefactor(LNumber | DNumber $node): bool
{
// "_" notation can be applied to decimal numbers only
if ($node instanceof LNumber) {

View File

@ -115,10 +115,7 @@ CODE_SAMPLE
return $this->processParams($node);
}
/**
* @param FuncCall|MethodCall|StaticCall|New_ $node
*/
private function processArgs(Node $node): ?Node
private function processArgs(FuncCall | MethodCall | StaticCall | New_ $node): ?Node
{
if ($node->args === []) {
return null;

View File

@ -108,11 +108,10 @@ CODE_SAMPLE
}
/**
* @param Expression|Return_ $node
* @param MatchArm[] $matchArms
* @return Case_[]
*/
private function createSwitchCasesFromMatchArms(Node $node, array $matchArms): array
private function createSwitchCasesFromMatchArms(Expression | Return_ $node, array $matchArms): array
{
$switchCases = [];
@ -139,10 +138,9 @@ CODE_SAMPLE
}
/**
* @param Expression|Return_ $node
* @return Stmt[]
*/
private function createSwitchStmts(Node $node, MatchArm $matchArm): array
private function createSwitchStmts(Expression | Return_ $node, MatchArm $matchArm): array
{
$stmts = [];

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\DowngradePhp80\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
@ -83,10 +82,9 @@ CODE_SAMPLE
}
/**
* @param FuncCall|BooleanNot $expr
* @return FuncCall
*/
private function matchStrContainsOrNotStrContains(Expr $expr): ?FuncCall
private function matchStrContainsOrNotStrContains(FuncCall | BooleanNot $expr): ?FuncCall
{
$expr = ($expr instanceof BooleanNot) ? $expr->expr : $expr;
if (! $expr instanceof FuncCall) {

View File

@ -117,12 +117,11 @@ CODE_SAMPLE
}
/**
* @param MethodCall|StaticCall|New_ $node
* @param Arg[] $args
*/
private function processRemoveNamedArgument(
MethodReflection | FunctionReflection $reflection,
Node $node,
MethodCall | StaticCall | New_ $node,
array $args
): MethodCall | StaticCall | New_ {
/** @var Arg[] $newArgs */

View File

@ -131,10 +131,7 @@ CODE_SAMPLE
return $statements;
}
/**
* @param If_|ElseIf_ $node
*/
private function doesLastStatementBreakFlow(Node $node): bool
private function doesLastStatementBreakFlow(If_ | ElseIf_ $node): bool
{
$lastStmt = end($node->stmts);

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\MockeryToProphecy\Collector;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
@ -22,10 +21,9 @@ final class MockVariableCollector
}
/**
* @param FuncCall|StaticCall $node
* @return array<string, class-string>
*/
public function collectMockVariableName(Node $node): array
public function collectMockVariableName(FuncCall | StaticCall $node): array
{
$mockVariableTypesByNames = [];

View File

@ -14,10 +14,9 @@ use PhpParser\Node\Stmt\Foreach_;
final class CallMatcher
{
/**
* @param Assign|Foreach_ $node
* @return FuncCall|StaticCall|MethodCall|null
*/
public function matchCall(Node $node): ?Node
public function matchCall(Assign | Foreach_ $node): ?Node
{
if ($node->expr instanceof MethodCall) {
return $node->expr;

View File

@ -103,10 +103,7 @@ final class ExpectedNameResolver
return $expectedName->getName();
}
/**
* @param MethodCall|StaticCall|FuncCall $expr
*/
public function resolveForCall(Expr $expr): ?string
public function resolveForCall(MethodCall | StaticCall | FuncCall $expr): ?string
{
if ($this->isDynamicNameCall($expr)) {
return null;
@ -146,10 +143,7 @@ final class ExpectedNameResolver
return null;
}
/**
* @param MethodCall|StaticCall|FuncCall $expr
*/
public function resolveForForeach(Expr $expr): ?string
public function resolveForForeach(MethodCall | StaticCall | FuncCall $expr): ?string
{
if ($this->isDynamicNameCall($expr)) {
return null;
@ -190,10 +184,7 @@ final class ExpectedNameResolver
return $expectedNameFromMethodName->getSingularized();
}
/**
* @param MethodCall|StaticCall|FuncCall $expr
*/
private function isDynamicNameCall(Expr $expr): bool
private function isDynamicNameCall(MethodCall | StaticCall | FuncCall $expr): bool
{
if ($expr->name instanceof StaticCall) {
return true;

View File

@ -229,10 +229,7 @@ final class VariableNaming
return $varName . ucfirst($propertyName);
}
/**
* @param MethodCall|NullsafeMethodCall|StaticCall $node
*/
private function resolveFromMethodCall(Node $node): ?string
private function resolveFromMethodCall(MethodCall | NullsafeMethodCall | StaticCall $node): ?string
{
if ($node->name instanceof MethodCall) {
return $this->resolveFromMethodCall($node->name);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Naming\NamingConvention;
use Nette\Utils\Strings;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
@ -24,11 +23,12 @@ final class NamingConventionAnalyzer
* $someNameSuffix = $this->getSomeName();
* $prefixSomeName = $this->getSomeName();
* $someName = $this->getSomeName();
*
* @param FuncCall|StaticCall|MethodCall $expr
*/
public function isCallMatchingVariableName(Expr $expr, string $currentName, string $expectedName): bool
{
public function isCallMatchingVariableName(
FuncCall | StaticCall | MethodCall $expr,
string $currentName,
string $expectedName
): bool {
// skip "$call = $method->call();" based conventions
$callName = $this->nodeNameResolver->getName($expr->name);
if ($currentName === $callName) {

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Naming\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
@ -122,10 +121,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param FuncCall|StaticCall|MethodCall $callNode
*/
private function isMultipleCall(Node $callNode): bool
private function isMultipleCall(FuncCall | StaticCall | MethodCall $callNode): bool
{
$parentNode = $callNode->getAttribute(AttributeKey::PARENT_NODE);
@ -207,10 +203,7 @@ CODE_SAMPLE
);
}
/**
* @param StaticCall|MethodCall|FuncCall $expr
*/
private function isClassTypeWithChildren(Expr $expr): bool
private function isClassTypeWithChildren(StaticCall | MethodCall | FuncCall $expr): bool
{
$callStaticType = $this->getStaticType($expr);
$callStaticType = $this->typeUnwrapper->unwrapNullableType($callStaticType);

View File

@ -120,11 +120,8 @@ CODE_SAMPLE
return $node;
}
/**
* @param Class_|Trait_ $classLike
*/
private function getSortedAndOriginalClassMethods(
ClassLike $classLike
Class_ | Trait_ $classLike
): SortedClassMethodsAndOriginalClassMethods {
return new SortedClassMethodsAndOriginalClassMethods(
$this->getLocalPrivateMethodCallOrder($classLike),

View File

@ -81,10 +81,9 @@ CODE_SAMPLE
}
/**
* @param StaticCall|MethodCall $node
* @param array<int, mixed> $defaultValuesByPosition
*/
private function refactorArgs(Node $node, array $defaultValuesByPosition): void
private function refactorArgs(StaticCall | MethodCall $node, array $defaultValuesByPosition): void
{
foreach ($defaultValuesByPosition as $position => $defaultValue) {
// value is already set
@ -104,10 +103,7 @@ CODE_SAMPLE
}
}
/**
* @param StaticCall|MethodCall $node
*/
private function isCallerObjectType(Node $node, ObjectType $objectType): bool
private function isCallerObjectType(StaticCall | MethodCall $node, ObjectType $objectType): bool
{
return $this->isObjectType($node instanceof MethodCall ? $node->var : $node->class, $objectType);
}

View File

@ -162,10 +162,7 @@ CODE_SAMPLE
return $nodeToReturn;
}
/**
* @param Namespace_|FileWithoutNamespace $mainNode
*/
private function printNewNodes(ClassLike $classLike, Node $mainNode): void
private function printNewNodes(ClassLike $classLike, Namespace_ | FileWithoutNamespace $mainNode): void
{
$smartFileInfo = $this->file->getSmartFileInfo();

View File

@ -7,7 +7,6 @@ namespace Rector\Php54\Rector\Break_;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Continue_;
use PHPStan\Type\Constant\ConstantIntegerType;
@ -100,10 +99,7 @@ CODE_SAMPLE
return null;
}
/**
* @param Break_|Continue_ $stmt
*/
private function processVariableNum(Stmt $stmt, Variable $numVariable): ?Node
private function processVariableNum(Break_ | Continue_ $stmt, Variable $numVariable): ?Node
{
$staticType = $this->getStaticType($numVariable);

View File

@ -119,10 +119,7 @@ CODE_SAMPLE
return $assign;
}
/**
* @param PropertyFetch|StaticPropertyFetch $propertyFetchExpr
*/
private function refactorPropertyFetch(Expr $propertyFetchExpr): bool
private function refactorPropertyFetch(PropertyFetch | StaticPropertyFetch $propertyFetchExpr): bool
{
foreach ($this->emptyStringProperties as $emptyStringProperty) {
if (! $this->nodeNameResolver->areNamesEqual($emptyStringProperty, $propertyFetchExpr)) {
@ -136,10 +133,7 @@ CODE_SAMPLE
return false;
}
/**
* @param Variable|PropertyFetch|StaticPropertyFetch|Expr $expr
*/
private function processVariable(Assign $assign, Expr $expr): bool
private function processVariable(Assign $assign, Variable | PropertyFetch | StaticPropertyFetch | Expr $expr): bool
{
if ($this->shouldSkipVariable($expr)) {
return true;

View File

@ -130,10 +130,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param LNumber|DNumber $node
*/
private function shouldSkip(Node $node, string $numericValueAsString): bool
private function shouldSkip(LNumber | DNumber $node, string $numericValueAsString): bool
{
/** @var int $startToken */
$startToken = $node->getAttribute(AttributeKey::START_TOKEN_POSITION);

View File

@ -192,10 +192,7 @@ CODE_SAMPLE
return true;
}
/**
* @param Name|NullableType|PhpParserUnionType $node
*/
private function shouldSkipNonClassLikeType(Node $node): bool
private function shouldSkipNonClassLikeType(Name | NullableType | PhpParserUnionType $node): bool
{
// unwrap nullable type
if ($node instanceof NullableType) {

View File

@ -111,10 +111,6 @@ CODE_SAMPLE
}
foreach ($functionLike->getParams() as $param) {
if ($param->type !== null) {
continue;
}
/** @var string $paramName */
$paramName = $this->getName($param->var);
$paramType = $phpDocInfo->getParamType($paramName);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php80\Rector\NotIdentical;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
@ -85,10 +84,7 @@ CODE_SAMPLE
return $funcCall;
}
/**
* @param Identical|NotIdentical $expr
*/
private function matchIdenticalOrNotIdenticalToFalse(Expr $expr): ?FuncCall
private function matchIdenticalOrNotIdenticalToFalse(Identical | NotIdentical $expr): ?FuncCall
{
if ($this->valueResolver->isFalse($expr->left)) {
if (! $expr->right instanceof FuncCall) {

View File

@ -40,18 +40,12 @@ final class VisibilityManipulator
$node->flags -= Class_::MODIFIER_STATIC;
}
/**
* @param Class_|ClassMethod $node
*/
public function makeFinal(Node $node): void
public function makeFinal(Class_ | ClassMethod $node): void
{
$this->addVisibilityFlag($node, Visibility::FINAL);
}
/**
* @param Class_|ClassMethod $node
*/
public function makeNonFinal(Node $node): void
public function makeNonFinal(Class_ | ClassMethod $node): void
{
if (! $node->isFinal()) {
return;
@ -62,10 +56,8 @@ final class VisibilityManipulator
/**
* This way "abstract", "static", "final" are kept
*
* @param ClassMethod|Property|ClassConst $node
*/
public function removeVisibility(Node $node): void
public function removeVisibility(ClassMethod | Property | ClassConst $node): void
{
$this->ensureIsClassMethodOrProperty($node, __METHOD__);
@ -87,10 +79,7 @@ final class VisibilityManipulator
}
}
/**
* @param ClassMethod|Property|ClassConst $node
*/
public function changeNodeVisibility(Node $node, int $visibility): void
public function changeNodeVisibility(ClassMethod | Property | ClassConst $node, int $visibility): void
{
Assert::oneOf($visibility, [
Visibility::PUBLIC,
@ -104,26 +93,17 @@ final class VisibilityManipulator
$this->replaceVisibilityFlag($node, $visibility);
}
/**
* @param ClassMethod|Property|ClassConst $node
*/
public function makePublic(Node $node): void
public function makePublic(ClassMethod | Property | ClassConst $node): void
{
$this->replaceVisibilityFlag($node, Visibility::PUBLIC);
}
/**
* @param ClassMethod|Property|ClassConst $node
*/
public function makeProtected(Node $node): void
public function makeProtected(ClassMethod | Property | ClassConst $node): void
{
$this->replaceVisibilityFlag($node, Visibility::PROTECTED);
}
/**
* @param ClassMethod|Property|ClassConst $node
*/
public function makePrivate(Node $node): void
public function makePrivate(ClassMethod | Property | ClassConst $node): void
{
$this->replaceVisibilityFlag($node, Visibility::PRIVATE);
}
@ -133,10 +113,7 @@ final class VisibilityManipulator
$class->flags -= Class_::MODIFIER_FINAL;
}
/**
* @param Class_|ClassMethod|Property|ClassConst $node
*/
private function addVisibilityFlag(Node $node, int $visibility): void
private function addVisibilityFlag(Class_ | ClassMethod | Property | ClassConst $node, int $visibility): void
{
$this->ensureIsClassMethodOrProperty($node, __METHOD__);
$node->flags |= $visibility;
@ -158,10 +135,7 @@ final class VisibilityManipulator
));
}
/**
* @param ClassMethod|Property|ClassConst $node
*/
private function replaceVisibilityFlag(Node $node, int $visibility): void
private function replaceVisibilityFlag(ClassMethod | Property | ClassConst $node, int $visibility): void
{
$isStatic = $node instanceof ClassMethod && $node->isStatic();
if ($isStatic) {

View File

@ -96,11 +96,10 @@ CODE_SAMPLE
$this->removedArguments = $removedArguments;
}
/**
* @param ClassMethod|StaticCall|MethodCall $node
*/
private function processPosition(Node $node, ArgumentRemover $argumentRemover): void
{
private function processPosition(
ClassMethod | StaticCall | MethodCall $node,
ArgumentRemover $argumentRemover
): void {
if ($argumentRemover->getValue() === null) {
if ($node instanceof MethodCall || $node instanceof StaticCall) {
$this->nodeRemover->removeArg($node, $argumentRemover->getPosition());
@ -131,10 +130,7 @@ CODE_SAMPLE
}
}
/**
* @param ClassMethod|StaticCall|MethodCall $node
*/
private function removeByName(Node $node, int $position, string $name): void
private function removeByName(ClassMethod | StaticCall | MethodCall $node, int $position, string $name): void
{
if ($node instanceof MethodCall || $node instanceof StaticCall) {
if (isset($node->args[$position]) && $this->isName($node->args[$position], $name)) {

View File

@ -55,11 +55,9 @@ final class IdentifierManipulator
$node->name = new Identifier($newName);
}
/**
* @param ClassConstFetch|MethodCall|PropertyFetch|StaticCall|ClassMethod $node
*/
private function resolveOldMethodName(Node $node): ?string
{
private function resolveOldMethodName(
ClassConstFetch | MethodCall | PropertyFetch | StaticCall | ClassMethod $node
): ?string {
if ($node instanceof StaticCall || $node instanceof MethodCall) {
return $this->nodeNameResolver->getName($node->name);
}

View File

@ -155,10 +155,9 @@ CODE_SAMPLE
}
/**
* @param Name|Identifier $node
* @return Name|Identifier
*/
private function processNameOrIdentifier(Node $node): ?Node
private function processNameOrIdentifier(Name | Identifier $node): ?Node
{
// no name → skip
if ($node->toString() === '') {

View File

@ -129,11 +129,10 @@ CODE_SAMPLE
$this->methodCallRenameCollector->addMethodCallRenames($methodCallRenames);
}
/**
* @param MethodCall|StaticCall|ClassMethod $node
*/
private function skipClassMethod(Node $node, MethodCallRenameInterface $methodCallRename): bool
{
private function skipClassMethod(
MethodCall | StaticCall | ClassMethod $node,
MethodCallRenameInterface $methodCallRename
): bool {
if (! $node instanceof ClassMethod) {
return false;
}

View File

@ -7,7 +7,6 @@ namespace Rector\Transform\NodeAnalyzer;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
@ -31,12 +30,9 @@ final class FuncCallStaticCallToMethodCallAnalyzer
) {
}
/**
* @param ClassMethod|Function_ $functionLike
*/
public function matchTypeProvidingExpr(
Class_ $class,
FunctionLike $functionLike,
ClassMethod | Function_ $functionLike,
ObjectType $objectType
): MethodCall | PropertyFetch | Variable {
$expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass(
@ -58,13 +54,10 @@ final class FuncCallStaticCallToMethodCallAnalyzer
return $this->propertyFetchFactory->createFromType($objectType);
}
/**
* @param ClassMethod|Function_ $functionLike
*/
private function addClassMethodParamForVariable(
Variable $variable,
ObjectType $objectType,
FunctionLike $functionLike
ClassMethod | Function_ $functionLike
): void {
/** @var string $variableName */
$variableName = $this->nodeNameResolver->getName($variable);

View File

@ -38,12 +38,11 @@ final class TypeProvidingExprFromClassResolver
}
/**
* @param ClassMethod|Function_ $functionLike
* @return MethodCall|PropertyFetch|Variable|null
*/
public function resolveTypeProvidingExprFromClass(
Class_ $class,
FunctionLike $functionLike,
ClassMethod | Function_ $functionLike,
ObjectType $objectType
): ?Expr {
$className = $class->getAttribute(AttributeKey::CLASS_NAME);

View File

@ -153,13 +153,10 @@ CODE_SAMPLE
return $stmts;
}
/**
* @param Namespace_|FileWithoutNamespace $node
*/
private function printStaticMethodClass(
SmartFileInfo $smartFileInfo,
string $shortClassName,
Node $node,
Namespace_ | FileWithoutNamespace $node,
Class_ $class
): void {
$classFileDestination = $smartFileInfo->getPath() . DIRECTORY_SEPARATOR . $shortClassName . '.php';
@ -170,10 +167,7 @@ CODE_SAMPLE
$this->removedAndAddedFilesCollector->addAddedFile($addedFileWithNodes);
}
/**
* @param Namespace_|FileWithoutNamespace $node
*/
private function resolveNodeToPrint(Node $node, Class_ $class): Namespace_ | Class_
private function resolveNodeToPrint(Namespace_ | FileWithoutNamespace $node, Class_ $class): Namespace_ | Class_
{
if ($node instanceof Namespace_) {
return new Namespace_($node->name, [$class]);

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\TypeDeclaration\ChildPopulator;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
@ -29,10 +28,12 @@ final class ChildParamPopulator
/**
* Add typehint to all children
* @param ClassMethod|Function_ $functionLike
*/
public function populateChildClassMethod(FunctionLike $functionLike, int $position, Type $paramType): void
{
public function populateChildClassMethod(
ClassMethod | Function_ $functionLike,
int $position,
Type $paramType
): void {
if (! $functionLike instanceof ClassMethod) {
return;
}

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\TypeDeclaration\PhpDocParser;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
@ -53,10 +52,7 @@ final class NonInformativeReturnTagRemover
) {
}
/**
* @param ClassMethod|Function_ $functionLike
*/
public function removeReturnTagIfNotUseful(FunctionLike $functionLike): void
public function removeReturnTagIfNotUseful(ClassMethod | Function_ $functionLike): void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);

View File

@ -18,12 +18,10 @@ final class PhpParserTypeAnalyzer
) {
}
/**
* @param Name|NullableType|UnionType|Identifier $possibleSubtype
* @param Name|NullableType|UnionType|Identifier $possibleParentType
*/
public function isCovariantSubtypeOf(Node $possibleSubtype, Node $possibleParentType): bool
{
public function isCovariantSubtypeOf(
Name | NullableType | UnionType | Identifier $possibleSubtype,
Name | NullableType | UnionType | Identifier $possibleParentType
): bool {
// skip until PHP 8 is out
if ($this->isUnionType($possibleSubtype, $possibleParentType)) {
return false;

View File

@ -6,7 +6,6 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
@ -123,10 +122,7 @@ CODE_SAMPLE
return $node->returnType && $this->isName($node->returnType, 'never');
}
/**
* @param ClassMethod|Function_ $functionLike
*/
private function resolveHasNeverFuncCall(FunctionLike $functionLike): bool
private function resolveHasNeverFuncCall(ClassMethod | Function_ $functionLike): bool
{
$hasNeverType = false;

View File

@ -116,11 +116,8 @@ CODE_SAMPLE
return null;
}
/**
* @param ClassMethod|Function_|Closure $node
*/
private function processSingleUnionType(
Node $node,
ClassMethod | Function_ | Closure $node,
UnionType $unionType,
NullableType $nullableType
): Closure | ClassMethod | Function_ {

View File

@ -136,10 +136,7 @@ CODE_SAMPLE
return null;
}
/**
* @param ClassMethod|Function_ $functionLike
*/
private function refactorParam(Param $param, FunctionLike $functionLike, int $position): void
private function refactorParam(Param $param, ClassMethod | Function_ $functionLike, int $position): void
{
if ($this->shouldSkipParam($param, $functionLike)) {
return;

View File

@ -124,10 +124,7 @@ CODE_SAMPLE
return $this->processType($node, $inferedReturnType);
}
/**
* @param ClassMethod|Function_ $node
*/
private function processType(Node $node, Type $inferedType): ?Node
private function processType(ClassMethod | Function_ $node, Type $inferedType): ?Node
{
$inferredReturnNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
$inferedType,
@ -169,10 +166,7 @@ CODE_SAMPLE
return $this->vendorLockResolver->isReturnChangeVendorLockedIn($classMethod);
}
/**
* @param ClassMethod|Function_ $functionLike
*/
private function shouldSkipInferredReturnNode(FunctionLike $functionLike): bool
private function shouldSkipInferredReturnNode(ClassMethod | Function_ $functionLike): bool
{
// already overridden by previous populateChild() method run
if ($functionLike->returnType === null) {
@ -182,10 +176,7 @@ CODE_SAMPLE
return (bool) $functionLike->returnType->getAttribute(AttributeKey::DO_NOT_CHANGE);
}
/**
* @param ClassMethod|Function_ $functionLike
*/
private function shouldSkipExistingReturnType(FunctionLike $functionLike, Type $inferedType): bool
private function shouldSkipExistingReturnType(ClassMethod | Function_ $functionLike, Type $inferedType): bool
{
if ($functionLike->returnType === null) {
return false;
@ -205,12 +196,10 @@ CODE_SAMPLE
return $this->isNullableTypeSubType($currentType, $inferedType);
}
/**
* @param ClassMethod|Function_ $functionLike
* @param Name|NullableType|PhpParserUnionType $inferredReturnNode
*/
private function addReturnType(FunctionLike $functionLike, Node $inferredReturnNode): void
{
private function addReturnType(
ClassMethod | Function_ $functionLike,
Name | NullableType | PhpParserUnionType $inferredReturnNode
): void {
if ($this->isExternalVoid($functionLike, $inferredReturnNode)) {
return;
}
@ -232,12 +221,10 @@ CODE_SAMPLE
}
}
/**
* @param ClassMethod|Function_ $functionLike
* @param Name|NullableType|PhpParserUnionType $inferredReturnNode
*/
private function isExternalVoid(FunctionLike $functionLike, Node $inferredReturnNode): bool
{
private function isExternalVoid(
ClassMethod | Function_ $functionLike,
Name | NullableType | PhpParserUnionType $inferredReturnNode
): bool {
$classLike = $functionLike->getAttribute(AttributeKey::CLASS_NODE);
if (! $classLike instanceof Class_) {
return false;

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\TypeDeclaration\TypeAlreadyAddedChecker;
use Iterator;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
@ -42,10 +40,7 @@ final class ReturnTypeAlreadyAddedChecker
) {
}
/**
* @param ClassMethod|Function_ $functionLike
*/
public function isSameOrBetterReturnTypeAlreadyAdded(FunctionLike $functionLike, Type $returnType): bool
public function isSameOrBetterReturnTypeAlreadyAdded(ClassMethod | Function_ $functionLike, Type $returnType): bool
{
$nodeReturnType = $functionLike->returnType;
@ -95,11 +90,10 @@ final class ReturnTypeAlreadyAddedChecker
return $nodeContentWithoutPreslash === $className;
}
/**
* @param Identifier|Name|NullableType|PhpParserUnionType $returnTypeNode
*/
private function isArrayIterableIteratorCoType(Node $returnTypeNode, Type $returnType): bool
{
private function isArrayIterableIteratorCoType(
Identifier | Name | NullableType | PhpParserUnionType $returnTypeNode,
Type $returnType
): bool {
if (! $this->nodeNameResolver->isNames($returnTypeNode, self::FOREACHABLE_TYPES)) {
return false;
}
@ -107,11 +101,10 @@ final class ReturnTypeAlreadyAddedChecker
return $this->isStaticTypeIterable($returnType);
}
/**
* @param Identifier|Name|NullableType|PhpParserUnionType $returnTypeNode
*/
private function isUnionCoType(Node $returnTypeNode, Type $type): bool
{
private function isUnionCoType(
Identifier | Name | NullableType | PhpParserUnionType $returnTypeNode,
Type $type
): bool {
if (! $type instanceof UnionType) {
return false;
}

View File

@ -6,7 +6,6 @@ namespace Rector\TypeDeclaration\TypeInferer;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
@ -66,10 +65,7 @@ final class SilentVoidResolver
return true;
}
/**
* @param ClassMethod|Closure|Function_ $functionLike
*/
public function hasSilentVoid(FunctionLike $functionLike): bool
public function hasSilentVoid(ClassMethod | Closure | Function_ $functionLike): bool
{
if ($this->hasStmtsAlwaysReturn((array) $functionLike->stmts)) {
return false;
@ -149,9 +145,8 @@ final class SilentVoidResolver
/**
* @see https://phpstan.org/writing-php-code/phpdoc-types#bottom-type
* @param ClassMethod|Closure|Function_ $functionLike
*/
private function hasNeverType(FunctionLike $functionLike): bool
private function hasNeverType(ClassMethod | Closure | Function_ $functionLike): bool
{
return $this->betterNodeFinder->hasInstancesOf($functionLike, [Throw_::class]);
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Core\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
@ -69,10 +68,7 @@ final class PropertyFetchAnalyzer
});
}
/**
* @param PropertyFetch|StaticPropertyFetch $expr
*/
public function isPropertyToSelf(Expr $expr): bool
public function isPropertyToSelf(PropertyFetch | StaticPropertyFetch $expr): bool
{
if ($expr instanceof PropertyFetch && ! $this->nodeNameResolver->isName($expr->var, 'this')) {
return false;

View File

@ -29,10 +29,7 @@ final class ClassInsertManipulator
) {
}
/**
* @param ClassMethod|Property|ClassConst|ClassMethod $stmt
*/
public function addAsFirstMethod(Class_ $class, Stmt $stmt): void
public function addAsFirstMethod(Class_ $class, Property | ClassConst | ClassMethod $stmt): void
{
if ($this->isSuccessToInsertBeforeFirstMethod($class, $stmt)) {
return;

View File

@ -7,7 +7,6 @@ namespace Rector\Core\NodeManipulator;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
@ -27,10 +26,9 @@ final class ClassManipulator
/**
* @deprecated
* @param Class_|Trait_ $classLike
* @return array<string, Name>
*/
public function getUsedTraits(ClassLike $classLike): array
public function getUsedTraits(Class_ | Trait_ $classLike): array
{
$usedTraits = [];
foreach ($classLike->getTraitUses() as $traitUse) {
@ -118,10 +116,9 @@ final class ClassManipulator
}
/**
* @param Class_|Interface_ $classLike
* @return string[]
*/
public function getClassLikeNodeParentInterfaceNames(ClassLike $classLike): array
public function getClassLikeNodeParentInterfaceNames(Class_ | Interface_ $classLike): array
{
if ($classLike instanceof Class_) {
return $this->nodeNameResolver->getNames($classLike->implements);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Core\NodeManipulator;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PHPStan\Analyser\Scope;
@ -32,10 +31,7 @@ final class MagicPropertyFetchAnalyzer
) {
}
/**
* @param PropertyFetch|Node\Expr\StaticPropertyFetch $expr
*/
public function isMagicOnType(Expr $expr, Type $type): bool
public function isMagicOnType(PropertyFetch | StaticPropertyFetch $expr, Type $type): bool
{
$varNodeType = $this->nodeTypeResolver->resolve($expr);
@ -59,10 +55,7 @@ final class MagicPropertyFetchAnalyzer
return ! $this->hasPublicProperty($expr, $nodeName);
}
/**
* @param PropertyFetch|StaticPropertyFetch $expr
*/
private function hasPublicProperty(Expr $expr, string $propertyName): bool
private function hasPublicProperty(PropertyFetch | StaticPropertyFetch $expr, string $propertyName): bool
{
$scope = $expr->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {

View File

@ -88,10 +88,7 @@ final class PropertyManipulator
return false;
}
/**
* @param PropertyFetch|StaticPropertyFetch $expr
*/
private function isChangeableContext(Expr $expr): bool
private function isChangeableContext(PropertyFetch | StaticPropertyFetch $expr): bool
{
$parent = $expr->getAttribute(AttributeKey::PARENT_NODE);
if (! $parent instanceof Node) {