-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f05ab43
commit fcda73e
Showing
9 changed files
with
223 additions
and
1 deletion.
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
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
29 changes: 29 additions & 0 deletions
29
tests/AnnotationsToAttributesWithPropertyAttributeForVarRectorTest.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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class AnnotationsToAttributesWithPropertyAttributeForVarRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
yield [__DIR__ . '/SpecialFixture/PropertyAttributeTestForVarAnnotation.php.inc']; | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured-rule-with-property-attribute-for-var.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,37 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
|
||
/** | ||
* @deprecated | ||
* @property string $name | ||
* @psalm-property int $num | ||
* @phpstan-property string[] $index | ||
*/ | ||
#[Template('T')] | ||
class PropertyAttributeTest | ||
{ | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
#[Template('T')] | ||
#[\PhpStaticAnalysis\Attributes\Property(name: 'string')] | ||
#[\PhpStaticAnalysis\Attributes\Property(num: 'int')] | ||
#[\PhpStaticAnalysis\Attributes\Property(index: 'string[]')] | ||
class PropertyAttributeTest | ||
{ | ||
} | ||
|
||
?> |
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
67 changes: 67 additions & 0 deletions
67
tests/SpecialFixture/PropertyAttributeTestForVarAnnotation.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,67 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\IsReadOnly; | ||
|
||
class PropertyAttributeTestForVarAnnotation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @deprecated | ||
* @var string | ||
*/ | ||
public $anotherName; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
#[IsReadOnly] | ||
public $otherName; | ||
|
||
/** | ||
* @psalm-var string | ||
*/ | ||
public $psalmName; | ||
|
||
/** | ||
* @phpstan-var string | ||
*/ | ||
public $phpstanName; | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\IsReadOnly; | ||
|
||
class PropertyAttributeTestForVarAnnotation | ||
{ | ||
#[\PhpStaticAnalysis\Attributes\Property('string')] | ||
public $name; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
#[\PhpStaticAnalysis\Attributes\Property('string')] | ||
public $anotherName; | ||
|
||
#[IsReadOnly] | ||
#[\PhpStaticAnalysis\Attributes\Property('string')] | ||
public $otherName; | ||
|
||
#[\PhpStaticAnalysis\Attributes\Property('string')] | ||
public $psalmName; | ||
|
||
#[\PhpStaticAnalysis\Attributes\Property('string')] | ||
public $phpstanName; | ||
} | ||
|
||
?> |
19 changes: 19 additions & 0 deletions
19
tests/config/configured-rule-with-property-attribute-for-var.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpStaticAnalysis\RectorRule\AnnotationsToAttributesRector; | ||
use PhpStaticAnalysis\RectorRule\Set\PhpStaticAnalysisSetList; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->sets([ | ||
PhpStaticAnalysisSetList::ANNOTATIONS_TO_ATTRIBUTES | ||
]); | ||
$rectorConfig->ruleWithConfiguration( | ||
AnnotationsToAttributesRector::class, | ||
[ | ||
'usePropertyAttributeForVarAnnotation' => true, | ||
] | ||
); | ||
}; |