-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Do not remove unused param in middle on RemoveUnusedConstr…
…uctorParamRector (#2231) * [DeadCode] Do not remove unused param in middle on RemoveUnusedConstructorParamRector * more fixture * Fixed 🎉 * Fixed 🎉
- Loading branch information
1 parent
0175838
commit dd178de
Showing
6 changed files
with
163 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
tests/Issues/RemoveUnusedParamInMiddle/Fixture/do_not_remove_parameter_in_middle.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedParamInMiddle\Fixture; | ||
|
||
final class DoNotRemoveParameterInMiddle | ||
{ | ||
private $propertyA; | ||
private $propertyB; | ||
private $propertyC; | ||
|
||
public function __construct($propertyA, $propertyB, $propertyC) | ||
{ | ||
$this->propertyA = $propertyA; | ||
$this->propertyB = $propertyB; | ||
$this->propertyC = $propertyC; | ||
} | ||
|
||
public function run() | ||
{ | ||
echo $this->propertyA; | ||
echo $this->propertyC; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedParamInMiddle\Fixture; | ||
|
||
final class DoNotRemoveParameterInMiddle | ||
{ | ||
private $propertyA; | ||
private $propertyC; | ||
|
||
public function __construct($propertyA, $propertyB, $propertyC) | ||
{ | ||
$this->propertyA = $propertyA; | ||
$this->propertyC = $propertyC; | ||
} | ||
|
||
public function run() | ||
{ | ||
echo $this->propertyA; | ||
echo $this->propertyC; | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/RemoveUnusedParamInMiddle/RemoveUnusedParamInMiddleTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedParamInMiddle; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class RemoveUnusedParamInMiddleTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Issues/RemoveUnusedParamInMiddle/config/configured_rule.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; | ||
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(RemoveUnusedConstructorParamRector::class); | ||
$rectorConfig->rule(RemoveUnusedPrivatePropertyRector::class); | ||
}; |