Skip to content

Commit

Permalink
Fix removal of useless @param tag when string|null insteadof ?string …
Browse files Browse the repository at this point in the history
…is used. (#5684)

Fixed by removing the "skip union types" in ParamTagRemover.
This was added to fix a different bug, cause a bug in TypeHasher, where the normalized UnionType was actually overwritten by the last element in the union,

Co-authored-by: Arjen Schol <arjen.schol@lyceo.nl>
  • Loading branch information
arjenschol and Arjen Schol committed Apr 3, 2024
1 parent b925e54 commit 9b4ad93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

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

class WithNullableType
{
/**
* @param string|null $nullable
*/
function foo(?string $nullable)
{
}
}

?>
-----
<?php

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

class WithNullableType
{
function foo(?string $nullable)
{
}
}

?>
5 changes: 0 additions & 5 deletions rules/DeadCode/PhpDoc/TagRemover/ParamTagRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public function removeParamTagsIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $f
return null;
}

// skip union types
if ($docNode->value->type instanceof UnionTypeNode) {
return null;
}

if (! $this->deadParamTagValueNodeAnalyzer->isDead($docNode->value, $functionLike)) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NodeTypeResolver/PHPStan/TypeHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function createUnionTypeHash(UnionType $unionType): string
$normalizedUnionType = clone $unionType;

// change alias to non-alias
$normalizedUnionType = TypeTraverser::map(
TypeTraverser::map(
$normalizedUnionType,
static function (Type $type, callable $callable): Type {
if (! $type instanceof AliasedObjectType && ! $type instanceof ShortenedObjectType) {
Expand Down

0 comments on commit 9b4ad93

Please sign in to comment.