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
11 changes: 11 additions & 0 deletions src/NodeTypeResolver/TypeComparator/TypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\Generic\TemplateObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\UnionType;
use Rector\NodeTypeResolver\PHPStan\TypeHasher;
use Rector\Reflection\ReflectionResolver;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand Down Expand Up @@ -98,6 +101,14 @@ public function arePhpParserAndPhpStanPhpDocTypesEqual(
return false;
}

if ($phpStanDocType instanceof UnionType || $phpStanDocType instanceof IntersectionType) {
foreach ($phpStanDocType->getTypes() as $type) {
if ($type instanceof TemplateObjectType) {
return false;
}
}
}

return $this->isThisTypeInFinalClass($phpStanDocType, $phpParserNodeType, $phpParserNode);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\TemplatedTypeOnParamAndReturn\Fixture;

abstract class Model {}
interface EventInterface {}

/** @template TModel of Model */
abstract class SkipTemplatedTypeOnParamAndReturn
{
/**
* @param TModel&EventInterface $model
* @return TModel&EventInterface
*/
abstract public function run(Model&EventInterface $model): Model&EventInterface;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\TemplatedTypeOnParamAndReturn;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class TemplatedTypeOnParamAndReturnTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;

return RectorConfig::configure()
->withRules([
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class
]);