-
-
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.
Add Immutable attribute and the possibility to exclude some annotations
- Loading branch information
1 parent
c35515d
commit 19cdb95
Showing
8 changed files
with
188 additions
and
5 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
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
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 ExcludeAnnotationsTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
yield [__DIR__ . '/SpecialFixture/ExcludeAnnotationsTest.php.inc']; | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured-rule-with-exclude-annotations.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,55 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
* @immutable all properties are read only | ||
*/ | ||
class ImmutableAttributeTest | ||
{ | ||
} | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
class ImmutableAttributePsalmTest | ||
{ | ||
} | ||
|
||
/** | ||
* @phpstan-immutable | ||
*/ | ||
class ImmutableAttributePHPStanTest | ||
{ | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
#[\PhpStaticAnalysis\Attributes\Immutable] // all properties are read only | ||
class ImmutableAttributeTest | ||
{ | ||
} | ||
|
||
#[\PhpStaticAnalysis\Attributes\Immutable] | ||
class ImmutableAttributePsalmTest | ||
{ | ||
} | ||
|
||
#[\PhpStaticAnalysis\Attributes\Immutable] | ||
class ImmutableAttributePHPStanTest | ||
{ | ||
} | ||
|
||
?> |
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 test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use Exception; | ||
|
||
/** | ||
* @deprecated | ||
* @template T | ||
*/ | ||
class ExcludeAnnotationsTest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function throwsException() | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\RectorRule\Fixture; | ||
|
||
use Exception; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
#[\PhpStaticAnalysis\Attributes\Template('T')] | ||
class ExcludeAnnotationsTest | ||
{ | ||
#[\PhpStaticAnalysis\Attributes\Type('string')] | ||
public $name; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function throwsException() | ||
{ | ||
} | ||
} | ||
|
||
?> |
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, | ||
[ | ||
'excludeAnnotations' => ['throws', 'deprecated'], | ||
] | ||
); | ||
}; |