diff --git a/.doctrine-project.json b/.doctrine-project.json index 25d470860..38553aa66 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -5,25 +5,34 @@ "docsSlug": "doctrine-annotations", "versions": [ { - "name": "1.9", - "branchName": "1.9", - "slug": "1.9", - "aliases": [ - "latest" - ], + "name": "1.11", + "branchName": "master", + "slug": "latest", "upcoming": true }, { - "name": "1.8", - "branchName": "1.8", - "slug": "1.8", - "current": true, + "name": "1.10", + "branchName": "1.10.x", + "slug": "1.10", "aliases": [ "current", "stable" ], + "current": true, "maintained": true }, + { + "name": "1.9", + "branchName": "1.9.x", + "slug": "1.9", + "maintained": false + }, + { + "name": "1.8", + "branchName": "1.8", + "slug": "1.8", + "maintained": false + }, { "name": "1.7", "branchName": "1.7", diff --git a/README.md b/README.md index a53b91f2b..bf07cd514 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ Docblock Annotations Parser library (extracted from [Doctrine Common](https://gi See the [doctrine-project website](https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/index.html). +## Contributing + +When making a pull request, make sure your changes follow the +[Coding Standard Guidelines](https://www.doctrine-project.org/projects/doctrine-coding-standard/en/latest/reference/index.html#introduction). + ## Changelog See [CHANGELOG.md](CHANGELOG.md). diff --git a/composer.json b/composer.json index 75b5d0ec3..2f3318a5f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "Docblock Annotations Parser", "keywords": ["annotations", "docblock", "parser"], - "homepage": "http://www.doctrine-project.org", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", "license": "MIT", "authors": [ {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, @@ -40,7 +40,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.9.x-dev" + "dev-master": "1.11.x-dev" } } } diff --git a/docs/en/annotations.rst b/docs/en/annotations.rst index 22afc2621..648ab26ed 100644 --- a/docs/en/annotations.rst +++ b/docs/en/annotations.rst @@ -13,7 +13,7 @@ Take a look at the following code snippet: namespace MyProject\Entities; use Doctrine\ORM\Mapping AS ORM; - use Symfony\Component\Validation\Constraints AS Assert; + use Symfony\Component\Validator\Constraints AS Assert; /** * @author Benjamin Eberlei diff --git a/docs/en/index.rst b/docs/en/index.rst index 84355f010..b124f86a7 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -73,7 +73,10 @@ annotations of a class. A common one is $property = $reflectionClass->getProperty('bar'); $reader = new AnnotationReader(); - $myAnnotation = $reader->getPropertyAnnotation($property, MyAnnotation::class); + $myAnnotation = $reader->getPropertyAnnotation( + $property, + MyAnnotation::class + ); echo $myAnnotation->myProperty; // result: "value" diff --git a/lib/Doctrine/Common/Annotations/Annotation.php b/lib/Doctrine/Common/Annotations/Annotation.php index 937b30e67..750270e42 100644 --- a/lib/Doctrine/Common/Annotations/Annotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -31,7 +14,7 @@ class Annotation /** * Value property. Common among all derived classes. * - * @var string + * @var mixed */ public $value; diff --git a/lib/Doctrine/Common/Annotations/Annotation/Attribute.php b/lib/Doctrine/Common/Annotations/Annotation/Attribute.php index 206dad112..b1f851400 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Attribute.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Attribute.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Common\Annotations\Annotation; /** diff --git a/lib/Doctrine/Common/Annotations/Annotation/Attributes.php b/lib/Doctrine/Common/Annotations/Annotation/Attributes.php index d76ade2d1..8f758f3f7 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Attributes.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Attributes.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Common\Annotations\Annotation; /** diff --git a/lib/Doctrine/Common/Annotations/Annotation/Enum.php b/lib/Doctrine/Common/Annotations/Annotation/Enum.php index 2dd70a9ca..35d6410b1 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Enum.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Enum.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Common\Annotations\Annotation; use InvalidArgumentException; diff --git a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php index 0877c4fe5..ae60f7d5b 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations\Annotation; diff --git a/lib/Doctrine/Common/Annotations/Annotation/Required.php b/lib/Doctrine/Common/Annotations/Annotation/Required.php index e3dbeb7d6..dee585755 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Required.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Required.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Common\Annotations\Annotation; /** diff --git a/lib/Doctrine/Common/Annotations/Annotation/Target.php b/lib/Doctrine/Common/Annotations/Annotation/Target.php index 128d9f701..9cf9a2eb9 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Target.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Target.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Common\Annotations\Annotation; use InvalidArgumentException; diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index 804eb8cea..84d6660f8 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationException.php +++ b/lib/Doctrine/Common/Annotations/AnnotationException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/AnnotationReader.php b/lib/Doctrine/Common/Annotations/AnnotationReader.php index a51a657f9..98b32b2d5 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/AnnotationReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -40,7 +23,9 @@ class AnnotationReader implements Reader * * @var array */ - private static $globalImports = ['ignoreannotation' => 'Doctrine\Common\Annotations\Annotation\IgnoreAnnotation']; + private static $globalImports = [ + 'ignoreannotation' => Annotation\IgnoreAnnotation::class, + ]; /** * A list with annotations that are not causing exceptions when not resolved to an annotation class. @@ -49,95 +34,7 @@ class AnnotationReader implements Reader * * @var array */ - private static $globalIgnoredNames = [ - // Annotation tags - 'Annotation' => true, - 'Attribute' => true, - 'Attributes' => true, - /* Can we enable this? 'Enum' => true, */ - 'Required' => true, - 'Target' => true, - // Widely used tags (but not existent in phpdoc) - 'fix' => true , - 'fixme' => true, - 'override' => true, - // PHPDocumentor 1 tags - 'abstract' => true, - 'access' => true, - 'code' => true, - 'deprec' => true, - 'endcode' => true, - 'exception' => true, - 'final' => true, - 'ingroup' => true, - 'inheritdoc' => true, - 'inheritDoc' => true, - 'magic' => true, - 'name' => true, - 'toc' => true, - 'tutorial' => true, - 'private' => true, - 'static' => true, - 'staticvar' => true, - 'staticVar' => true, - 'throw' => true, - // PHPDocumentor 2 tags. - 'api' => true, - 'author' => true, - 'category' => true, - 'copyright' => true, - 'deprecated' => true, - 'example' => true, - 'filesource' => true, - 'global' => true, - 'ignore' => true, /* Can we enable this? 'index' => true, */ - 'internal' => true, - 'license' => true, - 'link' => true, - 'method' => true, - 'package' => true, - 'param' => true, - 'property' => true, - 'property-read' => true, - 'property-write' => true, - 'return' => true, - 'see' => true, - 'since' => true, - 'source' => true, - 'subpackage' => true, - 'throws' => true, - 'todo' => true, - 'TODO' => true, - 'usedby' => true, - 'uses' => true, - 'var' => true, - 'version' => true, - // PHPUnit tags - 'codeCoverageIgnore' => true, - 'codeCoverageIgnoreStart' => true, - 'codeCoverageIgnoreEnd' => true, - // PHPCheckStyle - 'SuppressWarnings' => true, - // PHPStorm - 'noinspection' => true, - // PEAR - 'package_version' => true, - // PlantUML - 'startuml' => true, - 'enduml' => true, - // Symfony 3.3 Cache Adapter - 'experimental' => true, - // Slevomat Coding Standard - 'phpcsSuppress' => true, - // PHP CodeSniffer - 'codingStandardsIgnoreStart' => true, - 'codingStandardsIgnoreEnd' => true, - // PHPStan - 'template' => true, - 'implements' => true, - 'extends' => true, - 'use' => true, - ]; + private static $globalIgnoredNames = ImplicitlyIgnoredAnnotationNames::LIST; /** * A list with annotations that are not causing exceptions when not resolved to an annotation class. diff --git a/lib/Doctrine/Common/Annotations/AnnotationRegistry.php b/lib/Doctrine/Common/Annotations/AnnotationRegistry.php index 3096f81c8..259d497dd 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationRegistry.php +++ b/lib/Doctrine/Common/Annotations/AnnotationRegistry.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/CachedReader.php b/lib/Doctrine/Common/Annotations/CachedReader.php index ad985b24e..91fbad0c6 100644 --- a/lib/Doctrine/Common/Annotations/CachedReader.php +++ b/lib/Doctrine/Common/Annotations/CachedReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/DocLexer.php b/lib/Doctrine/Common/Annotations/DocLexer.php index 773c05a6a..f6567c512 100644 --- a/lib/Doctrine/Common/Annotations/DocLexer.php +++ b/lib/Doctrine/Common/Annotations/DocLexer.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/DocParser.php b/lib/Doctrine/Common/Annotations/DocParser.php index 84feb90e9..031ef55ba 100644 --- a/lib/Doctrine/Common/Annotations/DocParser.php +++ b/lib/Doctrine/Common/Annotations/DocParser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -158,7 +141,7 @@ final class DocParser * @var array */ private static $annotationMetadata = [ - 'Doctrine\Common\Annotations\Annotation\Target' => [ + Annotation\Target::class => [ 'is_annotation' => true, 'has_constructor' => true, 'properties' => [], @@ -174,7 +157,7 @@ final class DocParser ], ], ], - 'Doctrine\Common\Annotations\Annotation\Attribute' => [ + Annotation\Attribute::class => [ 'is_annotation' => true, 'has_constructor' => false, 'targets_literal' => 'ANNOTATION_ANNOTATION', @@ -203,7 +186,7 @@ final class DocParser ], ], ], - 'Doctrine\Common\Annotations\Annotation\Attributes' => [ + Annotation\Attributes::class => [ 'is_annotation' => true, 'has_constructor' => false, 'targets_literal' => 'ANNOTATION_CLASS', @@ -214,12 +197,12 @@ final class DocParser 'value' => [ 'type' => 'array', 'required' => true, - 'array_type' => 'Doctrine\Common\Annotations\Annotation\Attribute', - 'value' => 'array', + 'array_type' => Annotation\Attribute::class, + 'value' => 'array<' . Annotation\Attribute::class . '>', ], ], ], - 'Doctrine\Common\Annotations\Annotation\Enum' => [ + Annotation\Enum::class => [ 'is_annotation' => true, 'has_constructor' => true, 'targets_literal' => 'ANNOTATION_PROPERTY', @@ -498,10 +481,10 @@ private function collectAnnotationMetadata(string $name): void self::$metadataParser->setIgnoreNotImportedAnnotations(true); self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames); self::$metadataParser->setImports([ - 'enum' => 'Doctrine\Common\Annotations\Annotation\Enum', - 'target' => 'Doctrine\Common\Annotations\Annotation\Target', - 'attribute' => 'Doctrine\Common\Annotations\Annotation\Attribute', - 'attributes' => 'Doctrine\Common\Annotations\Annotation\Attributes', + 'enum' => Annotation\Enum::class, + 'target' => Annotation\Target::class, + 'attribute' => Annotation\Attribute::class, + 'attributes' => Annotation\Attributes::class, ]); // Make sure that annotations from metadata are loaded diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php index 359a2a379..e6a7a958b 100644 --- a/lib/Doctrine/Common/Annotations/FileCacheReader.php +++ b/lib/Doctrine/Common/Annotations/FileCacheReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php b/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php new file mode 100644 index 000000000..797bc5972 --- /dev/null +++ b/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php @@ -0,0 +1,170 @@ + true, + 'Attribute' => true, + 'Attributes' => true, + /* Can we enable this? 'Enum' => true, */ + 'Required' => true, + 'Target' => true, + ]; + + private const WidelyUsedNonStandard = [ + 'fix' => true, + 'fixme' => true, + 'override' => true, + ]; + + private const PhpDocumentor1 = [ + 'abstract' => true, + 'access' => true, + 'code' => true, + 'deprec' => true, + 'endcode' => true, + 'exception' => true, + 'final' => true, + 'ingroup' => true, + 'inheritdoc' => true, + 'inheritDoc' => true, + 'magic' => true, + 'name' => true, + 'private' => true, + 'static' => true, + 'staticvar' => true, + 'staticVar' => true, + 'toc' => true, + 'tutorial' => true, + 'throw' => true, + ]; + + private const PhpDocumentor2 = [ + 'api' => true, + 'author' => true, + 'category' => true, + 'copyright' => true, + 'deprecated' => true, + 'example' => true, + 'filesource' => true, + 'global' => true, + 'ignore' => true, + /* Can we enable this? 'index' => true, */ + 'internal' => true, + 'license' => true, + 'link' => true, + 'method' => true, + 'package' => true, + 'param' => true, + 'property' => true, + 'property-read' => true, + 'property-write' => true, + 'return' => true, + 'see' => true, + 'since' => true, + 'source' => true, + 'subpackage' => true, + 'throws' => true, + 'todo' => true, + 'TODO' => true, + 'usedby' => true, + 'uses' => true, + 'var' => true, + 'version' => true, + ]; + + private const PHPUnit = [ + 'author' => true, + 'after' => true, + 'afterClass' => true, + 'backupGlobals' => true, + 'backupStaticAttributes' => true, + 'before' => true, + 'beforeClass' => true, + 'codeCoverageIgnore' => true, + 'codeCoverageIgnoreStart' => true, + 'codeCoverageIgnoreEnd' => true, + 'covers' => true, + 'coversDefaultClass' => true, + 'coversNothing' => true, + 'dataProvider' => true, + 'depends' => true, + 'doesNotPerformAssertions' => true, + 'expectedException' => true, + 'expectedExceptionCode' => true, + 'expectedExceptionMessage' => true, + 'expectedExceptionMessageRegExp' => true, + 'group' => true, + 'large' => true, + 'medium' => true, + 'preserveGlobalState' => true, + 'requires' => true, + 'runTestsInSeparateProcesses' => true, + 'runInSeparateProcess' => true, + 'small' => true, + 'test' => true, + 'testdox' => true, + 'testWith' => true, + 'ticket' => true, + 'uses' => true, + ]; + + private const PhpCheckStyle = ['SuppressWarnings' => true]; + + private const PhpStorm = ['noinspection' => true]; + + private const PEAR = ['package_version' => true]; + + private const PlainUML = [ + 'startuml' => true, + 'enduml' => true, + ]; + + private const Symfony = ['experimental' => true]; + + private const PhpCodeSniffer = [ + 'codingStandardsIgnoreStart' => true, + 'codingStandardsIgnoreEnd' => true, + ]; + + private const SlevomatCodingStandard = ['phpcsSuppress' => true]; + + private const PhpStan = [ + 'extends' => true, + 'implements' => true, + 'template' => true, + 'use' => true, + ]; + + private const Phan = [ + 'suppress' => true, + ]; + + public const LIST = self::Reserved + + self::WidelyUsedNonStandard + + self::PhpDocumentor1 + + self::PhpDocumentor2 + + self::PHPUnit + + self::PhpCheckStyle + + self::PhpStorm + + self::PEAR + + self::PlainUML + + self::Symfony + + self::SlevomatCodingStandard + + self::PhpCodeSniffer + + self::PhpStan + + self::Phan; + + private function __construct() + { + } +} diff --git a/lib/Doctrine/Common/Annotations/IndexedReader.php b/lib/Doctrine/Common/Annotations/IndexedReader.php index e5887e795..42e70765d 100644 --- a/lib/Doctrine/Common/Annotations/IndexedReader.php +++ b/lib/Doctrine/Common/Annotations/IndexedReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/PhpParser.php b/lib/Doctrine/Common/Annotations/PhpParser.php index 9415c9d62..28c059978 100644 --- a/lib/Doctrine/Common/Annotations/PhpParser.php +++ b/lib/Doctrine/Common/Annotations/PhpParser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/Reader.php b/lib/Doctrine/Common/Annotations/Reader.php index b1c8680ac..c306574f1 100644 --- a/lib/Doctrine/Common/Annotations/Reader.php +++ b/lib/Doctrine/Common/Annotations/Reader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php b/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php index 99d574d54..8a78c119d 100644 --- a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -28,6 +11,8 @@ * * This annotation reader is intended to be used in projects where you have * full-control over all annotations that are available. + * + * @deprecated Deprecated in favour of using AnnotationReader */ class SimpleAnnotationReader implements Reader { diff --git a/lib/Doctrine/Common/Annotations/TokenParser.php b/lib/Doctrine/Common/Annotations/TokenParser.php index a5b00b9f4..28512fdce 100644 --- a/lib/Doctrine/Common/Annotations/TokenParser.php +++ b/lib/Doctrine/Common/Annotations/TokenParser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 81dcf1c07..dd64fe185 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -146,4 +146,9 @@ */tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php */tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceWithConstants.php + + + + */lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php + diff --git a/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php b/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php index fef1f89c8..c90bcebb1 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\Annotations\Annotation;