Skip to content

Commit a57295c

Browse files
authored
[CodeQuality] Keep param/return with description on TypeNullableEntityFromDocblockRector (#460)
1 parent 17bd644 commit a57295c

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\TypeNullableEntityFromDocblockRector\Fixture;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
class DocblockEntityWithParamReturnDescription
11+
{
12+
/**
13+
* @var string
14+
* @ORM\Id
15+
* @ORM\Column(type="string")
16+
* @ORM\GeneratedValue
17+
*/
18+
private $name;
19+
20+
/**
21+
* @return string some description
22+
*/
23+
public function getName()
24+
{
25+
return $this->name;
26+
}
27+
28+
/**
29+
* @param string $name some description
30+
*/
31+
public function setName($name): void
32+
{
33+
$this->name = $name;
34+
}
35+
}
36+
37+
38+
?>
39+
-----
40+
<?php
41+
42+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\TypeNullableEntityFromDocblockRector\Fixture;
43+
44+
use Doctrine\ORM\Mapping as ORM;
45+
46+
/**
47+
* @ORM\Entity()
48+
*/
49+
class DocblockEntityWithParamReturnDescription
50+
{
51+
/**
52+
* @ORM\Id
53+
* @ORM\Column(type="string")
54+
* @ORM\GeneratedValue
55+
*/
56+
private ?string $name = null;
57+
58+
/**
59+
* @return string some description
60+
*/
61+
public function getName(): ?string
62+
{
63+
return $this->name;
64+
}
65+
66+
/**
67+
* @param string $name some description
68+
*/
69+
public function setName(?string $name): void
70+
{
71+
$this->name = $name;
72+
}
73+
}
74+
75+
76+
?>

rules/CodeQuality/Rector/Class_/TypeNullableEntityFromDocblockRector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ private function removeParamDocblock(ClassMethod $classMethod): void
267267
return;
268268
}
269269

270+
$paramTagValueNode = $classMethodPhpDocInfo->getParamTagValueNodes()[0] ?? null;
271+
if ($paramTagValueNode instanceof ParamTagValueNode && $paramTagValueNode->description !== '') {
272+
return;
273+
}
274+
270275
$classMethodPhpDocInfo->removeByType(ParamTagValueNode::class);
271276
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
272277
}
@@ -282,6 +287,10 @@ private function removeReturnDocblock(ClassMethod $classMethod): void
282287
return;
283288
}
284289

290+
if ($classMethodPhpDocInfo->getReturnTagValue()->description !== '') {
291+
return;
292+
}
293+
285294
$classMethodPhpDocInfo->removeByType(ReturnTagValueNode::class);
286295
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
287296
}

0 commit comments

Comments
 (0)