Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector\Fixture;

/**
* @template TPayload
* @template TDomainId
*/
final class SkipGenericFluentBuilder
{
/**
* @return SkipGenericFluentBuilder<TPayload, TDomainId>
*/
public function withFoo(): self
{
return $this;
}

/**
* @return SkipGenericFluentBuilder<TPayload, TDomainId>
*/
public function withBar(): self
{
return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector\Fixture;

/**
* @template TAdded
* @template TRemoved
*/
final readonly class SkipGenericSelfReturn
{
/**
* @param list<TAdded> $added
* @param list<TRemoved> $removed
*/
private function __construct(
public array $added,
public array $removed,
) {
}

/**
* @param list<TAdded> $added
* @param list<TRemoved> $removed
*
* @return self<TAdded, TRemoved>
*/
public static function create(array $added, array $removed): self
{
return new self($added, $removed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
Expand Down Expand Up @@ -103,6 +104,11 @@ public function refactor(Node $node): ?Node
return null;
}

// keep generic return types, because they carry template info the native type cannot express
if ($returnTagValueNode->type instanceof GenericTypeNode) {
return null;
}

if ($this->isClassTypeAlias($node, $returnTagValueNode)) {
return null;
}
Expand Down
Loading