File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed
rules-tests/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector/Fixture
rules/DowngradePhp80/Rector/Class_ Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DowngradePhp80 \Rector \Class_ \DowngradePropertyPromotionRector \Fixture ;
4+
5+ trait OnTrait
6+ {
7+ public function __construct (public float $ value = 0.0 )
8+ {
9+ }
10+ }
11+
12+ ?>
13+ -----
14+ <?php
15+
16+ namespace Rector \Tests \DowngradePhp80 \Rector \Class_ \DowngradePropertyPromotionRector \Fixture ;
17+
18+ trait OnTrait
19+ {
20+ public float $ value = 0.0 ;
21+ public function __construct (float $ value = 0.0 )
22+ {
23+ $ this ->value = $ value ;
24+ }
25+ }
26+
27+ ?>
Original file line number Diff line number Diff line change 1414use PhpParser \Node \Stmt \ClassMethod ;
1515use PhpParser \Node \Stmt \Expression ;
1616use PhpParser \Node \Stmt \Property ;
17+ use PhpParser \Node \Stmt \Trait_ ;
1718use PHPStan \PhpDocParser \Ast \PhpDoc \ParamTagValueNode ;
1819use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfo ;
1920use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
@@ -75,11 +76,11 @@ public function __construct(float $value = 0.0)
7576 */
7677 public function getNodeTypes (): array
7778 {
78- return [Class_::class];
79+ return [Class_::class, Trait_::class ];
7980 }
8081
8182 /**
82- * @param Class_ $node
83+ * @param Class_|Trait_ $node
8384 */
8485 public function refactor (Node $ node ): ?Node
8586 {
@@ -163,7 +164,7 @@ private function setParamAttrGroupAsComment(Param $param): void
163164 private function resolvePropertiesFromPromotedParams (
164165 ClassMethod $ classMethod ,
165166 array $ promotedParams ,
166- Class_ $ class
167+ Class_ | Trait_ $ class
167168 ): array {
168169 $ properties = $ this ->createPropertiesFromParams ($ classMethod , $ promotedParams );
169170 $ class ->stmts = array_merge ($ properties , $ class ->stmts );
@@ -177,7 +178,7 @@ private function resolvePropertiesFromPromotedParams(
177178 */
178179 private function addPropertyAssignsToConstructorClassMethod (
179180 array $ properties ,
180- Class_ $ class ,
181+ Class_ | Trait_ $ class ,
181182 array $ oldComments
182183 ): void {
183184 $ assigns = [];
You can’t perform that action at this time.
0 commit comments