-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented TypedPropertyFromStrictConstructorReadonlyClassRector (#4552
- Loading branch information
Showing
14 changed files
with
465 additions
and
27 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
37 changes: 37 additions & 0 deletions
37
...yFromStrictConstructorReadonlyClassRector/Fixture/immutable_class_public_property.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,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
/** | ||
* @immutable | ||
*/ | ||
class ImmutableClassPublicProperty | ||
{ | ||
public $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
/** | ||
* @immutable | ||
*/ | ||
class ImmutableClassPublicProperty | ||
{ | ||
public string $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
...onstructorReadonlyClassRector/Fixture/immutable_class_public_property_useless_var.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,40 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
/** | ||
* @immutable | ||
*/ | ||
class ImmutableClassPublicPropertyUselessVar | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
/** | ||
* @immutable | ||
*/ | ||
class ImmutableClassPublicPropertyUselessVar | ||
{ | ||
public string $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
...PropertyFromStrictConstructorReadonlyClassRector/Fixture/readonly_public_property.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,33 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
class ReadonlyPublicProperty | ||
{ | ||
/** @readonly */ | ||
public $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
class ReadonlyPublicProperty | ||
{ | ||
/** @readonly */ | ||
public string $config; | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
...pertyFromStrictConstructorReadonlyClassRector/Fixture/skip_default_false_in_param.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,15 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
final class SkipDefaultFalseInParam | ||
{ | ||
public $someString = false; | ||
|
||
public function __construct(string $someString) | ||
{ | ||
if (mt_rand(0, 1)) { | ||
$this->someString = $someString; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...r/Property/TypedPropertyFromStrictConstructorReadonlyClassRector/Fixture/skip_doc.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,16 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
class SkipDoc | ||
{ | ||
private $name; | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function __construct($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...PropertyFromStrictConstructorReadonlyClassRector/Fixture/skip_doctrine_collection.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,15 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
final class SkipDoctrineCollection | ||
{ | ||
private $items; | ||
|
||
public function __construct() | ||
{ | ||
$this->items = new ArrayCollection(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...PropertyFromStrictConstructorReadonlyClassRector/Fixture/skip_non_public_property.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,16 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector\Fixture; | ||
|
||
/** | ||
* @immutable | ||
*/ | ||
class SkipNonPublicProperty | ||
{ | ||
protected $config; // non-public properties are handled by other rules | ||
|
||
public function __construct(string $s) | ||
{ | ||
$this->config = $s; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...structorReadonlyClassRector/TypedPropertyFromStrictConstructorReadonlyClassRectorTest.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\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class TypedPropertyFromStrictConstructorReadonlyClassRectorTest 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'; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...Property/TypedPropertyFromStrictConstructorReadonlyClassRector/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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Core\ValueObject\PhpVersionFeature; | ||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector; | ||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(TypedPropertyFromStrictConstructorReadonlyClassRector::class); | ||
|
||
$rectorConfig->phpVersion(PhpVersionFeature::TYPED_PROPERTIES); | ||
}; |
Oops, something went wrong.