From 629f2f4c753d3e5aeaef5d10ad2516e80685b401 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Mon, 19 Feb 2024 16:54:19 +0100 Subject: [PATCH] Add TemplateCovariant and TemplateContravariant attributes --- README.md | 2 + composer.json | 2 +- ...tic-analysis-annotations-to-attributes.php | 4 ++ ...TemplateContravariantAttributeTest.php.inc | 39 ++++++++++++++++++ .../TemplateCovariantAttributeTest.php.inc | 41 +++++++++++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/Fixture/TemplateContravariantAttributeTest.php.inc create mode 100644 tests/Fixture/TemplateCovariantAttributeTest.php.inc diff --git a/README.md b/README.md index ce367db..bf7351e 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ These are the available attributes and their corresponding PHPDoc annotations: | [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` | +| [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` | | [Type](https://github.com/php-static-analysis/attributes/blob/main/doc/Type.md) | `@var` `@return` | ### Location of Param attributes diff --git a/composer.json b/composer.json index 97e6079..cf4b0aa 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "prefer-stable": true, "require": { "php": ">=8.0", - "php-static-analysis/attributes": "^0.1.4 || dev-main", + "php-static-analysis/attributes": "^0.1.5 || 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 738d3ff..775697c 100644 --- a/config/sets/php-static-analysis-annotations-to-attributes.php +++ b/config/sets/php-static-analysis-annotations-to-attributes.php @@ -4,6 +4,8 @@ use PhpStaticAnalysis\Attributes\PropertyRead; use PhpStaticAnalysis\Attributes\PropertyWrite; +use PhpStaticAnalysis\Attributes\TemplateContravariant; +use PhpStaticAnalysis\Attributes\TemplateCovariant; use Rector\Config\RectorConfig; use Rector\Php80\ValueObject\AnnotationToAttribute; use PhpStaticAnalysis\Attributes\IsReadOnly; @@ -25,6 +27,8 @@ new AnnotationToAttribute('readonly', IsReadOnly::class), new AnnotationToAttribute('return', Returns::class), new AnnotationToAttribute('template', Template::class), + new AnnotationToAttribute('template_contravariant', TemplateContravariant::class), + new AnnotationToAttribute('template_covariant', TemplateCovariant::class), new AnnotationToAttribute('var', Type::class), 'addParamAttributeOnParameters' => false, 'useTypeAttributeForReturnAnnotation' => false, diff --git a/tests/Fixture/TemplateContravariantAttributeTest.php.inc b/tests/Fixture/TemplateContravariantAttributeTest.php.inc new file mode 100644 index 0000000..2dbeb93 --- /dev/null +++ b/tests/Fixture/TemplateContravariantAttributeTest.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/tests/Fixture/TemplateCovariantAttributeTest.php.inc b/tests/Fixture/TemplateCovariantAttributeTest.php.inc new file mode 100644 index 0000000..922e352 --- /dev/null +++ b/tests/Fixture/TemplateCovariantAttributeTest.php.inc @@ -0,0 +1,41 @@ + +----- +