diff --git a/README.md b/README.md index bf7351e..6d14944 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ These are the available attributes and their corresponding PHPDoc annotations: | Attribute | PHPDoc Annotations | |---------------------------------------------------------------------------------------------------|--------------------| | [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` | | [Param](https://github.com/php-static-analysis/attributes/blob/main/doc/Param.md) | `@param` | | [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` | diff --git a/composer.json b/composer.json index cf4b0aa..16a806f 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "prefer-stable": true, "require": { "php": ">=8.0", - "php-static-analysis/attributes": "^0.1.5 || dev-main", + "php-static-analysis/attributes": "^0.1.6 || 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 775697c..ea94175 100644 --- a/config/sets/php-static-analysis-annotations-to-attributes.php +++ b/config/sets/php-static-analysis-annotations-to-attributes.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpStaticAnalysis\Attributes\Method; use PhpStaticAnalysis\Attributes\PropertyRead; use PhpStaticAnalysis\Attributes\PropertyWrite; use PhpStaticAnalysis\Attributes\TemplateContravariant; @@ -21,6 +22,7 @@ AnnotationsToAttributesRector::class, [ new AnnotationToAttribute('param', Param::class), + new AnnotationToAttribute('method', Method::class), new AnnotationToAttribute('property', Property::class), new AnnotationToAttribute('property_read', PropertyRead::class), new AnnotationToAttribute('property_write', PropertyWrite::class), diff --git a/src/AnnotationsToAttributesRector.php b/src/AnnotationsToAttributesRector.php index 41c8e32..1d3b1e7 100644 --- a/src/AnnotationsToAttributesRector.php +++ b/src/AnnotationsToAttributesRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; @@ -225,6 +226,11 @@ private function processAnnotations(PhpDocInfo $phpDocInfo): array $tagValueNode = $phpDocChildNode->value; switch (true) { + case $tagValueNode instanceof MethodTagValueNode: + $args = [ + new Node\Arg(new Scalar\String_((string)($tagValueNode))) + ]; + break; case $tagValueNode instanceof ParamTagValueNode: $args = [ new Node\Arg( diff --git a/tests/Fixture/MethodAttributeTest.php.inc b/tests/Fixture/MethodAttributeTest.php.inc new file mode 100644 index 0000000..b8614f7 --- /dev/null +++ b/tests/Fixture/MethodAttributeTest.php.inc @@ -0,0 +1,37 @@ + +----- +