-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parent constructor call only once (#3094)
- Loading branch information
Showing
4 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ection/Rector/Class_/ActionInjectionToConstructorInjectionRector/Fixture/fixture3.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Fixture; | ||
|
||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\CategoryRepository; | ||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\ProductRepository; | ||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\SomeProduct; | ||
|
||
abstract class ParentFixture3Constructor { | ||
public function __construct(protected SomeProduct $someProduct) | ||
{ | ||
} | ||
} | ||
|
||
final class Fixture3Controller extends ParentFixture3Constructor | ||
{ | ||
public function default(CategoryRepository $categoryRepository, ProductRepository $productRepository) | ||
{ | ||
$products = $productRepository->fetchAll(); | ||
$categories = $categoryRepository->fetchAll(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Fixture; | ||
|
||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\CategoryRepository; | ||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\ProductRepository; | ||
use Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\SomeProduct; | ||
|
||
abstract class ParentFixture3Constructor { | ||
public function __construct(protected SomeProduct $someProduct) | ||
{ | ||
} | ||
} | ||
|
||
final class Fixture3Controller extends ParentFixture3Constructor | ||
{ | ||
public function __construct(\Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\SomeProduct $someProduct, private \Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\CategoryRepository $categoryRepository, private \Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\ProductRepository $productRepository) | ||
{ | ||
parent::__construct($someProduct); | ||
} | ||
public function default() | ||
{ | ||
$products = $this->productRepository->fetchAll(); | ||
$categories = $this->categoryRepository->fetchAll(); | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...n/Rector/Class_/ActionInjectionToConstructorInjectionRector/Source/CategoryRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source; | ||
|
||
final class CategoryRepository | ||
{ | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...dencyInjection/Rector/Class_/ActionInjectionToConstructorInjectionRector/xml/services.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\CategoryRepository"></service> | ||
<service id="Rector\Tests\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector\Source\ProductRepository"></service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters