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
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture;

trait OnTrait
{
public function __construct(public float $value = 0.0)
{
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture;

trait OnTrait
{
public float $value = 0.0;
public function __construct(float $value = 0.0)
{
$this->value = $value;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
Expand Down Expand Up @@ -75,11 +76,11 @@ public function __construct(float $value = 0.0)
*/
public function getNodeTypes(): array
{
return [Class_::class];
return [Class_::class, Trait_::class];
}

/**
* @param Class_ $node
* @param Class_|Trait_ $node
*/
public function refactor(Node $node): ?Node
{
Expand Down Expand Up @@ -163,7 +164,7 @@ private function setParamAttrGroupAsComment(Param $param): void
private function resolvePropertiesFromPromotedParams(
ClassMethod $classMethod,
array $promotedParams,
Class_ $class
Class_|Trait_ $class
): array {
$properties = $this->createPropertiesFromParams($classMethod, $promotedParams);
$class->stmts = array_merge($properties, $class->stmts);
Expand All @@ -177,7 +178,7 @@ private function resolvePropertiesFromPromotedParams(
*/
private function addPropertyAssignsToConstructorClassMethod(
array $properties,
Class_ $class,
Class_|Trait_ $class,
array $oldComments
): void {
$assigns = [];
Expand Down
Loading