diff --git a/README.md b/README.md index d29e632..2f8f78f 100644 --- a/README.md +++ b/README.md @@ -110,26 +110,26 @@ return RectorConfig::configure() These are the available attributes and their corresponding PHPDoc annotations: -| Attribute | PHPDoc Annotations | -|---------------------------------------------------------------------------------------------------|--------------------| +| Attribute | PHPDoc Annotations | +|-------------------------------------------------------------------------------------------------------------------|--------------------| | [Deprecated](https://github.com/php-static-analysis/attributes/blob/main/doc/Deprecated.md) | `@deprecated` | | [Internal](https://github.com/php-static-analysis/attributes/blob/main/doc/Internal.md) | `@internal` | -| [IsReadOnly](https://github.com/php-static-analysis/attributes/blob/main/doc/IsReadOnly.md) | `@readonly` | +| [IsReadOnly](https://github.com/php-static-analysis/attributes/blob/main/doc/IsReadOnly.md) | `@readonly` | | [Method](https://github.com/php-static-analysis/attributes/blob/main/doc/Method.md) | `@method` | | [Mixin](https://github.com/php-static-analysis/attributes/blob/main/doc/Mixin.md) | `@mixin` | -| [Param](https://github.com/php-static-analysis/attributes/blob/main/doc/Param.md) | `@param` | +| [Param](https://github.com/php-static-analysis/attributes/blob/main/doc/Param.md) | `@param` | | [ParamOut](https://github.com/php-static-analysis/attributes/blob/main/doc/ParamOut.md) | `@param-out` | -| [Property](https://github.com/php-static-analysis/attributes/blob/main/doc/Property.md) | `@property` `@var` | -| [PropertyRead](https://github.com/php-static-analysis/attributes/blob/main/doc/PropertyRead.md) | `@property-read` | -| [PropertyWrite](https://github.com/php-static-analysis/attributes/blob/main/doc/PropertyWrite.md) | `@property-write` | -| [Returns](https://github.com/php-static-analysis/attributes/blob/main/doc/Returns.md) | `@return` | -| [Template](https://github.com/php-static-analysis/attributes/blob/main/doc/Template.md) | `@template` | +| [Property](https://github.com/php-static-analysis/attributes/blob/main/doc/Property.md) | `@property` `@var` | +| [PropertyRead](https://github.com/php-static-analysis/attributes/blob/main/doc/PropertyRead.md) | `@property-read` | +| [PropertyWrite](https://github.com/php-static-analysis/attributes/blob/main/doc/PropertyWrite.md) | `@property-write` | +| [Returns](https://github.com/php-static-analysis/attributes/blob/main/doc/Returns.md) | `@return` | +| [SelfOutAttributeTest.php](..%2Fphpstan-extension%2Ftests%2FSelfOutAttributeTest.php) | [Template](https://github.com/php-static-analysis/attributes/blob/main/doc/Template.md) | `@template` | | [TemplateContravariant](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateContravariant.md) | `@template-contravariant` | | [TemplateCovariant](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateCovariant.md) | `@template-covariant` | | [TemplateExtends](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateExtends.md) | `@extends` `@template-extends` | -| [TemplateImplements](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateImplements.md) | `@implements` `@template-implements` | -| [TemplateUse](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateUse.md) | `@use` `@template-use` | -| [Type](https://github.com/php-static-analysis/attributes/blob/main/doc/Type.md) | `@var` `@return` | +| [TemplateImplements](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateImplements.md) | `@implements` `@template-implements` | +| [TemplateUse](https://github.com/php-static-analysis/attributes/blob/main/doc/TemplateUse.md) | `@use` `@template-use` | +| [Type](https://github.com/php-static-analysis/attributes/blob/main/doc/Type.md) | `@var` `@return` | ### Location of Param and ParamOut attributes diff --git a/composer.json b/composer.json index 921b0f1..4f930b4 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require": { "php": ">=8.0", "cweagans/composer-patches": "^1.7", - "php-static-analysis/attributes": "^0.1.12 || dev-main", + "php-static-analysis/attributes": "^0.1.13 || dev-main", "rector/rector": "^0.19 || ^1.0" }, "require-dev": { diff --git a/config/sets/php-static-analysis-annotations-to-attributes.php b/config/sets/php-static-analysis-annotations-to-attributes.php index 62a8f9a..d8515e4 100644 --- a/config/sets/php-static-analysis-annotations-to-attributes.php +++ b/config/sets/php-static-analysis-annotations-to-attributes.php @@ -9,6 +9,7 @@ use PhpStaticAnalysis\Attributes\ParamOut; use PhpStaticAnalysis\Attributes\PropertyRead; use PhpStaticAnalysis\Attributes\PropertyWrite; +use PhpStaticAnalysis\Attributes\SelfOut; use PhpStaticAnalysis\Attributes\TemplateContravariant; use PhpStaticAnalysis\Attributes\TemplateCovariant; use PhpStaticAnalysis\Attributes\TemplateExtends; @@ -41,12 +42,14 @@ new AnnotationToAttribute('property_write', PropertyWrite::class), new AnnotationToAttribute('readonly', IsReadOnly::class), new AnnotationToAttribute('return', Returns::class), + new AnnotationToAttribute('self_out', SelfOut::class), new AnnotationToAttribute('template', Template::class), new AnnotationToAttribute('template_contravariant', TemplateContravariant::class), new AnnotationToAttribute('template_covariant', TemplateCovariant::class), new AnnotationToAttribute('template_extends', TemplateExtends::class), new AnnotationToAttribute('template_implements', TemplateImplements::class), new AnnotationToAttribute('template_use', TemplateUse::class), + new AnnotationToAttribute('this_out', SelfOut::class), new AnnotationToAttribute('use', TemplateUse::class), new AnnotationToAttribute('var', Type::class), 'addParamAttributeOnParameters' => false, diff --git a/src/AnnotationsToAttributesRector.php b/src/AnnotationsToAttributesRector.php index 7acd6cd..410701a 100644 --- a/src/AnnotationsToAttributesRector.php +++ b/src/AnnotationsToAttributesRector.php @@ -22,6 +22,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\SelfOutTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\UsesTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; @@ -287,6 +288,7 @@ private function processAnnotations(PhpDocInfo $phpDocInfo): array case $tagValueNode instanceof ImplementsTagValueNode: case $tagValueNode instanceof MixinTagValueNode: case $tagValueNode instanceof ReturnTagValueNode: + case $tagValueNode instanceof SelfOutTagValueNode: case $tagValueNode instanceof UsesTagValueNode: case $tagValueNode instanceof VarTagValueNode: $args = [ diff --git a/tests/Fixture/SelfOutAttributeTest.php.inc b/tests/Fixture/SelfOutAttributeTest.php.inc new file mode 100644 index 0000000..7ca170b --- /dev/null +++ b/tests/Fixture/SelfOutAttributeTest.php.inc @@ -0,0 +1,99 @@ + + */ + public function add() + { + } + + /** + * @phpstan-this-out self + */ + public function addThis() + { + } + + /** + * @codeCoverageIgnore + * @phpstan-self-out self + */ + public function addMore() + { + } + + /** + * @phpstan-self-out self + */ + #[Param(name:'string')] + public function addAnother() + { + } + + /** + * @phpstan-self-out self this is the new type + */ + public function addUserName() + { + } + + /** + * @psalm-self-out self + */ + public function addPsalm() + { + } +} + +?> +----- +')] + public function add() + { + } + + #[\PhpStaticAnalysis\Attributes\SelfOut('self')] + public function addThis() + { + } + + /** + * @codeCoverageIgnore + */ + #[\PhpStaticAnalysis\Attributes\SelfOut('self')] + public function addMore() + { + } + + #[Param(name:'string')] + #[\PhpStaticAnalysis\Attributes\SelfOut('self')] + public function addAnother() + { + } + + #[\PhpStaticAnalysis\Attributes\SelfOut('self')] // this is the new type + public function addUserName() + { + } + + #[\PhpStaticAnalysis\Attributes\SelfOut('self')] + public function addPsalm() + { + } +} + +?>