-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Skip nullable @ template on RemoveUselessReturnTagRector (#…
- Loading branch information
1 parent
1afc647
commit afe7c46
Showing
6 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...ector/ClassMethod/RemoveUselessReturnTagRector/Fixture/skip_nullable_template_tag.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Fixture; | ||
|
||
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Source\Performance; | ||
|
||
/** | ||
* @template TPerformance of Performance | ||
*/ | ||
interface SkipNullableTemplateTag { | ||
/** @return TPerformance|null */ | ||
public function performance(): Performance|null; | ||
} |
5 changes: 5 additions & 0 deletions
5
rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector/Source/Performance.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Source; | ||
|
||
interface Performance {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DeadCode\PhpDoc\Guard; | ||
|
||
use PHPStan\Type\Type; | ||
use PHPStan\Type\UnionType; | ||
use PHPStan\Type\Generic\TemplateType; | ||
|
||
final class TemplateTypeRemovalGuard | ||
{ | ||
public function isLegal(Type $docType): bool | ||
{ | ||
// cover direct \PHPStan\Type\Generic\TemplateUnionType | ||
if ($docType instanceof TemplateType) { | ||
return false; | ||
} | ||
|
||
// cover mixed template with mix from @template and non @template | ||
$types = $docType instanceof UnionType | ||
? $docType->getTypes() | ||
: [$docType]; | ||
|
||
foreach ($types as $type) { | ||
if ($type instanceof TemplateType) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |