Skip to content

Commit

Permalink
[DeadCode] Remove union with interface on RemoveUselessParamTagRector…
Browse files Browse the repository at this point in the history
… to make it consistent (#5794)

* [DeadCode] Remove union with interface on RemoveUselessParamTagRector

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Apr 3, 2024
1 parent 8bce424 commit f889e41
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\F
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeClass;

class SkipUnionOfInterface {
class UnionOfInterface {
/**
* @param SomeClass|SomeInterface $someInterface
*/
Expand All @@ -18,3 +18,25 @@ class SkipUnionOfInterface {
}
}
}

?>
-----
<?php

declare(strict_types = 1);

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

use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeClass;

class UnionOfInterface {
public function run(SomeInterface $someInterface)
{
if (method_exists($someInterface, 'run')) {
$someInterface->run();
}
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

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

use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeClass;

class UnionOfInterface {
/**
* Some comment
*
* @param SomeClass|SomeInterface $someInterface
*/
public function run(SomeInterface $someInterface)
{
if (method_exists($someInterface, 'run')) {
$someInterface->run();
}
}
}

?>
-----
<?php

declare(strict_types = 1);

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

use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeInterface;
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeClass;

class UnionOfInterface {
/**
* Some comment
*/
public function run(SomeInterface $someInterface)
{
if (method_exists($someInterface, 'run')) {
$someInterface->run();
}
}
}

?>
6 changes: 0 additions & 6 deletions src/NodeTypeResolver/TypeComparator/TypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Rector\NodeTypeResolver\TypeComparator;

use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Reflection\ClassReflection;
Expand Down Expand Up @@ -83,10 +81,6 @@ public function arePhpParserAndPhpStanPhpDocTypesEqual(
TypeNode $phpStanDocTypeNode,
Node $node
): bool {
if ($phpStanDocTypeNode instanceof UnionTypeNode && $phpParserNode instanceof FullyQualified) {
return false;
}

$phpParserNodeType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($phpParserNode);
$phpStanDocType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType(
$phpStanDocTypeNode,
Expand Down

0 comments on commit f889e41

Please sign in to comment.