Skip to content

Commit

Permalink
[Php81] Merge attributes on NewInInitializerRector (#3546)
Browse files Browse the repository at this point in the history
* Add failing test fixture for NewInInitializerRector

# Failing Test for NewInInitializerRector

Based on https://getrector.com/demo/dd5bff80-0789-4aae-b2a3-686c23a3d164

* Update property_with_attributes.php.inc

* Closes #3516

---------

Co-authored-by: Leo Viezens <leo.viezens@web.de>
  • Loading branch information
samsonasik and LeoVie committed May 8, 2023
1 parent 8aa976c commit e145ef2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

#[ORM\Entity]
class Carrier
{
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
private Ulid $id;

public function __construct(
?Ulid $id = null,
) {
$this->id = $id ?? new Ulid();
}
}

?>
-----
<?php

namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

#[ORM\Entity]
class Carrier
{
public function __construct(#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
private Ulid $id = new Ulid())
{
}
}

?>
1 change: 1 addition & 0 deletions rules/Php81/Rector/ClassMethod/NewInInitializerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private function processPropertyPromotion(ClassMethod $classMethod, Param $param
}

$param->flags = $property->flags;
$param->attrGroups = array_merge($property->attrGroups, $param->attrGroups);
$this->removeNode($property);
}

Expand Down

0 comments on commit e145ef2

Please sign in to comment.