Skip to content

Commit b17019f

Browse files
authored
[TypeDeclarationDocblocks] Skip reprint docblock on no change on AddParamArrayDocblockFromAssignsParamToParamReferenceRector (#8271)
* [TypeDeclarationDocblocks] Skip reprint docblock on no change on AddParamArrayDocblockFromAssignsParamToParamReferenceRector * eol
1 parent c782801 commit b17019f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromAssignsParamToParamReferenceRector\Fixture;
4+
5+
final class SkipReprintDoc
6+
{
7+
/**
8+
* Recursively traverse the Tiptap document tree to find user mentions
9+
*
10+
* @param array|null $node The current node to check
11+
* @param mixed[] $mentions Array to collect mentions
12+
*/
13+
private function traverseNodes($node, array &$mentions): void
14+
{
15+
if (! $node || ! is_array($node)) {
16+
return;
17+
}
18+
19+
// Check if current node is a user mention
20+
if (isset($node['type']) && $node['type'] === 'userMention' && isset($node['attrs']['user'])) {
21+
$mentions[] = $node['attrs']['user'];
22+
}
23+
24+
// Check content array
25+
if (isset($node['content']) && is_array($node['content'])) {
26+
foreach ($node['content'] as $childNode) {
27+
$this->traverseNodes($childNode, $mentions);
28+
}
29+
}
30+
}
31+
}

‎rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\FunctionLike;
88
use PhpParser\Node\Param;
99
use PhpParser\Node\Stmt\Property;
10+
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
1011
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
1112
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
1213
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
@@ -48,6 +49,11 @@ public function decorateGenericIterableParamType(
4849
return false;
4950
}
5051

52+
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($parameterName);
53+
if ($paramTagValueNode instanceof ParamTagValueNode && (string) $paramTagValueNode->type === (string) $typeNode) {
54+
return false;
55+
}
56+
5157
$this->phpDocTypeChanger->changeParamTypeNode($functionLike, $phpDocInfo, $param, $parameterName, $typeNode);
5258

5359
return true;

0 commit comments

Comments
 (0)