Skip to content

Commit

Permalink
[TypeDeclaration] Skip generic on ReturnTypeDeclarationRector (#2469)
Browse files Browse the repository at this point in the history
* Add failing test fixture for ReturnTypeDeclarationRector

# Failing Test for ReturnTypeDeclarationRector

The native return type is replaced by the generic type of the pdpdoc, which does not exist.

Based on https://getrector.org/demo/5a20665a-b61f-4923-8b9a-aa9cb5c3a8ea

* Rename failing test

* Add missing namespace

* Closes #2454 Fixes rectorphp/rector#7213

* re-trigger CI

Co-authored-by: François Poguet <francoispoguet@gmail.com>
Co-authored-by: François Poguet <francois.poguet@quarks.pro>
  • Loading branch information
3 people committed Jun 11, 2022
1 parent a5340c6 commit a8dae7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture;

class SkipGeneric
{
private readonly UseCaseBusInterface $useCaseBus;

/**
* @template T
*
* @param UseCaseInterface<T> $useCase
*
* @return T
*/
protected function execute(UseCaseInterface $useCase): mixed
{
return $this->useCaseBus->execute($useCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType;
use Rector\TypeDeclaration\PhpDocParser\NonInformativeReturnTagRemover;
use Rector\TypeDeclaration\PhpParserTypeAnalyzer;
use Rector\TypeDeclaration\TypeAlreadyAddedChecker\ReturnTypeAlreadyAddedChecker;
Expand Down Expand Up @@ -109,7 +110,7 @@ public function refactor(Node $node): ?Node
[ReturnTypeDeclarationReturnTypeInfererTypeInferer::class]
);

if ($inferedReturnType instanceof MixedType) {
if ($inferedReturnType instanceof MixedType || $inferedReturnType instanceof NonExistingObjectType) {
return null;
}

Expand Down

0 comments on commit a8dae7f

Please sign in to comment.