Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\MethodName;
Expand Down Expand Up @@ -102,17 +101,13 @@ public function refactor(Node $node): ?Node
return null;
}

$hasChangedDoc = false;
$hasChanged = false;
foreach ($node->params as $param) {
if (! $this->visibilityManipulator->isReadonly($param)) {
continue;
}

if ($this->addPhpDocTag($param)) {
$hasChangedDoc = true;
}

$this->addPhpDocTag($param);
$this->visibilityManipulator->removeReadonly($param);
$hasChanged = true;
}
Expand All @@ -121,23 +116,18 @@ public function refactor(Node $node): ?Node
return null;
}

if ($hasChangedDoc) {
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}

return $node;
}

private function addPhpDocTag(Property|Param $node): bool
private function addPhpDocTag(Property|Param $node): void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);

if ($phpDocInfo->hasByName(self::TAGNAME)) {
return false;
return;
}

$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ public function refactor(Node $node): ?ClassMethod
return null;
}

private function addPhpDocTag(Property|Param $node): bool
private function addPhpDocTag(Property|Param $node): void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);

if ($phpDocInfo->hasByName(self::TAGNAME)) {
return false;
return;
}

$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ namespace Rector\Tests\Issues\DowngradeReadonlyClassPropertyToPhp80\Fixture;

final class Fixture
{
public function __construct(
/**
* @readonly
*/
public array $property
)
public function __construct(/**
* @readonly
*/
public array $property)
{
}
}
Expand Down