diff --git a/phpstan.neon b/phpstan.neon index dcbccd314ad..b74dc43f8cb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -92,7 +92,10 @@ parameters: - src/StaticTypeMapper/ValueObject/Type/*Type.php # generics nullable bugs - - '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#' + - + message: '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#' + path: src/PhpParser/Node/BetterNodeFinder.php + - '#Method (.*?) should return array but returns array#' - '#Property Rector\\PhpParser\\Node\\AssignAndBinaryMap\:\:\$binaryOpToAssignClasses \(array, class\-string\>\) does not accept array#' @@ -121,6 +124,8 @@ parameters: # array_index on generic types - '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory\:\:uniquateTypes\(\) should return array but returns array#' + - '#Method Rector\\Arguments\\ArgumentDefaultValueReplacer\:\:processReplaces\(\) should return \(TCall of PhpParser\\Node\\Expr\\FuncCall\|PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\New_\|PhpParser\\Node\\Expr\\StaticCall\|PhpParser\\Node\\Stmt\\ClassMethod\)\|null but returns PhpParser\\Node\\Stmt\\ClassMethod\|null#' + # native filesystem calls, required for performance reasons - message: '#"@\\unlink\(\$tmpPath\)" is forbidden to use#' @@ -160,9 +165,6 @@ parameters: - rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php - src/PhpParser/NodeTransformer.php - # impossible to validate json string is a class-string - - '#Parameter \#1 \$rectorClass of class Rector\\ChangesReporting\\ValueObject\\RectorWithLineChange constructor expects class\-string\|Rector\\Contract\\Rector\\RectorInterface, string given#' - # mapper re-use - '#Parameter \#1 \$type of method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ObjectWithoutClassTypeMapper\:\:mapToPhpParserNode\(\) expects PHPStan\\Type\\ObjectWithoutClassType, PHPStan\\Type\\Accessory\\Has(Property|Method)Type given#' diff --git a/rules/Arguments/ArgumentDefaultValueReplacer.php b/rules/Arguments/ArgumentDefaultValueReplacer.php index 8e07d0f51a2..570c3e9163b 100644 --- a/rules/Arguments/ArgumentDefaultValueReplacer.php +++ b/rules/Arguments/ArgumentDefaultValueReplacer.php @@ -5,7 +5,6 @@ namespace Rector\Arguments; use PhpParser\BuilderHelpers; -use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ClassConstFetch; @@ -27,10 +26,16 @@ public function __construct( ) { } + /** + * @template TCall as (MethodCall|StaticCall|ClassMethod|FuncCall|New_) + * + * @param TCall $node + * @return TCall|null + */ public function processReplaces( MethodCall | StaticCall | ClassMethod | FuncCall | New_ $node, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue - ): ?Node { + ): MethodCall | StaticCall | ClassMethod | FuncCall | New_ |null { if ($node instanceof ClassMethod) { if (! isset($node->params[$replaceArgumentDefaultValue->getPosition()])) { return null; @@ -82,6 +87,12 @@ private function processParams( return $classMethod; } + /** + * @template TCall as (MethodCall|StaticCall|FuncCall|New_) + * + * @param TCall $expr + * @return TCall|null + */ private function processArgs( MethodCall | StaticCall | FuncCall | New_ $expr, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index debab26ff44..16579d3ea5f 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -45,6 +45,7 @@ public function __construct( /** * @param array $oldToNewClasses + * @return ($node is FullyQualified ? FullyQualified : Node) */ public function renameNode(Node $node, array $oldToNewClasses, ?Scope $scope): ?Node { diff --git a/src/ChangesReporting/ValueObject/RectorWithLineChange.php b/src/ChangesReporting/ValueObject/RectorWithLineChange.php index 83f00dec292..5ea9f462b76 100644 --- a/src/ChangesReporting/ValueObject/RectorWithLineChange.php +++ b/src/ChangesReporting/ValueObject/RectorWithLineChange.php @@ -52,6 +52,7 @@ public function getRectorClass(): string */ public static function decode(array $json): self { + /** @var class-string $rectorClass */ $rectorClass = $json[self::KEY_RECTOR_CLASS]; Assert::string($rectorClass); diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php index 8f1c4768dbb..6631d244355 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php @@ -155,8 +155,10 @@ private function resolveNullableType(NullableType $nullableType): null|NullableT /** * @param TypeKind::* $typeKind */ - private function mapNullabledType(Type $nullabledType, string $typeKind): ?Node - { + private function mapNullabledType( + Type $nullabledType, + string $typeKind + ): NullableType|ComplexType|PhpParserUnionType|null { // void cannot be nullable if ($nullabledType->isVoid()->yes()) { return null; diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index dba0c0661cb..35f2677976d 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeFinder; @@ -134,7 +133,7 @@ public function find(Node | array $nodes, callable $filter): array /** * @api symfony * @param Node[] $nodes - * @return ClassLike|null + * @return Class_|null */ public function findFirstNonAnonymousClass(array $nodes): ?Node { diff --git a/tests/NodeTypeResolver/StaticTypeMapper/StaticTypeMapperTest.php b/tests/NodeTypeResolver/StaticTypeMapper/StaticTypeMapperTest.php index 59472581c73..63031789556 100644 --- a/tests/NodeTypeResolver/StaticTypeMapper/StaticTypeMapperTest.php +++ b/tests/NodeTypeResolver/StaticTypeMapper/StaticTypeMapperTest.php @@ -4,7 +4,6 @@ namespace Rector\Tests\NodeTypeResolver\StaticTypeMapper; -use PHPStan\Type\Type; use Iterator; use PhpParser\Node; use PhpParser\Node\Identifier; @@ -17,6 +16,7 @@ use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; +use PHPStan\Type\Type; use PHPUnit\Framework\Attributes\DataProvider; use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\Testing\PHPUnit\AbstractLazyTestCase;