From 914c6de7c345ebe96a299a15475e6d233b301bd5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 12 Jul 2022 07:47:05 +0200 Subject: [PATCH 1/5] Bump dev dependencies --- composer.json | 8 ++++---- .../Common/Annotations/Annotation/Enum.php | 4 ++-- .../Annotations/Annotation/IgnoreAnnotation.php | 4 ++-- .../Common/Annotations/Annotation/Target.php | 4 ++-- .../Common/Annotations/AnnotationException.php | 3 +-- lib/Doctrine/Common/Annotations/DocParser.php | 16 ++++++++-------- phpcs.xml.dist | 12 ++---------- 7 files changed, 21 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index b4dfbd390..62f76d217 100644 --- a/composer.json +++ b/composer.json @@ -39,10 +39,10 @@ }, "require-dev": { "doctrine/cache": "^1.11 || ^2.0", - "doctrine/coding-standard": "^6.0 || ^8.1", - "phpstan/phpstan": "^1.4.10 || ^1.8.0", - "phpunit/phpunit": "^7.5 || ^8.0 || ^9.1.5", - "symfony/cache": "^4.4 || ^5.2", + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "~1.4.10 || ^1.8.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "symfony/cache": "^4.4 || ^5.4 || ^6", "vimeo/psalm": "^4.10" }, "autoload": { diff --git a/lib/Doctrine/Common/Annotations/Annotation/Enum.php b/lib/Doctrine/Common/Annotations/Annotation/Enum.php index 35d6410b1..6f24d9f1b 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Enum.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Enum.php @@ -34,9 +34,9 @@ final class Enum public $literal; /** - * @throws InvalidArgumentException - * * @phpstan-param array{literal?: mixed[], value: list} $values + * + * @throws InvalidArgumentException */ public function __construct(array $values) { diff --git a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php index ae60f7d5b..97a15c257 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php @@ -21,9 +21,9 @@ final class IgnoreAnnotation public $names; /** - * @throws RuntimeException - * * @phpstan-param array{value: string|list} $values + * + * @throws RuntimeException */ public function __construct(array $values) { diff --git a/lib/Doctrine/Common/Annotations/Annotation/Target.php b/lib/Doctrine/Common/Annotations/Annotation/Target.php index 7fd75e2bb..ba1d489ac 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Target.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Target.php @@ -56,9 +56,9 @@ final class Target public $literal; /** - * @throws InvalidArgumentException - * * @phpstan-param array{value?: string|list} $values + * + * @throws InvalidArgumentException */ public function __construct(array $values) { diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index 4d91825e5..600bddf4d 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationException.php +++ b/lib/Doctrine/Common/Annotations/AnnotationException.php @@ -133,10 +133,9 @@ public static function requiredError($attributeName, $annotationName, $context, * @param string $annotationName * @param string $context * @param mixed $given + * @phpstan-param list $available * * @return AnnotationException - * - * @phpstan-param list $available */ public static function enumeratorError($attributeName, $annotationName, $context, $available, $given) { diff --git a/lib/Doctrine/Common/Annotations/DocParser.php b/lib/Doctrine/Common/Annotations/DocParser.php index 80f307cab..eda440abd 100644 --- a/lib/Doctrine/Common/Annotations/DocParser.php +++ b/lib/Doctrine/Common/Annotations/DocParser.php @@ -357,10 +357,10 @@ public function setTarget($target) * @param string $input The docblock string to parse. * @param string $context The parsing context. * + * @phpstan-return list Array of annotations. If no annotations are found, an empty array is returned. + * * @throws AnnotationException * @throws ReflectionException - * - * @phpstan-return list Array of annotations. If no annotations are found, an empty array is returned. */ public function parse($input, $context = '') { @@ -426,9 +426,9 @@ private function match(int $token): bool * If any of them matches, this method updates the lookahead token; otherwise * a syntax error is raised. * - * @throws AnnotationException - * * @phpstan-param list $tokens + * + * @throws AnnotationException */ private function matchAny(array $tokens): bool { @@ -674,10 +674,10 @@ private function collectAttributeTypeMetadata(array &$metadata, Attribute $attri /** * Annotations ::= Annotation {[ "*" ]* [Annotation]}* * + * @phpstan-return list + * * @throws AnnotationException * @throws ReflectionException - * - * @phpstan-return list */ private function Annotations(): array { @@ -1357,10 +1357,10 @@ private function Arrayx(): array * KeyValuePair ::= Key ("=" | ":") PlainValue | Constant * Key ::= string | integer | Constant * + * @phpstan-return array{mixed, mixed} + * * @throws AnnotationException * @throws ReflectionException - * - * @phpstan-return array{mixed, mixed} */ private function ArrayEntry(): array { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 038d03b00..0a170cdf1 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -12,6 +12,8 @@ + + lib tests @@ -105,16 +107,6 @@ */tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithRequire.php - - - */tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php - */tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespacedSingleClassLOC1000.php - - - - */tests/Doctrine/Tests/Common/Annotations/Fixtures/Controller.php - - */tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php From 4791d547526c3490a7521ce709aa2d86522ae635 Mon Sep 17 00:00:00 2001 From: Jorrit Schippers Date: Fri, 30 Sep 2022 21:32:14 +0200 Subject: [PATCH 2/5] Fix typo in custom.rst --- docs/en/custom.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/custom.rst b/docs/en/custom.rst index 11fbe1a31..e8f79af71 100644 --- a/docs/en/custom.rst +++ b/docs/en/custom.rst @@ -69,7 +69,7 @@ When using the ``@NamedArgumentConstructor`` tag, the first argument of the constructor is considered as the default one. -Usage with the ``@NamedArgumentContrustor`` tag +Usage with the ``@NamedArgumentConstructor`` tag .. code-block:: php From cbc5a5188d9eecf2e878a201351d414a1bb3bee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 4 Oct 2022 21:37:20 +0200 Subject: [PATCH 3/5] Encourage migration towards attributes We will deprecate this libary eventually. --- README.md | 6 ++++++ composer.json | 3 +++ docs/en/index.rst | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index c2c7eb7ba..6b8c0359b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +⚠️ PHP 8 introduced +[attributes](https://www.php.net/manual/en/language.attributes.overview.php), +which are a native replacement for annotations. As such, this library is +considered feature complete, and should receive exclusively bugfixes and +security fixes. + # Doctrine Annotations [![Build Status](https://github.com/doctrine/annotations/workflows/Continuous%20Integration/badge.svg?label=build)](https://github.com/doctrine/persistence/actions) diff --git a/composer.json b/composer.json index 62f76d217..b5839c84a 100644 --- a/composer.json +++ b/composer.json @@ -45,6 +45,9 @@ "symfony/cache": "^4.4 || ^5.4 || ^6", "vimeo/psalm": "^4.10" }, + "suggest": { + "php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations" + }, "autoload": { "psr-4": { "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" diff --git a/docs/en/index.rst b/docs/en/index.rst index 95476c313..7caffb50a 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -1,3 +1,12 @@ +Deprecation notice +================== + +PHP 8 introduced `attributes +`_, +which are a native replacement for annotations. As such, this library is +considered feature complete, and should receive exclusively bugfixes and +security fixes. + Introduction ============ From 8fb4048e0b24e05b0a14be7e1eb1a7e3afaf072f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 5 Oct 2022 23:45:17 +0200 Subject: [PATCH 4/5] Bump GHA workflows --- .github/workflows/coding-standards.yml | 2 +- .github/workflows/composer-lint.yml | 2 +- .github/workflows/continuous-integration.yml | 4 ++-- .github/workflows/release-on-milestone-closed.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 3ae99378a..83fd68b5e 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -12,4 +12,4 @@ on: jobs: coding-standards: name: "Coding Standards" - uses: "doctrine/.github/.github/workflows/coding-standards.yml@1.5.1" + uses: "doctrine/.github/.github/workflows/coding-standards.yml@2.1.0" diff --git a/.github/workflows/composer-lint.yml b/.github/workflows/composer-lint.yml index ae17b7af3..091b491c3 100644 --- a/.github/workflows/composer-lint.yml +++ b/.github/workflows/composer-lint.yml @@ -15,4 +15,4 @@ on: jobs: composer-lint: name: "Composer Lint" - uses: "doctrine/.github/.github/workflows/composer-lint.yml@1.5.1" + uses: "doctrine/.github/.github/workflows/composer-lint.yml@2.1.0" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ac5f75bb6..f160d3efb 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,6 +14,6 @@ env: jobs: phpunit: name: "PHPUnit" - uses: "doctrine/.github/.github/workflows/continuous-integration.yml@1.5.1" + uses: "doctrine/.github/.github/workflows/continuous-integration.yml@2.1.0" with: - php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0"]' + php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]' diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index d32d76ef7..949de8201 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -8,7 +8,7 @@ on: jobs: release: name: "Git tag, release & create merge-up PR" - uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.5.1" + uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@2.1.0" secrets: GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 4150ff29b..0adc3d08e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,4 +12,4 @@ on: jobs: static-analysis: name: "Static Analysis" - uses: "doctrine/.github/.github/workflows/static-analysis.yml@1.5.1" + uses: "doctrine/.github/.github/workflows/static-analysis.yml@2.1.0" From 8cd57e880a60372f333610b77a3ecdf54fe162e5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 5 Oct 2022 23:44:27 +0200 Subject: [PATCH 5/5] Doctrine CS 10 --- composer.json | 2 +- .../Common/Annotations/Annotation.php | 4 +- .../Annotations/AnnotationException.php | 8 +-- .../Common/Annotations/CachedReader.php | 4 +- lib/Doctrine/Common/Annotations/DocParser.php | 4 +- .../Common/Annotations/TokenParser.php | 4 +- phpcs.xml.dist | 5 ++ .../Common/Annotations/DocParserTest.php | 50 +++++++++---------- 8 files changed, 37 insertions(+), 44 deletions(-) diff --git a/composer.json b/composer.json index b5839c84a..47971b5cc 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "require-dev": { "doctrine/cache": "^1.11 || ^2.0", - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^9 || ^10", "phpstan/phpstan": "~1.4.10 || ^1.8.0", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "symfony/cache": "^4.4 || ^5.4 || ^6", diff --git a/lib/Doctrine/Common/Annotations/Annotation.php b/lib/Doctrine/Common/Annotations/Annotation.php index 750270e42..9cae3dacd 100644 --- a/lib/Doctrine/Common/Annotations/Annotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation.php @@ -18,9 +18,7 @@ class Annotation */ public $value; - /** - * @param array $data Key-value for properties to be defined in this class. - */ + /** @param array $data Key-value for properties to be defined in this class. */ final public function __construct(array $data) { foreach ($data as $key => $value) { diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index 600bddf4d..dcdfe4df6 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationException.php +++ b/lib/Doctrine/Common/Annotations/AnnotationException.php @@ -149,9 +149,7 @@ public static function enumeratorError($attributeName, $annotationName, $context )); } - /** - * @return AnnotationException - */ + /** @return AnnotationException */ public static function optimizerPlusSaveComments() { return new self( @@ -159,9 +157,7 @@ public static function optimizerPlusSaveComments() ); } - /** - * @return AnnotationException - */ + /** @return AnnotationException */ public static function optimizerPlusLoadComments() { return new self( diff --git a/lib/Doctrine/Common/Annotations/CachedReader.php b/lib/Doctrine/Common/Annotations/CachedReader.php index c036b2dab..85dbefab5 100644 --- a/lib/Doctrine/Common/Annotations/CachedReader.php +++ b/lib/Doctrine/Common/Annotations/CachedReader.php @@ -38,9 +38,7 @@ final class CachedReader implements Reader /** @var int[] */ private $loadedFilemtimes = []; - /** - * @param bool $debug - */ + /** @param bool $debug */ public function __construct(Reader $reader, Cache $cache, $debug = false) { $this->delegate = $reader; diff --git a/lib/Doctrine/Common/Annotations/DocParser.php b/lib/Doctrine/Common/Annotations/DocParser.php index eda440abd..4133fe5f4 100644 --- a/lib/Doctrine/Common/Annotations/DocParser.php +++ b/lib/Doctrine/Common/Annotations/DocParser.php @@ -1166,9 +1166,7 @@ private function identifierEndsWithClassConstant(string $identifier): bool return $this->getClassConstantPositionInIdentifier($identifier) === strlen($identifier) - strlen('::class'); } - /** - * @return int|false - */ + /** @return int|false */ private function getClassConstantPositionInIdentifier(string $identifier) { return stripos($identifier, '::class'); diff --git a/lib/Doctrine/Common/Annotations/TokenParser.php b/lib/Doctrine/Common/Annotations/TokenParser.php index 9605fb8dd..69259fccf 100644 --- a/lib/Doctrine/Common/Annotations/TokenParser.php +++ b/lib/Doctrine/Common/Annotations/TokenParser.php @@ -46,9 +46,7 @@ class TokenParser */ private $pointer = 0; - /** - * @param string $contents - */ + /** @param string $contents */ public function __construct($contents) { $this->tokens = token_get_all($contents); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0a170cdf1..eeadabad2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -148,4 +148,9 @@ */tests/Doctrine/Tests/Common/Annotations/Fixtures/functions.php + + + + */tests + diff --git a/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php b/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php index 5e6f35cb2..297d7e90c 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php @@ -130,7 +130,7 @@ public function testBasicAnnotations(): void self::assertEquals('value2', $annot->value[1]['key2']); // Complete docblock - $docblock = <<setIgnoreNotImportedAnnotations(true); - $docblock = <<createTestParser(); - $docblock = <<createTestParser(); - $docblock = <<data); self::assertEquals($annot->data, 'Some data'); - $docblock = <<name, 'Some Name'); self::assertEquals($annot->data, 'Some data'); - $docblock = <<data, 'Some data'); self::assertNull($annot->name); - $docblock = <<name, 'Some name'); self::assertNull($annot->data); - $docblock = <<data, 'Some data'); self::assertNull($annot->name); - $docblock = <<name, 'Some name'); self::assertEquals($annot->data, 'Some data'); - $docblock = <<name, 'Some name'); self::assertEquals($annot->data, 'Some data'); - $docblock = <<createTestParser(); - $docblock = <<createTestParser(); - $docblock = <<createTestParser(); $context = 'class SomeClassName'; - $docblock = <<createTestParser(); $context = 'class SomeClassName'; - $docblock = <<createTestParser(); $context = 'class SomeClassName'; - $docblock = <<createTestParser(); - $docblock = <<markTestSkipped('This test requires mbstring function overloading is turned on'); } - $docblock = <<