Skip to content

Commit

Permalink
[Transform] Handle Multi Assign on NewToConstructorInjectionRector (#714
Browse files Browse the repository at this point in the history
)
  • Loading branch information
samsonasik committed Aug 19, 2021
1 parent da03848 commit 2fd5a8e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\Fixture;

use Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\Source\DummyValidator;

class MultiAssign
{
public function run()
{
$dummyValidator = $temp = new DummyValidator();
$dummyValidator->validate(100000);
}
}

?>
-----
<?php

namespace Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\Fixture;

use Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\Source\DummyValidator;

class MultiAssign
{
public function __construct(private \Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\Source\DummyValidator $dummyValidator)
{
}
public function run()
{
$this->dummyValidator->validate(100000);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Naming\PropertyNaming;
use Rector\Naming\ValueObject\ExpectedName;
use Rector\NodeRemoval\AssignRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PostRector\Collector\PropertyToAddCollector;
use Rector\PostRector\ValueObject\PropertyMetadata;
Expand All @@ -40,7 +41,8 @@ final class NewToConstructorInjectionRector extends AbstractRector implements Co
public function __construct(
private PropertyFetchFactory $propertyFetchFactory,
private PropertyNaming $propertyNaming,
private PropertyToAddCollector $propertyToAddCollector
private PropertyToAddCollector $propertyToAddCollector,
private AssignRemover $assignRemover
) {
}

Expand Down Expand Up @@ -158,7 +160,7 @@ private function refactorAssign(Assign $assign): void
continue;
}

$this->removeNode($assign);
$this->assignRemover->removeAssignNode($assign);
}
}

Expand Down

0 comments on commit 2fd5a8e

Please sign in to comment.