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 dd346eec7..06f5b502f 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"}, diff --git a/docs/en/annotations.rst b/docs/en/annotations.rst index 1984dba5f..3fdf7cd96 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 7a6be485b..abcd8770c 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, 'bar'); + $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 a79a0f8f0..9defff90e 100644 --- a/lib/Doctrine/Common/Annotations/Annotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -32,7 +15,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 dbef6df08..4bc2ad7b2 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 53134e309..47f6c4605 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 82f6241ec..bb0c74586 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; /** diff --git a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php index 85ec3d6dd..2c4171ab4 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 d67f96068..2d64c4e3e 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 a52972b8b..d4f3326e1 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; /** diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index d06fe663c..74732e8e6 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 a767f7bee..68dd54b67 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/AnnotationReader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; @@ -52,64 +35,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 ceb7eb7e0..7a1aef7c0 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 8ed16f1a0..504ad0b9a 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 8182f6c6e..cc3da1d69 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 3ac48e3fc..edbb5a18c 100644 --- a/lib/Doctrine/Common/Annotations/DocParser.php +++ b/lib/Doctrine/Common/Annotations/DocParser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\Annotations; diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php index 40141af28..a9b9de745 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..169a46558 --- /dev/null +++ b/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php @@ -0,0 +1,175 @@ + 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, + ]; + + 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; + + private function __construct() + { + } +} diff --git a/lib/Doctrine/Common/Annotations/IndexedReader.php b/lib/Doctrine/Common/Annotations/IndexedReader.php index 4e8c3c8c3..bf2334506 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 ec871813b..686cc04d8 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 4774f8731..8f34c5b2b 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 d4757eea2..0dd139374 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,7 @@ * @since 2.2 * @author Johannes M. Schmitt * @author Fabio B. Silva + * @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 03d9320ab..4c8ba5b97 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/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php b/tests/Doctrine/Tests/Common/Annotations/Annotation/TargetTest.php index 69a953e15..36c71b7c6 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;