-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! [PHP 8.2] Add rule for AllowDynamicProperties attribute (#1225)
- Loading branch information
1 parent
1255b91
commit 5555104
Showing
8 changed files
with
167 additions
and
14 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
31 changes: 31 additions & 0 deletions
31
...Rector/Property/AddPropertyTypeDeclarationRector/AddPropertyTypeDeclarationRectorTest.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class AddPropertyTypeDeclarationRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return \Iterator<\Symplify\SmartFileSystem\SmartFileInfo> | ||
*/ | ||
public function provideData(): \Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...peDeclaration/Rector/Property/AddPropertyTypeDeclarationRector/Fixture/some_class.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,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector\Fixture; | ||
|
||
class SomeClass extends ParentClass | ||
{ | ||
public $name; | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector\Fixture; | ||
|
||
class SomeClass extends ParentClass | ||
{ | ||
public string $name; | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...peDeclaration/Rector/Property/AddPropertyTypeDeclarationRector/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 Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(\Rector\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector::class); | ||
}; |
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
68 changes: 68 additions & 0 deletions
68
rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\TypeDeclaration\Rector\Property; | ||
|
||
use PhpParser\Node; | ||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @see \Rector\Tests\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector\AddPropertyTypeDeclarationRectorTest | ||
*/ | ||
final class AddPropertyTypeDeclarationRector extends AbstractRector implements ConfigurableRectorInterface | ||
{ | ||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Add type to property by added rules, mostly public/property by parent type', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
class SomeClass extends ParentClass | ||
{ | ||
public $name; | ||
} | ||
CODE_SAMPLE | ||
|
||
, | ||
<<<'CODE_SAMPLE' | ||
class SomeClass extends ParentClass | ||
{ | ||
public string $name; | ||
} | ||
CODE_SAMPLE | ||
|
||
) | ||
]); | ||
} | ||
|
||
/** | ||
* @return array<class-string<\PhpParser\Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return array(\PhpParser\Node\Stmt\Property::class); | ||
} | ||
|
||
/** | ||
* @param \PhpParser\Node\Stmt\Property $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
// change the node | ||
|
||
return $node; | ||
} | ||
|
||
/** | ||
* @param array<string $configuration | ||
* @return void | ||
*/ | ||
public function configure(array $configuration): void | ||
{ | ||
// TODO: Implement configure() method. | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\TypeDeclaration\ValueObject; | ||
|
||
use PHPStan\Type\Type; | ||
|
||
final class AddPropertyType | ||
{ | ||
public function __construct( | ||
private string $class, | ||
private string $propertyName, | ||
private Type $type | ||
) { | ||
} | ||
|
||
public function getClass(): string | ||
{ | ||
return $this->class; | ||
} | ||
|
||
public function getPropertyName(): string | ||
{ | ||
return $this->propertyName; | ||
} | ||
|
||
public function getType(): Type | ||
{ | ||
return $this->type; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.