From 8032ba726365f11bbbb5db27e7942ab0f6fe9212 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Sun, 25 Feb 2024 16:11:16 +0100 Subject: [PATCH] Add Pure and Impure attributes --- README.md | 43 ++++---- composer.json | 2 +- ...tic-analysis-annotations-to-attributes.php | 4 + tests/Fixture/ImpureAttributeTest.php.inc | 89 +++++++++++++++ tests/Fixture/PureAttributeTest.php.inc | 101 ++++++++++++++++++ 5 files changed, 218 insertions(+), 21 deletions(-) create mode 100644 tests/Fixture/ImpureAttributeTest.php.inc create mode 100644 tests/Fixture/PureAttributeTest.php.inc diff --git a/README.md b/README.md index 9b0754a..265ad75 100644 --- a/README.md +++ b/README.md @@ -112,26 +112,29 @@ 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` | -| [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` | -| [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` | -| [RequireExtends](https://github.com/php-static-analysis/attributes/blob/main/doc/RequireExtends.md) | `@require-extends` | -| [RequireImplements](https://github.com/php-static-analysis/attributes/blob/main/doc/RequireImplements.md) | `@require-implements` | -| [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` | +| [Deprecated](https://github.com/php-static-analysis/attributes/blob/main/doc/Deprecated.md) | `@deprecated` | +| [Impure](https://github.com/php-static-analysis/attributes/blob/main/doc/Impure.md) | `@impure` | +| [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` | +| [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` | +| [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` | +| [Pure](https://github.com/php-static-analysis/attributes/blob/main/doc/Pure.md) | `@pure` | +| [RequireExtends](https://github.com/php-static-analysis/attributes/blob/main/doc/RequireExtends.md) | `@require-extends` | +| [RequireImplements](https://github.com/php-static-analysis/attributes/blob/main/doc/RequireImplements.md) | `@require-implements` | +| [Returns](https://github.com/php-static-analysis/attributes/blob/main/doc/Returns.md) | `@return` | +| [SelfOut](https://github.com/php-static-analysis/attributes/blob/main/doc/SelfOut.md) | `@self-out` `@this-out` | +| [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` | ### Location of Param and ParamOut attributes diff --git a/composer.json b/composer.json index 7b93dd4..1463cfd 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.14 || dev-main", + "php-static-analysis/attributes": "^0.1.15 || 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 28be4dc..b1f5567 100644 --- a/config/sets/php-static-analysis-annotations-to-attributes.php +++ b/config/sets/php-static-analysis-annotations-to-attributes.php @@ -3,12 +3,14 @@ declare(strict_types=1); use PhpStaticAnalysis\Attributes\Deprecated; +use PhpStaticAnalysis\Attributes\Impure; use PhpStaticAnalysis\Attributes\Internal; use PhpStaticAnalysis\Attributes\Method; use PhpStaticAnalysis\Attributes\Mixin; use PhpStaticAnalysis\Attributes\ParamOut; use PhpStaticAnalysis\Attributes\PropertyRead; use PhpStaticAnalysis\Attributes\PropertyWrite; +use PhpStaticAnalysis\Attributes\Pure; use PhpStaticAnalysis\Attributes\RequireExtends; use PhpStaticAnalysis\Attributes\RequireImplements; use PhpStaticAnalysis\Attributes\SelfOut; @@ -33,6 +35,7 @@ [ new AnnotationToAttribute('deprecated', Deprecated::class), new AnnotationToAttribute('extends', TemplateExtends::class), + new AnnotationToAttribute('impure', Impure::class), new AnnotationToAttribute('implements', TemplateImplements::class), new AnnotationToAttribute('internal', Internal::class), new AnnotationToAttribute('method', Method::class), @@ -42,6 +45,7 @@ new AnnotationToAttribute('property', Property::class), new AnnotationToAttribute('property_read', PropertyRead::class), new AnnotationToAttribute('property_write', PropertyWrite::class), + new AnnotationToAttribute('pure', Pure::class), new AnnotationToAttribute('readonly', IsReadOnly::class), new AnnotationToAttribute('require_extends', RequireExtends::class), new AnnotationToAttribute('require_implements', RequireImplements::class), diff --git a/tests/Fixture/ImpureAttributeTest.php.inc b/tests/Fixture/ImpureAttributeTest.php.inc new file mode 100644 index 0000000..1f7881e --- /dev/null +++ b/tests/Fixture/ImpureAttributeTest.php.inc @@ -0,0 +1,89 @@ + +----- + diff --git a/tests/Fixture/PureAttributeTest.php.inc b/tests/Fixture/PureAttributeTest.php.inc new file mode 100644 index 0000000..38266ea --- /dev/null +++ b/tests/Fixture/PureAttributeTest.php.inc @@ -0,0 +1,101 @@ + +----- +