diff --git a/README.md b/README.md index eb8ff08..86660fb 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ These are the available attributes and their corresponding 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` | | [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` | diff --git a/composer.json b/composer.json index f1b24e4..e3f637b 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.8 || dev-main", + "php-static-analysis/attributes": "^0.1.9 || 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 fdf76e0..1134b18 100644 --- a/config/sets/php-static-analysis-annotations-to-attributes.php +++ b/config/sets/php-static-analysis-annotations-to-attributes.php @@ -3,6 +3,7 @@ declare(strict_types=1); use PhpStaticAnalysis\Attributes\Deprecated; +use PhpStaticAnalysis\Attributes\Internal; use PhpStaticAnalysis\Attributes\Method; use PhpStaticAnalysis\Attributes\PropertyRead; use PhpStaticAnalysis\Attributes\PropertyWrite; @@ -23,6 +24,7 @@ AnnotationsToAttributesRector::class, [ new AnnotationToAttribute('deprecated', Deprecated::class), + new AnnotationToAttribute('internal', Internal::class), new AnnotationToAttribute('method', Method::class), new AnnotationToAttribute('param', Param::class), new AnnotationToAttribute('property', Property::class), diff --git a/src/AnnotationsToAttributesRector.php b/src/AnnotationsToAttributesRector.php index 9f4acce..942d339 100644 --- a/src/AnnotationsToAttributesRector.php +++ b/src/AnnotationsToAttributesRector.php @@ -227,7 +227,7 @@ private function processAnnotations(PhpDocInfo $phpDocInfo): array } $tagValueNode = $phpDocChildNode->value; - $attributeComment = null; + $attributeComment = ''; switch (true) { case $tagValueNode instanceof MethodTagValueNode: $methodSignature = (string)($tagValueNode); @@ -276,7 +276,17 @@ private function processAnnotations(PhpDocInfo $phpDocInfo): array case $tagValueNode instanceof DeprecatedTagValueNode: case $tagValueNode instanceof GenericTagValueNode: $args = []; - $attributeComment = (string)$tagValueNode; + if ($phpDocChildNode->name === '@psalm-internal') { + $remainingText = (string)$tagValueNode; + $parts = explode(' ', $remainingText); + $namespace = array_shift($parts); + if ($namespace) { + $args[] = new Node\Arg(new Scalar\String_($namespace)); + $attributeComment = implode(' ', $parts); + } + } else { + $attributeComment = (string)$tagValueNode; + } break; default: continue 2; diff --git a/tests/Fixture/InternalAttributeTest.php.inc b/tests/Fixture/InternalAttributeTest.php.inc new file mode 100644 index 0000000..e0a292b --- /dev/null +++ b/tests/Fixture/InternalAttributeTest.php.inc @@ -0,0 +1,133 @@ + +----- +