-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeQuality] Add AddTraitGetterReturnTypeBasedOnSetterRequiredRector (…
…#671) * [CodeQuality] Add AddTraitGetterReturnTypeBasedOnSetterRequiredRector * [CodeQuality] Add AddTraitGetterReturnTypeBasedOnSetterRequiredRector * Fix phpstan * Add Required attribute support * cs fix
- Loading branch information
1 parent
14fcc87
commit 928f117
Showing
7 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...peBasedOnSetterRequiredRector/AddTraitGetterReturnTypeBasedOnSetterRequiredRectorTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class AddTraitGetterReturnTypeBasedOnSetterRequiredRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...Trait_/AddTraitGetterReturnTypeBasedOnSetterRequiredRector/Fixture/flip_set_first.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,51 @@ | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
trait FlipSetFirst | ||
{ | ||
private $service; | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
|
||
public function getService() | ||
{ | ||
return $this->service; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
trait FlipSetFirst | ||
{ | ||
private $service; | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
|
||
public function getService(): stdClass | ||
{ | ||
return $this->service; | ||
} | ||
} | ||
|
||
?> |
25 changes: 25 additions & 0 deletions
25
...tGetterReturnTypeBasedOnSetterRequiredRector/Fixture/skip_already_has_return_type.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,25 @@ | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
trait SkipAlreadyHasReturnType | ||
{ | ||
private $service; | ||
|
||
public function getService(): stdClass | ||
{ | ||
return $this->service; | ||
} | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
} | ||
|
||
?> |
51 changes: 51 additions & 0 deletions
51
...tor/Trait_/AddTraitGetterReturnTypeBasedOnSetterRequiredRector/Fixture/some_trait.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,51 @@ | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
trait SomeTrait | ||
{ | ||
private $service; | ||
|
||
public function getService() | ||
{ | ||
return $this->service; | ||
} | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
trait SomeTrait | ||
{ | ||
private $service; | ||
|
||
public function getService(): stdClass | ||
{ | ||
return $this->service; | ||
} | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
} | ||
|
||
?> |
49 changes: 49 additions & 0 deletions
49
...dTraitGetterReturnTypeBasedOnSetterRequiredRector/Fixture/with_required_attribute.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,49 @@ | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
use Symfony\Contracts\Service\Attribute\Required; | ||
|
||
trait WithRequiredAttribute | ||
{ | ||
private $service; | ||
|
||
public function getService() | ||
{ | ||
return $this->service; | ||
} | ||
|
||
#[Required] | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Symfony\Tests\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector\Fixture; | ||
|
||
use stdClass; | ||
use Symfony\Contracts\Service\Attribute\Required; | ||
|
||
trait WithRequiredAttribute | ||
{ | ||
private $service; | ||
|
||
public function getService(): stdClass | ||
{ | ||
return $this->service; | ||
} | ||
|
||
#[Required] | ||
public function setService(stdClass $stdClass) | ||
{ | ||
$this->stdClass = $stdClass; | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...tor/Trait_/AddTraitGetterReturnTypeBasedOnSetterRequiredRector/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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Symfony\CodeQuality\Rector\Trait_\AddTraitGetterReturnTypeBasedOnSetterRequiredRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(AddTraitGetterReturnTypeBasedOnSetterRequiredRector::class); | ||
}; |
Oops, something went wrong.