diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6d4666748..bd2f80424 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -22,6 +22,7 @@ jobs: with: coverage: "none" php-version: "${{ matrix.php-version }}" + tools: "cs2pr" - name: "Cache dependencies installed with composer" uses: "actions/cache@v1" @@ -33,6 +34,5 @@ jobs: - name: "Install dependencies with composer" run: "composer install --no-interaction --no-progress --no-suggest" - # https://github.com/doctrine/annotations/issues/349 - name: "Run PHP Code Beautifier" - run: "vendor/bin/phpcbf" + run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" diff --git a/lib/Doctrine/Common/Annotations/Annotation.php b/lib/Doctrine/Common/Annotations/Annotation.php index 70f6a98e2..750270e42 100644 --- a/lib/Doctrine/Common/Annotations/Annotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation.php @@ -19,7 +19,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) { diff --git a/lib/Doctrine/Common/Annotations/Annotation/Enum.php b/lib/Doctrine/Common/Annotations/Annotation/Enum.php index 574b5af5a..35d6410b1 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Enum.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Enum.php @@ -23,20 +23,20 @@ */ final class Enum { - /** @var array */ + /** @phpstan-var list */ public $value; /** * Literal target declaration. * - * @var array + * @var mixed[] */ public $literal; /** - * @param array $values - * * @throws InvalidArgumentException + * + * @phpstan-param array{literal?: mixed[], value: list} $values */ public function __construct(array $values) { diff --git a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php index b1ae745d9..ae60f7d5b 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php @@ -17,13 +17,13 @@ */ final class IgnoreAnnotation { - /** @var array */ + /** @phpstan-var list */ public $names; /** - * @param array $values - * * @throws RuntimeException + * + * @phpstan-param array{value: string|list} $values */ public function __construct(array $values) { @@ -32,7 +32,10 @@ public function __construct(array $values) } if (! is_array($values['value'])) { - throw new RuntimeException(sprintf('@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.', json_encode($values['value']))); + throw new RuntimeException(sprintf( + '@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.', + json_encode($values['value']) + )); } $this->names = $values['value']; diff --git a/lib/Doctrine/Common/Annotations/Annotation/Target.php b/lib/Doctrine/Common/Annotations/Annotation/Target.php index 3f785d8bc..9cf9a2eb9 100644 --- a/lib/Doctrine/Common/Annotations/Annotation/Target.php +++ b/lib/Doctrine/Common/Annotations/Annotation/Target.php @@ -27,7 +27,7 @@ final class Target public const TARGET_ANNOTATION = 8; public const TARGET_ALL = 15; - /** @var array */ + /** @var array */ private static $map = [ 'ALL' => self::TARGET_ALL, 'CLASS' => self::TARGET_CLASS, @@ -36,7 +36,7 @@ final class Target 'ANNOTATION' => self::TARGET_ANNOTATION, ]; - /** @var array */ + /** @phpstan-var list */ public $value; /** @@ -54,9 +54,9 @@ final class Target public $literal; /** - * @param array $values - * * @throws InvalidArgumentException + * + * @phpstan-param array{value?: string|list} $values */ public function __construct(array $values) { diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index f8ad9ab2e..84d6660f8 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationException.php +++ b/lib/Doctrine/Common/Annotations/AnnotationException.php @@ -128,18 +128,19 @@ public static function requiredError($attributeName, $annotationName, $context, /** * Creates a new AnnotationException describing a invalid enummerator. * - * @param string $attributeName - * @param string $annotationName - * @param string $context - * @param array $available - * @param mixed $given + * @param string $attributeName + * @param string $annotationName + * @param string $context + * @param object|class-string $given * * @return AnnotationException + * + * @phpstan-param list $available */ public static function enumeratorError($attributeName, $annotationName, $context, $available, $given) { return new self(sprintf( - '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.', + '[Enum Error] Attribute "%s" of @%s declared on %s accepts only [%s], but got %s.', $attributeName, $annotationName, $context, diff --git a/lib/Doctrine/Common/Annotations/AnnotationReader.php b/lib/Doctrine/Common/Annotations/AnnotationReader.php index 6f976c7ac..98b32b2d5 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/AnnotationReader.php @@ -21,7 +21,7 @@ class AnnotationReader implements Reader /** * Global map for imports. * - * @var array + * @var array */ private static $globalImports = [ 'ignoreannotation' => Annotation\IgnoreAnnotation::class, @@ -32,7 +32,7 @@ class AnnotationReader implements Reader * * The names are case sensitive. * - * @var array + * @var array */ private static $globalIgnoredNames = ImplicitlyIgnoredAnnotationNames::LIST; @@ -41,7 +41,7 @@ class AnnotationReader implements Reader * * The names are case sensitive. * - * @var array + * @var array */ private static $globalIgnoredNamespaces = []; @@ -89,14 +89,14 @@ public static function addGlobalIgnoredNamespace($namespace) /** * In-memory cache mechanism to store imported annotations per class. * - * @var array + * @var array> */ private $imports = []; /** * In-memory cache mechanism to store ignored annotations per class. * - * @var array + * @var array> */ private $ignoredAnnotationNames = []; @@ -107,7 +107,10 @@ public static function addGlobalIgnoredNamespace($namespace) */ public function __construct(?DocParser $parser = null) { - if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === '0' || ini_get('opcache.save_comments') === '0')) { + if ( + extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === '0' || + ini_get('opcache.save_comments') === '0') + ) { throw AnnotationException::optimizerPlusSaveComments(); } @@ -225,7 +228,7 @@ public function getMethodAnnotation(ReflectionMethod $method, $annotationName) /** * Returns the ignored annotations for the given class. * - * @return array + * @return array */ private function getIgnoredAnnotationNames(ReflectionClass $class) { @@ -242,7 +245,7 @@ private function getIgnoredAnnotationNames(ReflectionClass $class) /** * Retrieves imports. * - * @return array + * @return array */ private function getClassImports(ReflectionClass $class) { @@ -259,7 +262,7 @@ private function getClassImports(ReflectionClass $class) /** * Retrieves imports for methods. * - * @return array + * @return array */ private function getMethodImports(ReflectionMethod $method) { @@ -285,7 +288,7 @@ private function getMethodImports(ReflectionMethod $method) /** * Retrieves imports for properties. * - * @return array + * @return array */ private function getPropertyImports(ReflectionProperty $property) { diff --git a/lib/Doctrine/Common/Annotations/AnnotationRegistry.php b/lib/Doctrine/Common/Annotations/AnnotationRegistry.php index 4684750b7..259d497dd 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationRegistry.php +++ b/lib/Doctrine/Common/Annotations/AnnotationRegistry.php @@ -59,7 +59,8 @@ public static function reset(): void /** * Registers file. * - * @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. + * @deprecated This method is deprecated and will be removed in + * doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. */ public static function registerFile(string $file): void { @@ -73,9 +74,10 @@ public static function registerFile(string $file): void * * Loading of this namespaces will be done with a PSR-0 namespace loading algorithm. * - * @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. + * @deprecated This method is deprecated and will be removed in + * doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. * - * @param string|array|null $dirs + * @phpstan-param string|list|null $dirs */ public static function registerAutoloadNamespace(string $namespace, $dirs = null): void { @@ -87,7 +89,8 @@ public static function registerAutoloadNamespace(string $namespace, $dirs = null * * Loading of this namespaces will be done with a PSR-0 namespace loading algorithm. * - * @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. + * @deprecated This method is deprecated and will be removed in + * doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. * * @param string[][]|string[]|null[] $namespaces indexed by namespace name */ @@ -102,7 +105,8 @@ public static function registerAutoloadNamespaces(array $namespaces): void * NOTE: These class loaders HAVE to be silent when a class was not found! * IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class. * - * @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. + * @deprecated This method is deprecated and will be removed in + * doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. */ public static function registerLoader(callable $callable): void { @@ -114,7 +118,8 @@ public static function registerLoader(callable $callable): void /** * Registers an autoloading callable for annotations, if it is not already registered * - * @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. + * @deprecated This method is deprecated and will be removed in + * doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. */ public static function registerUniqueLoader(callable $callable): void { @@ -146,7 +151,8 @@ public static function loadAnnotationClass(string $class): bool $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; if ($dirs === null) { - if ($path = stream_resolve_include_path($file)) { + $path = stream_resolve_include_path($file); + if ($path) { require $path; return true; @@ -168,7 +174,12 @@ public static function loadAnnotationClass(string $class): bool } } - if (self::$loaders === [] && self::$autoloadNamespaces === [] && self::$registerFileUsed === false && class_exists($class)) { + if ( + self::$loaders === [] && + self::$autoloadNamespaces === [] && + self::$registerFileUsed === false && + class_exists($class) + ) { return true; } diff --git a/lib/Doctrine/Common/Annotations/CachedReader.php b/lib/Doctrine/Common/Annotations/CachedReader.php index ea88464b7..91fbad0c6 100644 --- a/lib/Doctrine/Common/Annotations/CachedReader.php +++ b/lib/Doctrine/Common/Annotations/CachedReader.php @@ -28,7 +28,7 @@ final class CachedReader implements Reader /** @var bool */ private $debug; - /** @var array */ + /** @var array> */ private $loadedAnnotations = []; /** @var int[] */ @@ -55,7 +55,8 @@ public function getClassAnnotations(ReflectionClass $class) return $this->loadedAnnotations[$cacheKey]; } - if (($annots = $this->fetchFromCache($cacheKey, $class)) === false) { + $annots = $this->fetchFromCache($cacheKey, $class); + if ($annots === false) { $annots = $this->delegate->getClassAnnotations($class); $this->saveToCache($cacheKey, $annots); } @@ -89,7 +90,8 @@ public function getPropertyAnnotations(ReflectionProperty $property) return $this->loadedAnnotations[$cacheKey]; } - if (($annots = $this->fetchFromCache($cacheKey, $class)) === false) { + $annots = $this->fetchFromCache($cacheKey, $class); + if ($annots === false) { $annots = $this->delegate->getPropertyAnnotations($property); $this->saveToCache($cacheKey, $annots); } @@ -123,7 +125,8 @@ public function getMethodAnnotations(ReflectionMethod $method) return $this->loadedAnnotations[$cacheKey]; } - if (($annots = $this->fetchFromCache($cacheKey, $class)) === false) { + $annots = $this->fetchFromCache($cacheKey, $class); + if ($annots === false) { $annots = $this->delegate->getMethodAnnotations($method); $this->saveToCache($cacheKey, $annots); } @@ -165,7 +168,8 @@ public function clearLoadedAnnotations() */ private function fetchFromCache($cacheKey, ReflectionClass $class) { - if (($data = $this->cache->fetch($cacheKey)) !== false) { + $data = $this->cache->fetch($cacheKey); + if ($data !== false) { if (! $this->debug || $this->isCacheFresh($cacheKey, $class)) { return $data; } @@ -211,10 +215,8 @@ private function isCacheFresh($cacheKey, ReflectionClass $class) /** * Returns the time the class was last modified, testing traits and parents - * - * @return int */ - private function getLastModification(ReflectionClass $class) + private function getLastModification(ReflectionClass $class): int { $filename = $class->getFileName(); @@ -226,8 +228,12 @@ private function getLastModification(ReflectionClass $class) $lastModification = max(array_merge( [$filename ? filemtime($filename) : 0], - array_map([$this, 'getTraitLastModificationTime'], $class->getTraits()), - array_map([$this, 'getLastModification'], $class->getInterfaces()), + array_map(function (ReflectionClass $reflectionTrait): int { + return $this->getTraitLastModificationTime($reflectionTrait); + }, $class->getTraits()), + array_map(function (ReflectionClass $class): int { + return $this->getLastModification($class); + }, $class->getInterfaces()), $parent ? [$this->getLastModification($parent)] : [] )); @@ -236,10 +242,7 @@ private function getLastModification(ReflectionClass $class) return $this->loadedFilemtimes[$filename] = $lastModification; } - /** - * @return int - */ - private function getTraitLastModificationTime(ReflectionClass $reflectionTrait) + private function getTraitLastModificationTime(ReflectionClass $reflectionTrait): int { $fileName = $reflectionTrait->getFileName(); @@ -249,7 +252,9 @@ private function getTraitLastModificationTime(ReflectionClass $reflectionTrait) $lastModificationTime = max(array_merge( [$fileName ? filemtime($fileName) : 0], - array_map([$this, 'getTraitLastModificationTime'], $reflectionTrait->getTraits()) + array_map(function (ReflectionClass $reflectionTrait): int { + return $this->getTraitLastModificationTime($reflectionTrait); + }, $reflectionTrait->getTraits()) )); assert($lastModificationTime !== false); diff --git a/lib/Doctrine/Common/Annotations/DocLexer.php b/lib/Doctrine/Common/Annotations/DocLexer.php index a9d032435..f6567c512 100644 --- a/lib/Doctrine/Common/Annotations/DocLexer.php +++ b/lib/Doctrine/Common/Annotations/DocLexer.php @@ -39,7 +39,7 @@ final class DocLexer extends AbstractLexer public const T_COLON = 112; public const T_MINUS = 113; - /** @var array */ + /** @var array */ protected $noCase = [ '@' => self::T_AT, ',' => self::T_COMMA, @@ -53,7 +53,7 @@ final class DocLexer extends AbstractLexer '\\' => self::T_NAMESPACE_SEPARATOR, ]; - /** @var array */ + /** @var array */ protected $withCase = [ 'true' => self::T_TRUE, 'false' => self::T_FALSE, diff --git a/lib/Doctrine/Common/Annotations/DocParser.php b/lib/Doctrine/Common/Annotations/DocParser.php index 1955f0eda..031ef55ba 100644 --- a/lib/Doctrine/Common/Annotations/DocParser.php +++ b/lib/Doctrine/Common/Annotations/DocParser.php @@ -48,7 +48,7 @@ final class DocParser /** * An array of all valid tokens for a class name. * - * @var array + * @phpstan-var list */ private static $classIdentifiers = [ DocLexer::T_IDENTIFIER, @@ -89,7 +89,7 @@ final class DocParser * Hashmap containing all use-statements that are to be used when parsing * the given doc block. * - * @var array + * @var array */ private $imports = []; @@ -97,7 +97,7 @@ final class DocParser * This hashmap is used internally to cache results of class_exists() * look-ups. * - * @var array + * @var array */ private $classExists = []; @@ -138,7 +138,7 @@ final class DocParser /** * Hash-map for caching annotation metadata. * - * @var array + * @var array */ private static $annotationMetadata = [ Annotation\Target::class => [ @@ -225,7 +225,7 @@ final class DocParser /** * Hash-map for handle types declaration. * - * @var array + * @var array */ private static $typeMap = [ 'float' => 'double', @@ -303,7 +303,7 @@ public function addNamespace($namespace) /** * Sets the imports. * - * @param array $imports + * @param array $imports * * @return void * @@ -336,10 +336,10 @@ public function setTarget($target) * @param string $input The docblock string to parse. * @param string $context The parsing context. * - * @return array 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 = '') { @@ -406,6 +406,8 @@ private function match(int $token): bool * a syntax error is raised. * * @throws AnnotationException + * + * @phpstan-param list $tokens */ private function matchAny(array $tokens): bool { @@ -419,8 +421,8 @@ private function matchAny(array $tokens): bool /** * Generates a new syntax error. * - * @param string $expected Expected string. - * @param array|null $token Optional token. + * @param string $expected Expected string. + * @param mixed[]|null $token Optional token. */ private function syntaxError(string $expected, ?array $token = null): AnnotationException { @@ -445,6 +447,8 @@ private function syntaxError(string $expected, ?array $token = null): Annotation /** * Attempts to check if a class exists or not. This never goes through the PHP autoloading mechanism * but uses the {@link AnnotationRegistry} to load classes. + * + * @param class-string $fqcn */ private function classExists(string $fqcn): bool { @@ -464,7 +468,7 @@ private function classExists(string $fqcn): bool /** * Collects parsing metadata for a given annotation class * - * @param string $name The annotation name + * @param class-string $name The annotation name * * @throws AnnotationException * @throws ReflectionException @@ -494,9 +498,10 @@ class_exists(Attributes::class); $docComment = $class->getDocComment(); // Sets default values for annotation metadata - $metadata = [ + $constructor = $class->getConstructor(); + $metadata = [ 'default_property' => null, - 'has_constructor' => (null !== $constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0, + 'has_constructor' => $constructor !== null && $constructor->getNumberOfParameters() > 0, 'properties' => [], 'property_types' => [], 'attribute_types' => [], @@ -532,7 +537,8 @@ class_exists(Attributes::class); foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { $metadata['properties'][$property->name] = $property->name; - if (($propertyComment = $property->getDocComment()) === false) { + $propertyComment = $property->getDocComment(); + if ($propertyComment === false) { continue; } @@ -540,7 +546,8 @@ class_exists(Attributes::class); $attribute->required = (strpos($propertyComment, '@Required') !== false); $attribute->name = $property->name; - $attribute->type = (strpos($propertyComment, '@var') !== false && preg_match('/@var\s+([^\s]+)/', $propertyComment, $matches)) + $attribute->type = (strpos($propertyComment, '@var') !== false && + preg_match('/@var\s+([^\s]+)/', $propertyComment, $matches)) ? $matches[1] : 'mixed'; @@ -577,6 +584,8 @@ class_exists(Attributes::class); /** * Collects parsing metadata for a given attribute. + * + * @param mixed[] $metadata */ private function collectAttributeTypeMetadata(array &$metadata, Attribute $attribute): void { @@ -589,21 +598,21 @@ private function collectAttributeTypeMetadata(array &$metadata, Attribute $attri } // Evaluate type - switch (true) { + $pos = strpos($type, '<'); + if ($pos !== false) { // Checks if the property has array - case (false !== $pos = strpos($type, '<')): - $arrayType = substr($type, $pos + 1, -1); - $type = 'array'; - - if (isset(self::$typeMap[$arrayType])) { - $arrayType = self::$typeMap[$arrayType]; - } + $arrayType = substr($type, $pos + 1, -1); + $type = 'array'; - $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType; - break; + if (isset(self::$typeMap[$arrayType])) { + $arrayType = self::$typeMap[$arrayType]; + } + $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType; + } else { // Checks if the property has type[] - case (false !== $pos = strrpos($type, '[')): + $pos = strrpos($type, '['); + if ($pos !== false) { $arrayType = substr($type, 0, $pos); $type = 'array'; @@ -612,7 +621,7 @@ private function collectAttributeTypeMetadata(array &$metadata, Attribute $attri } $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType; - break; + } } $metadata['attribute_types'][$attribute->name]['type'] = $type; @@ -625,6 +634,8 @@ private function collectAttributeTypeMetadata(array &$metadata, Attribute $attri * * @throws AnnotationException * @throws ReflectionException + * + * @phpstan-return list */ private function Annotations(): array { @@ -637,16 +648,26 @@ private function Annotations(): array } // make sure the @ is preceded by non-catchable pattern - if ($this->lexer->token !== null && $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen($this->lexer->token['value'])) { + if ( + $this->lexer->token !== null && + $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen( + $this->lexer->token['value'] + ) + ) { $this->lexer->moveNext(); continue; } // make sure the @ is followed by either a namespace separator, or // an identifier token + $peek = $this->lexer->glimpse(); if ( - (null === $peek = $this->lexer->glimpse()) - || ($peek['type'] !== DocLexer::T_NAMESPACE_SEPARATOR && ! in_array($peek['type'], self::$classIdentifiers, true)) + ($peek === null) + || ($peek['type'] !== DocLexer::T_NAMESPACE_SEPARATOR && ! in_array( + $peek['type'], + self::$classIdentifiers, + true + )) || $peek['position'] !== $this->lexer->lookahead['position'] + 1 ) { $this->lexer->moveNext(); @@ -654,7 +675,8 @@ private function Annotations(): array } $this->isNestedAnnotation = false; - if (false === $annot = $this->Annotation()) { + $annot = $this->Annotation(); + if ($annot === false) { continue; } @@ -671,7 +693,7 @@ private function Annotations(): array * NameSpacePart ::= identifier | null | false | true * SimpleName ::= identifier | null | false | true * - * @return mixed False if it is not a valid annotation. + * @return object|false False if it is not a valid annotation. * * @throws AnnotationException * @throws ReflectionException @@ -731,14 +753,25 @@ private function Annotation() return false; } - throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context)); + throw AnnotationException::semanticalError(sprintf( + <<<'EXCEPTION' +The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation? +EXCEPTION + , + $name, + $this->context + )); } } $name = ltrim($name, '\\'); if (! $this->classExists($name)) { - throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context)); + throw AnnotationException::semanticalError(sprintf( + 'The annotation "@%s" in %s does not exist, or could not be auto-loaded.', + $name, + $this->context + )); } // at this point, $name contains the fully qualified class name of the @@ -756,7 +789,19 @@ private function Annotation() return false; } - throw AnnotationException::semanticalError(sprintf('The class "%s" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "%s". If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.', $name, $name, $originalName, $this->context)); + throw AnnotationException::semanticalError(sprintf( + <<<'EXCEPTION' +The class "%s" is not annotated with @Annotation. +Are you sure this class can be used as annotation? +If so, then you need to add @Annotation to the _class_ doc comment of "%s". +If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s. +EXCEPTION + , + $name, + $name, + $originalName, + $this->context + )); } //if target is nested annotation @@ -769,7 +814,10 @@ private function Annotation() if ((self::$annotationMetadata[$name]['targets'] & $target) === 0 && $target) { throw AnnotationException::semanticalError( sprintf( - 'Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.', + <<<'EXCEPTION' +Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s. +EXCEPTION + , $originalName, $this->context, self::$annotationMetadata[$name]['targets_literal'] @@ -784,7 +832,13 @@ private function Annotation() foreach (self::$annotationMetadata[$name]['enum'] as $property => $enum) { // checks if the attribute is a valid enumerator if (isset($values[$property]) && ! in_array($values[$property], $enum['value'])) { - throw AnnotationException::enumeratorError($property, $name, $this->context, $enum['literal'], $values[$property]); + throw AnnotationException::enumeratorError( + $property, + $name, + $this->context, + $enum['literal'], + $values[$property] + ); } } } @@ -801,7 +855,12 @@ private function Annotation() // handle a not given attribute or null value if (! isset($values[$property])) { if ($type['required']) { - throw AnnotationException::requiredError($property, $originalName, $this->context, 'a(n) ' . $type['value']); + throw AnnotationException::requiredError( + $property, + $originalName, + $this->context, + 'a(n) ' . $type['value'] + ); } continue; @@ -817,12 +876,24 @@ private function Annotation() if (isset($type['array_type'])) { foreach ($values[$property] as $item) { if (gettype($item) !== $type['array_type'] && ! $item instanceof $type['array_type']) { - throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'either a(n) ' . $type['array_type'] . ', or an array of ' . $type['array_type'] . 's', $item); + throw AnnotationException::attributeTypeError( + $property, + $originalName, + $this->context, + 'either a(n) ' . $type['array_type'] . ', or an array of ' . $type['array_type'] . 's', + $item + ); } } } } elseif (gettype($values[$property]) !== $type['type'] && ! $values[$property] instanceof $type['type']) { - throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'a(n) ' . $type['value'], $values[$property]); + throw AnnotationException::attributeTypeError( + $property, + $originalName, + $this->context, + 'a(n) ' . $type['value'], + $values[$property] + ); } } @@ -837,12 +908,28 @@ private function Annotation() foreach ($values as $property => $value) { if (! isset(self::$annotationMetadata[$name]['properties'][$property])) { if ($property !== 'value') { - throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not have a property named "%s". Available properties: %s', $originalName, $this->context, $property, implode(', ', self::$annotationMetadata[$name]['properties']))); + throw AnnotationException::creationError(sprintf( + <<<'EXCEPTION' +The annotation @%s declared on %s does not have a property named "%s". +Available properties: %s +EXCEPTION + , + $originalName, + $this->context, + $property, + implode(', ', self::$annotationMetadata[$name]['properties']) + )); } // handle the case if the property has no annotations - if (! $property = self::$annotationMetadata[$name]['default_property']) { - throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not accept any values, but got %s.', $originalName, $this->context, json_encode($values))); + $property = self::$annotationMetadata[$name]['default_property']; + if (! $property) { + throw AnnotationException::creationError(sprintf( + 'The annotation @%s declared on %s does not accept any values, but got %s.', + $originalName, + $this->context, + json_encode($values) + )); } } @@ -855,6 +942,8 @@ private function Annotation() /** * MethodCall ::= ["(" [Values] ")"] * + * @return mixed[] + * * @throws AnnotationException * @throws ReflectionException */ @@ -880,6 +969,8 @@ private function MethodCall(): array /** * Values ::= Array | Value {"," Value}* [","] * + * @return mixed[] + * * @throws AnnotationException * @throws ReflectionException */ @@ -982,7 +1073,10 @@ private function Constant() /** * Checks if identifier ends with ::class and remove the leading backslash if it exists. */ - if ($this->identifierEndsWithClassConstant($identifier) && ! $this->identifierStartsWithBackslash($identifier)) { + if ( + $this->identifierEndsWithClassConstant($identifier) && + ! $this->identifierStartsWithBackslash($identifier) + ) { return substr($identifier, 0, $this->getClassConstantPositionInIdentifier($identifier)); } @@ -1033,7 +1127,8 @@ private function Identifier(): string while ( $this->lexer->lookahead !== null && - $this->lexer->lookahead['position'] === ($this->lexer->token['position'] + strlen($this->lexer->token['value'])) && + $this->lexer->lookahead['position'] === ($this->lexer->token['position'] + + strlen($this->lexer->token['value'])) && $this->lexer->isNextToken(DocLexer::T_NAMESPACE_SEPARATOR) ) { $this->match(DocLexer::T_NAMESPACE_SEPARATOR); @@ -1146,6 +1241,8 @@ private function FieldAssignment(): stdClass /** * Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}" * + * @return mixed[] + * * @throws AnnotationException * @throws ReflectionException */ @@ -1197,6 +1294,8 @@ private function Arrayx(): array * * @throws AnnotationException * @throws ReflectionException + * + * @phpstan-return array{mixed, mixed} */ private function ArrayEntry(): array { diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php index 81e454beb..e6a7a958b 100644 --- a/lib/Doctrine/Common/Annotations/FileCacheReader.php +++ b/lib/Doctrine/Common/Annotations/FileCacheReader.php @@ -46,10 +46,10 @@ class FileCacheReader implements Reader /** @var bool */ private $debug; - /** @var array */ + /** @phpstan-var array> */ private $loadedAnnotations = []; - /** @var array */ + /** @var array */ private $classNameHashes = []; /** @var int */ @@ -58,6 +58,7 @@ class FileCacheReader implements Reader /** * @param string $cacheDir * @param bool $debug + * @param int $umask * * @throws InvalidArgumentException */ @@ -74,7 +75,10 @@ public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = $this->umask = $umask; if (! is_dir($cacheDir) && ! @mkdir($cacheDir, 0777 & (~$this->umask), true)) { - throw new InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $cacheDir)); + throw new InvalidArgumentException(sprintf( + 'The directory "%s" does not exist and could not be created.', + $cacheDir + )); } $this->dir = rtrim($cacheDir, '\\/'); @@ -104,9 +108,10 @@ public function getClassAnnotations(ReflectionClass $class) return $this->loadedAnnotations[$key] = $annot; } + $filename = $class->getFilename(); if ( $this->debug - && (false !== $filename = $class->getFileName()) + && $filename !== false && filemtime($path) < filemtime($filename) ) { @unlink($path); @@ -144,9 +149,10 @@ public function getPropertyAnnotations(ReflectionProperty $property) return $this->loadedAnnotations[$key] = $annot; } + $filename = $class->getFilename(); if ( $this->debug - && (false !== $filename = $class->getFilename()) + && $filename !== false && filemtime($path) < filemtime($filename) ) { @unlink($path); @@ -184,9 +190,10 @@ public function getMethodAnnotations(ReflectionMethod $method) return $this->loadedAnnotations[$key] = $annot; } + $filename = $class->getFilename(); if ( $this->debug - && (false !== $filename = $class->getFilename()) + && $filename !== false && filemtime($path) < filemtime($filename) ) { @unlink($path); @@ -211,7 +218,15 @@ public function getMethodAnnotations(ReflectionMethod $method) private function saveCacheFile($path, $data) { if (! is_writable($this->dir)) { - throw new InvalidArgumentException(sprintf('The directory "%s" is not writable. Both, the webserver and the console user need access. You can manage access rights for multiple users with "chmod +a". If your system does not support this, check out the acl package.', $this->dir)); + throw new InvalidArgumentException(sprintf( + <<<'EXCEPTION' +The directory "%s" is not writable. Both the webserver and the console user need access. +You can manage access rights for multiple users with "chmod +a". +If your system does not support this, check out the acl package., +EXCEPTION + , + $this->dir + )); } $tempfile = tempnam($this->dir, uniqid('', true)); @@ -222,7 +237,10 @@ private function saveCacheFile($path, $data) @chmod($tempfile, 0666 & (~$this->umask)); - $written = file_put_contents($tempfile, 'ReflectionClass object. * - * @return array A list with use statements in the form (Alias => FQN). + * @return array A list with use statements in the form (Alias => FQN). */ public function parseClass(ReflectionClass $class) { @@ -28,7 +28,9 @@ public function parseClass(ReflectionClass $class) return $class->getUseStatements(); } - if (false === $filename = $class->getFileName()) { + $filename = $class->getFileName(); + + if ($filename === false) { return []; } diff --git a/lib/Doctrine/Common/Annotations/Reader.php b/lib/Doctrine/Common/Annotations/Reader.php index 09731c704..c306574f1 100644 --- a/lib/Doctrine/Common/Annotations/Reader.php +++ b/lib/Doctrine/Common/Annotations/Reader.php @@ -17,9 +17,9 @@ interface Reader * @param ReflectionClass $class The ReflectionClass of the class from which * the class annotations should be read. * - * @return array An array of Annotations. + * @return array An array of Annotations. */ - function getClassAnnotations(ReflectionClass $class); + public function getClassAnnotations(ReflectionClass $class); /** * Gets a class annotation. @@ -30,7 +30,7 @@ function getClassAnnotations(ReflectionClass $class); * * @return object|null The Annotation or NULL, if the requested annotation does not exist. */ - function getClassAnnotation(ReflectionClass $class, $annotationName); + public function getClassAnnotation(ReflectionClass $class, $annotationName); /** * Gets the annotations applied to a method. @@ -38,9 +38,9 @@ function getClassAnnotation(ReflectionClass $class, $annotationName); * @param ReflectionMethod $method The ReflectionMethod of the method from which * the annotations should be read. * - * @return array An array of Annotations. + * @return array An array of Annotations. */ - function getMethodAnnotations(ReflectionMethod $method); + public function getMethodAnnotations(ReflectionMethod $method); /** * Gets a method annotation. @@ -50,7 +50,7 @@ function getMethodAnnotations(ReflectionMethod $method); * * @return object|null The Annotation or NULL, if the requested annotation does not exist. */ - function getMethodAnnotation(ReflectionMethod $method, $annotationName); + public function getMethodAnnotation(ReflectionMethod $method, $annotationName); /** * Gets the annotations applied to a property. @@ -58,9 +58,9 @@ function getMethodAnnotation(ReflectionMethod $method, $annotationName); * @param ReflectionProperty $property The ReflectionProperty of the property * from which the annotations should be read. * - * @return array An array of Annotations. + * @return array An array of Annotations. */ - function getPropertyAnnotations(ReflectionProperty $property); + public function getPropertyAnnotations(ReflectionProperty $property); /** * Gets a property annotation. @@ -70,5 +70,5 @@ function getPropertyAnnotations(ReflectionProperty $property); * * @return object|null The Annotation or NULL, if the requested annotation does not exist. */ - function getPropertyAnnotation(ReflectionProperty $property, $annotationName); + public function getPropertyAnnotation(ReflectionProperty $property, $annotationName); } diff --git a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php b/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php index 9d19c7970..8a78c119d 100644 --- a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php @@ -53,7 +53,10 @@ public function getClassAnnotations(ReflectionClass $class) */ public function getMethodAnnotations(ReflectionMethod $method) { - return $this->parser->parse($method->getDocComment(), 'method ' . $method->getDeclaringClass()->name . '::' . $method->getName() . '()'); + return $this->parser->parse( + $method->getDocComment(), + 'method ' . $method->getDeclaringClass()->name . '::' . $method->getName() . '()' + ); } /** @@ -61,7 +64,10 @@ public function getMethodAnnotations(ReflectionMethod $method) */ public function getPropertyAnnotations(ReflectionProperty $property) { - return $this->parser->parse($property->getDocComment(), 'property ' . $property->getDeclaringClass()->name . '::$' . $property->getName()); + return $this->parser->parse( + $property->getDocComment(), + 'property ' . $property->getDeclaringClass()->name . '::$' . $property->getName() + ); } /** diff --git a/lib/Doctrine/Common/Annotations/TokenParser.php b/lib/Doctrine/Common/Annotations/TokenParser.php index b645e0b9f..28512fdce 100644 --- a/lib/Doctrine/Common/Annotations/TokenParser.php +++ b/lib/Doctrine/Common/Annotations/TokenParser.php @@ -26,7 +26,7 @@ class TokenParser /** * The token list. * - * @var array + * @phpstan-var list */ private $tokens; @@ -69,7 +69,7 @@ public function __construct($contents) * @param bool $docCommentIsComment If TRUE then a doc comment is considered a comment and skipped. * If FALSE then only whitespace and normal comments are skipped. * - * @return array|null The token if exists, null otherwise. + * @return mixed[]|string|null The token if exists, null otherwise. */ public function next($docCommentIsComment = true) { @@ -92,7 +92,7 @@ public function next($docCommentIsComment = true) /** * Parses a single use statement. * - * @return array A list with all found class names for a use statement. + * @return array A list with all found class names for a use statement. */ public function parseUseStatement() { @@ -107,7 +107,10 @@ public function parseUseStatement() $alias = $token[1]; } elseif ($explicitAlias && $token[0] === T_STRING) { $alias = $token[1]; - } elseif (PHP_VERSION_ID >= 80000 && ($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)) { + } elseif ( + PHP_VERSION_ID >= 80000 && + ($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED) + ) { $class .= $token[1]; $classSplit = explode('\\', $token[1]); @@ -144,7 +147,7 @@ public function parseUseStatement() * * @param string $namespaceName The namespace name of the reflected class. * - * @return array A list with all found use statements. + * @return array A list with all found use statements. */ public function parseUseStatements($namespaceName) { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d65f87063..dd64fe185 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -40,6 +40,13 @@ + + */lib/Doctrine/Common/Annotations/DocParser.php + + + */tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassNoNamespaceNoComment.php + + */tests/Doctrine/Tests/Common/Annotations/Fixtures/* @@ -79,4 +86,69 @@ */tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php + + + + */tests/* + + + */tests/* + + + + */tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Test.php + */tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php + */tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php + */tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespaceWithClosureDeclaration.php + */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 + */tests/Doctrine/Tests/Common/Annotations/Fixtures/NonNamespacedClass.php + */tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Entity.php + */tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassNoNamespaceNoComment.php + */tests/Doctrine/Tests/Common/Annotations/TopLevelAnnotation.php + + + + + */tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php + */tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithValidAnnotationTarget.php + + + + + */tests/Doctrine/Tests/Common/Annotations/Fixtures/GroupUseStatement.php + + + */tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithVarType.php + + + + */tests/Doctrine/Tests/Common/Annotations/Fixtures/EmptyInterface.php + */tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php + + + + */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/AbstractReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php index 905cbf0bc..1ad529e7c 100644 --- a/tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php @@ -28,7 +28,7 @@ final protected function ignoreIssues(): void $this->expectException = false; } - public function getReflectionClass() + public function getReflectionClass(): ReflectionClass { return new ReflectionClass(DummyClass::class); } @@ -39,7 +39,10 @@ public function testAnnotations(): void $reader = $this->getReader(); self::assertCount(1, $reader->getClassAnnotations($class)); - self::assertInstanceOf($annotName = DummyAnnotation::class, $annot = $reader->getClassAnnotation($class, $annotName)); + self::assertInstanceOf( + $annotName = DummyAnnotation::class, + $annot = $reader->getClassAnnotation($class, $annotName) + ); self::assertEquals('hello', $annot->dummyValue); $field1Prop = $class->getProperty('field1'); @@ -57,7 +60,10 @@ public function testAnnotations(): void $field2Prop = $class->getProperty('field2'); $propAnnots = $reader->getPropertyAnnotations($field2Prop); self::assertCount(1, $propAnnots); - self::assertInstanceOf($annotName = DummyJoinTable::class, $joinTableAnnot = $reader->getPropertyAnnotation($field2Prop, $annotName)); + self::assertInstanceOf( + $annotName = DummyJoinTable::class, + $joinTableAnnot = $reader->getPropertyAnnotation($field2Prop, $annotName) + ); self::assertCount(1, $joinTableAnnot->joinColumns); self::assertCount(1, $joinTableAnnot->inverseJoinColumns); self::assertInstanceOf(DummyJoinColumn::class, $joinTableAnnot->joinColumns[0]); @@ -129,7 +135,11 @@ public function testClassWithInvalidAnnotationTargetAtClassDocBlock(): void $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Semantical Error] Annotation @AnnotationTargetPropertyMethod is not allowed to be declared on class Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtClass. You may only use this annotation on these code elements: METHOD, PROPERTY'); + $this->expectExceptionMessage( + '[Semantical Error] Annotation @AnnotationTargetPropertyMethod is not allowed to be declared on class' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtClass.' . + ' You may only use this annotation on these code elements: METHOD, PROPERTY' + ); } $reader->getClassAnnotations(new ReflectionClass(Fixtures\ClassWithInvalidAnnotationTargetAtClass::class)); @@ -147,10 +157,17 @@ public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock(): void $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$foo. You may only use this annotation on these code elements: CLASS'); + $this->expectExceptionMessage( + '[Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on property' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$foo. ' . + 'You may only use this annotation on these code elements: CLASS' + ); } - $reader->getPropertyAnnotations(new ReflectionProperty(Fixtures\ClassWithInvalidAnnotationTargetAtProperty::class, 'foo')); + $reader->getPropertyAnnotations(new ReflectionProperty( + Fixtures\ClassWithInvalidAnnotationTargetAtProperty::class, + 'foo' + )); } public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock(): void @@ -158,10 +175,17 @@ public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock(): $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Semantical Error] Annotation @AnnotationTargetAnnotation is not allowed to be declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$bar. You may only use this annotation on these code elements: ANNOTATION'); + $this->expectExceptionMessage( + '[Semantical Error] Annotation @AnnotationTargetAnnotation is not allowed to be declared on property' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$bar.' . + ' You may only use this annotation on these code elements: ANNOTATION' + ); } - $reader->getPropertyAnnotations(new ReflectionProperty(Fixtures\ClassWithInvalidAnnotationTargetAtProperty::class, 'bar')); + $reader->getPropertyAnnotations(new ReflectionProperty( + Fixtures\ClassWithInvalidAnnotationTargetAtProperty::class, + 'bar' + )); } public function testClassWithInvalidAnnotationTargetAtMethodDocBlock(): void @@ -169,34 +193,58 @@ public function testClassWithInvalidAnnotationTargetAtMethodDocBlock(): void $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtMethod::functionName(). You may only use this annotation on these code elements: CLASS'); + $this->expectExceptionMessage( + '[Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on method' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtMethod' . + '::functionName(). You may only use this annotation on these code elements: CLASS' + ); } - $reader->getMethodAnnotations(new ReflectionMethod(Fixtures\ClassWithInvalidAnnotationTargetAtMethod::class, 'functionName')); + $reader->getMethodAnnotations(new ReflectionMethod( + Fixtures\ClassWithInvalidAnnotationTargetAtMethod::class, + 'functionName' + )); } public function testClassWithAnnotationWithTargetSyntaxErrorAtClassDocBlock(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError."); - $reader->getClassAnnotations(new ReflectionClass(Fixtures\ClassWithAnnotationWithTargetSyntaxError::class)); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 24" . + ' in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.' + ); + $reader->getClassAnnotations(new ReflectionClass( + Fixtures\ClassWithAnnotationWithTargetSyntaxError::class + )); } public function testClassWithAnnotationWithTargetSyntaxErrorAtPropertyDocBlock(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError."); - $reader->getPropertyAnnotations(new ReflectionProperty(Fixtures\ClassWithAnnotationWithTargetSyntaxError::class, 'foo')); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 24" . + ' in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.' + ); + $reader->getPropertyAnnotations(new ReflectionProperty( + Fixtures\ClassWithAnnotationWithTargetSyntaxError::class, + 'foo' + )); } public function testClassWithAnnotationWithTargetSyntaxErrorAtMethodDocBlock(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError."); - $reader->getMethodAnnotations(new ReflectionMethod(Fixtures\ClassWithAnnotationWithTargetSyntaxError::class, 'bar')); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 24" . + ' in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.' + ); + $reader->getMethodAnnotations(new ReflectionMethod( + Fixtures\ClassWithAnnotationWithTargetSyntaxError::class, + 'bar' + )); } public function testClassWithPropertyInvalidVarTypeError(): void @@ -205,7 +253,11 @@ public function testClassWithPropertyInvalidVarTypeError(): void $class = new ReflectionClass(Fixtures\ClassWithAnnotationWithVarType::class); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Type Error] Attribute "string" of @AnnotationWithVarType declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::$invalidProperty expects a(n) string, but got integer.'); + $this->expectExceptionMessage( + '[Type Error] Attribute "string" of @AnnotationWithVarType declared on property' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::$invalidProperty' . + ' expects a(n) string, but got integer.' + ); $reader->getPropertyAnnotations($class->getProperty('invalidProperty')); } @@ -215,7 +267,12 @@ public function testClassWithMethodInvalidVarTypeError(): void $class = new ReflectionClass(Fixtures\ClassWithAnnotationWithVarType::class); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Type Error] Attribute "annotation" of @AnnotationWithVarType declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::invalidMethod() expects a(n) \Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll, but got an instance of Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation.'); + $this->expectExceptionMessage( + '[Type Error] Attribute "annotation" of @AnnotationWithVarType declared' . + ' on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::invalidMethod()' . + ' expects a(n) \Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,' . + ' but got an instance of Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation.' + ); $reader->getMethodAnnotations($class->getMethod('invalidMethod')); } @@ -223,7 +280,10 @@ public function testClassSyntaxErrorContext(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 18 in class Doctrine\Tests\Common\Annotations\DummyClassSyntaxError."); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 18" . + ' in class Doctrine\Tests\Common\Annotations\DummyClassSyntaxError.' + ); $reader->getClassAnnotations(new ReflectionClass(DummyClassSyntaxError::class)); } @@ -231,7 +291,10 @@ public function testMethodSyntaxErrorContext(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 18 in method Doctrine\Tests\Common\Annotations\DummyClassMethodSyntaxError::foo()."); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 18" . + ' in method Doctrine\Tests\Common\Annotations\DummyClassMethodSyntaxError::foo().' + ); $reader->getMethodAnnotations(new ReflectionMethod(DummyClassMethodSyntaxError::class, 'foo')); } @@ -239,9 +302,9 @@ public function testPropertySyntaxErrorContext(): void { $reader = $this->getReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage(<<<'EOT' -Expected namespace separator or identifier, got ')' at position 18 in property Doctrine\Tests\Common\Annotations\DummyClassPropertySyntaxError::$foo. -EOT + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')'" . + ' at position 36 in property Doctrine\Tests\Common\Annotations\DummyClassPropertySyntaxError::$foo.' ); $reader->getPropertyAnnotations(new ReflectionProperty(DummyClassPropertySyntaxError::class, 'foo')); } @@ -260,7 +323,10 @@ public function testNonAnnotationProblem(): void { $reader = $this->getReader(); - self::assertNotNull($annot = $reader->getPropertyAnnotation(new ReflectionProperty(DummyClassNonAnnotationProblem::class, 'foo'), $name = DummyAnnotation::class)); + self::assertNotNull($annot = $reader->getPropertyAnnotation( + new ReflectionProperty(DummyClassNonAnnotationProblem::class, 'foo'), + $name = DummyAnnotation::class + )); self::assertInstanceOf($name, $annot); } @@ -302,7 +368,10 @@ public function testImportDetectsNotImportedAnnotation(): void $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('The annotation "@NameFoo" in property Doctrine\Tests\Common\Annotations\TestAnnotationNotImportedClass::$field was never imported.'); + $this->expectExceptionMessage( + 'The annotation "@NameFoo" in property' . + ' Doctrine\Tests\Common\Annotations\TestAnnotationNotImportedClass::$field was never imported.' + ); } $reader->getPropertyAnnotations(new ReflectionProperty(TestAnnotationNotImportedClass::class, 'field')); @@ -313,7 +382,10 @@ public function testImportDetectsNonExistentAnnotation(): void $reader = $this->getReader(); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('The annotation "@Foo\Bar\Name" in property Doctrine\Tests\Common\Annotations\TestNonExistentAnnotationClass::$field was never imported.'); + $this->expectExceptionMessage( + 'The annotation "@Foo\Bar\Name" in property' . + ' Doctrine\Tests\Common\Annotations\TestNonExistentAnnotationClass::$field was never imported.' + ); } $reader->getPropertyAnnotations(new ReflectionProperty(TestNonExistentAnnotationClass::class, 'field')); @@ -322,7 +394,10 @@ public function testImportDetectsNonExistentAnnotation(): void public function testTopLevelAnnotation(): void { $reader = $this->getReader(); - $annotations = $reader->getPropertyAnnotations(new ReflectionProperty(TestTopLevelAnnotationClass::class, 'field')); + $annotations = $reader->getPropertyAnnotations(new ReflectionProperty( + TestTopLevelAnnotationClass::class, + 'field' + )); self::assertCount(1, $annotations); self::assertInstanceOf(TopLevelAnnotation::class, reset($annotations)); @@ -332,7 +407,10 @@ public function testIgnoresAnnotationsNotPrefixedWithWhitespace(): void { $reader = $this->getReader(); - $annotation = $reader->getClassAnnotation(new ReflectionClass(new TestIgnoresNonAnnotationsClass()), Name::class); + $annotation = $reader->getClassAnnotation( + new ReflectionClass(new TestIgnoresNonAnnotationsClass()), + Name::class + ); self::assertInstanceOf(Name::class, $annotation); } @@ -351,7 +429,9 @@ public function testResetsPhpParserAfterUse(): void { // If someone has already included our main test fixture this test is invalid. It's important that our require // causes this file to be parsed and compiled at a certain point. - self::assertFalse(! self::$testResetsPhpParserAfterUseRun && class_exists(Doctrine_Tests_Common_Annotations_Fixtures_ClassNoNamespaceNoComment::class), 'Test invalid if class has already been compiled'); + self::assertFalse(! self::$testResetsPhpParserAfterUseRun && class_exists( + Doctrine_Tests_Common_Annotations_Fixtures_ClassNoNamespaceNoComment::class + ), 'Test invalid if class has already been compiled'); self::$testResetsPhpParserAfterUseRun = true; $reader = $this->getReader(); @@ -362,7 +442,8 @@ public function testResetsPhpParserAfterUse(): void $class = new ReflectionClass(Fixtures\ClassWithValidAnnotationTarget::class); $reader->getClassAnnotations($class); - // Now import an incredibly dull class which makes use of the same class level annotation that the previous class does. + // Now import an incredibly dull class which makes use of the same + // class level annotation that the previous class does. $class = new ReflectionClass(Fixtures\ClassWithClassAnnotationOnly::class); $annotations = $reader->getClassAnnotations($class); @@ -378,8 +459,11 @@ public function testResetsPhpParserAfterUse(): void // compiler global state, and invalidating this test case. self::assertNotEmpty($annotations); - $annotations = $reader->getClassAnnotations(new ReflectionClass(new Doctrine_Tests_Common_Annotations_Fixtures_ClassNoNamespaceNoComment())); - // And if our workaround for this bug is OK, our class with no doc comment should not have any class annotations. + $annotations = $reader->getClassAnnotations(new ReflectionClass( + new Doctrine_Tests_Common_Annotations_Fixtures_ClassNoNamespaceNoComment() + )); + // And if our workaround for this bug is OK, our class with no doc + // comment should not have any class annotations. self::assertEmpty($annotations); } @@ -389,7 +473,14 @@ public function testErrorWhenInvalidAnnotationIsUsed(): void $ref = new ReflectionClass(Fixtures\InvalidAnnotationUsageClass::class); if ($this->expectException) { $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('The class "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation". If it is indeed no annotation, then you need to add @IgnoreAnnotation("NoAnnotation") to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageClass.'); + $this->expectExceptionMessage( + 'The class "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation" is not annotated with @Annotation. +Are you sure this class can be used as annotation? +If so, then you need to add @Annotation to the _class_ doc comment of' . + ' "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation". +If it is indeed no annotation, then you need to add @IgnoreAnnotation("NoAnnotation") to the _class_ doc comment' . + ' of class Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageClass.' + ); } $reader->getClassAnnotations($ref); @@ -434,14 +525,24 @@ public function testAnnotationEnumeratorException(): void $reader->getPropertyAnnotations($class->getProperty('invalidProperty')); $this->fail(); } catch (AnnotationException $exc) { - self::assertEquals('[Enum Error] Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationEnum::$invalidProperty accept only [ONE, TWO, THREE], but got FOUR.', $exc->getMessage()); + self::assertEquals( + '[Enum Error] Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum' . + ' declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationEnum' . + '::$invalidProperty accepts only [ONE, TWO, THREE], but got FOUR.', + $exc->getMessage() + ); } try { $reader->getMethodAnnotations($class->getMethod('invalidMethod')); $this->fail(); } catch (AnnotationException $exc) { - self::assertEquals('[Enum Error] Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationEnum::invalidMethod() accept only [ONE, TWO, THREE], but got 5.', $exc->getMessage()); + self::assertEquals( + '[Enum Error] Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum' . + ' declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationEnum' . + '::invalidMethod() accepts only [ONE, TWO, THREE], but got 5.', + $exc->getMessage() + ); } } @@ -489,7 +590,7 @@ abstract protected function getReader(): Reader; class TestParseAnnotationClass { /** @var */ - private $field; + public $field; } /** @@ -501,38 +602,56 @@ class TestIgnoresNonAnnotationsClass class TestTopLevelAnnotationClass { - /** @\TopLevelAnnotation */ - private $field; + /** + * @var mixed + * @\TopLevelAnnotation + */ + public $field; } class TestNonExistentAnnotationClass { - /** @Foo\Bar\Name */ - private $field; + /** + * @var mixed + * @Foo\Bar\Name + */ + public $field; } class TestAnnotationNotImportedClass { - /** @NameFoo */ - private $field; + /** + * @var mixed + * @NameFoo + */ + public $field; } class TestChildClass { - /** @\Doctrine\Tests\Common\Annotations\Foo\Name(name = "foo") */ + /** + * @var mixed + * @\Doctrine\Tests\Common\Annotations\Foo\Name(name = "foo") + */ protected $child; } class TestParentClass extends TestChildClass { - /** @\Doctrine\Tests\Common\Annotations\Bar\Name(name = "bar") */ - private $parent; + /** + * @var mixed + * @\Doctrine\Tests\Common\Annotations\Bar\Name(name = "bar") + */ + public $parent; } class TestImportWithConcreteAnnotation { - /** @DummyAnnotation(dummyValue = "bar") */ - private $field; + /** + * @var mixed + * @DummyAnnotation(dummyValue = "bar") + */ + public $field; } /** @@ -544,7 +663,7 @@ class DummyClass2 * @DummyId @DummyColumn(type="integer") @DummyGeneratedValue * @var int */ - private $id; + public $id; } /** @Annotation */ @@ -554,6 +673,7 @@ class DummyId extends Annotation /** @Annotation */ class DummyColumn extends Annotation { + /** @var mixed */ public $type; } /** @Annotation */ @@ -563,6 +683,7 @@ class DummyGeneratedValue extends Annotation /** @Annotation */ class DummyAnnotation extends Annotation { + /** @var mixed */ public $dummyValue; } @@ -571,20 +692,26 @@ class DummyAnnotation extends Annotation */ class DummyAnnotationWithIgnoredAnnotation extends Annotation { + /** @var mixed */ public $dummyValue; } /** @Annotation */ class DummyJoinColumn extends Annotation { + /** @var mixed */ public $name; + /** @var mixed */ public $referencedColumnName; } /** @Annotation */ class DummyJoinTable extends Annotation { + /** @var mixed */ public $name; + /** @var mixed */ public $joinColumns; + /** @var mixed */ public $inverseJoinColumns; } @@ -614,7 +741,10 @@ public function foo(): void class DummyClassPropertySyntaxError { - /** @DummyAnnotation(@) */ + /** + * @var mixed + * @DummyAnnotation(@) + */ public $foo; } @@ -654,6 +784,7 @@ class DCOM106 /** @Annotation */ class Name extends Annotation { + /** @var mixed */ public $name; } @@ -664,5 +795,6 @@ class Name extends Annotation /** @Annotation */ class Name extends Annotation { + /** @var mixed */ public $name; } diff --git a/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php index 2a90495ae..1cb7f61e2 100644 --- a/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php @@ -166,7 +166,9 @@ public function testGloballyIgnoredAnnotationNotIgnored(): void $class = new ReflectionClass(Fixtures\ClassDDC1660::class); $testLoader = static function (string $className): bool { if ($className === 'since') { - throw new InvalidArgumentException('Globally ignored annotation names should never be passed to an autoloader.'); + throw new InvalidArgumentException( + 'Globally ignored annotation names should never be passed to an autoloader.' + ); } return false; @@ -197,7 +199,11 @@ public function testPHPStanGenericsAnnotationsAreIgnored(): void self::assertEmpty($reader->getMethodAnnotations($ref->getMethod('foo'))); $this->expectException('\Doctrine\Common\Annotations\AnnotationException'); - $this->expectExceptionMessage('[Semantical Error] The annotation "@Template" in method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPStanGenericsAnnotations::twigTemplateFunctionName() was never imported.'); + $this->expectExceptionMessage( + '[Semantical Error] The annotation "@Template" in method' . + ' Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPStanGenericsAnnotations' . + '::twigTemplateFunctionName() was never imported.' + ); self::assertEmpty($reader->getMethodAnnotations($ref->getMethod('twigTemplateFunctionName'))); } diff --git a/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php index c739e9ea8..5fe6c733d 100644 --- a/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php @@ -14,6 +14,7 @@ class AnnotationRegistryTest extends TestCase { + /** @var string */ protected $class = AnnotationRegistry::class; /** @@ -56,7 +57,10 @@ public function testRegisterLoaderNoCallable(): void AnnotationRegistry::registerLoader('test' . random_int(10, 10000)); } - protected function setStaticField($class, $field, $value): void + /** + * @param mixed[] $value + */ + protected function setStaticField(string $class, string $field, array $value): void { $reflection = new ReflectionProperty($class, $field); @@ -64,7 +68,10 @@ protected function setStaticField($class, $field, $value): void $reflection->setValue(null, $value); } - protected function getStaticField($class, $field) + /** + * @return mixed + */ + protected function getStaticField(string $class, string $field) { $reflection = new ReflectionProperty($class, $field); diff --git a/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php index 377eca18a..cd87db49c 100644 --- a/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php @@ -19,6 +19,7 @@ class CachedReaderTest extends AbstractReaderTest { + /** @var int|ArrayCache */ private $cache; public function testIgnoresStaleCache(): void @@ -161,7 +162,7 @@ public function testAvoidCallingFilemtimeTooMuch(): void $route2->pattern = '/someotherprefix'; $cache = $this->createMock('Doctrine\Common\Cache\Cache'); - assert($cache instanceof Cache || $cache instanceof MockObject); + assert($cache instanceof Cache && $cache instanceof MockObject); $cache ->expects($this->exactly(6)) @@ -212,7 +213,7 @@ public function testAvoidCallingFilemtimeTooMuch(): void $this->assertEquals([$route2], $reader->getMethodAnnotations(new ReflectionMethod($className, 'method2'))); } - protected function doTestCacheStale($className, $lastCacheModification): CachedReader + protected function doTestCacheStale(string $className, int $lastCacheModification): CachedReader { $cacheKey = $className; @@ -245,7 +246,7 @@ protected function doTestCacheStale($className, $lastCacheModification): CachedR return $reader; } - protected function doTestCacheFresh($className, $lastCacheModification): void + protected function doTestCacheFresh(string $className, int $lastCacheModification): void { $cacheKey = $className; $route = new Route(); diff --git a/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php b/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php index 4c98db1d9..0df8a115a 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php @@ -31,7 +31,13 @@ public function testMarkerAnnotation(): void public function testScannerTokenizesDocBlockWhitConstants(): void { $lexer = new DocLexer(); - $docblock = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, ClassWithConstants::CONSTANT_, ClassWithConstants::CONST_ANT3, \Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_VALUE)'; + $docblock = '@AnnotationWithConstants( + PHP_EOL, + ClassWithConstants::SOME_VALUE, + ClassWithConstants::CONSTANT_, + ClassWithConstants::CONST_ANT3, + \Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_VALUE + )'; $tokens = [ [ @@ -51,52 +57,52 @@ public function testScannerTokenizesDocBlockWhitConstants(): void ], [ 'value' => 'PHP_EOL', - 'position' => 25, + 'position' => 38, 'type' => DocLexer::T_IDENTIFIER, ], [ 'value' => ',', - 'position' => 32, + 'position' => 45, 'type' => DocLexer::T_COMMA, ], [ 'value' => 'ClassWithConstants::SOME_VALUE', - 'position' => 34, + 'position' => 59, 'type' => DocLexer::T_IDENTIFIER, ], [ 'value' => ',', - 'position' => 64, + 'position' => 89, 'type' => DocLexer::T_COMMA, ], [ 'value' => 'ClassWithConstants::CONSTANT_', - 'position' => 66, + 'position' => 103, 'type' => DocLexer::T_IDENTIFIER, ], [ 'value' => ',', - 'position' => 95, + 'position' => 132, 'type' => DocLexer::T_COMMA, ], [ 'value' => 'ClassWithConstants::CONST_ANT3', - 'position' => 97, + 'position' => 146, 'type' => DocLexer::T_IDENTIFIER, ], [ 'value' => ',', - 'position' => 127, + 'position' => 176, 'type' => DocLexer::T_COMMA, ], [ 'value' => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\InterfaceWithConstants::SOME_VALUE', - 'position' => 129, + 'position' => 190, 'type' => DocLexer::T_IDENTIFIER, ], [ 'value' => ')', - 'position' => 207, + 'position' => 277, 'type' => DocLexer::T_CLOSE_PARENTHESIS, ], ]; @@ -274,6 +280,9 @@ public function testRecognizesNegativeNumbers(): void ); } + /** + * @phpstan-param list $expectedTokens + */ private function expectDocblockTokens(string $docBlock, array $expectedTokens): void { $lexer = new DocLexer(); diff --git a/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php b/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php index 1affd0e62..53241c59f 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php @@ -372,6 +372,9 @@ public function testAnnotationTarget(): void } } + /** + * @phpstan-return list + */ public function getAnnotationVarTypeProviderValid() { //({attribute name}, {attribute value}) @@ -417,7 +420,13 @@ public function getAnnotationVarTypeProviderValid() ['arrayOfIntegers', '{1,2,3,4}'], ['arrayOfAnnotations', '@AnnotationExtendsAnnotationTargetAll'], ['arrayOfAnnotations', '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll}'], - ['arrayOfAnnotations', '{@AnnotationExtendsAnnotationTargetAll, @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll}'], + [ + 'arrayOfAnnotations', + '{ + @AnnotationExtendsAnnotationTargetAll, + @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll + }', + ], // annotation instance ['annotation', '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll'], @@ -425,7 +434,10 @@ public function getAnnotationVarTypeProviderValid() ]; } - public function getAnnotationVarTypeProviderInvalid() + /** + * @phpstan-return list + */ + public function getAnnotationVarTypeProviderInvalid(): array { //({attribute name}, {type declared type}, {attribute value} , {given type or class}) return [ @@ -474,10 +486,18 @@ public function getAnnotationVarTypeProviderInvalid() ['annotation', AnnotationTargetAll::class, '1.2','double'], ['annotation', AnnotationTargetAll::class, '{"str"}','array'], ['annotation', AnnotationTargetAll::class, '{1,2,3,4}','array'], - ['annotation', AnnotationTargetAll::class, '@Name','an instance of Doctrine\Tests\Common\Annotations\Name'], + [ + 'annotation', + AnnotationTargetAll::class, + '@Name', + 'an instance of Doctrine\Tests\Common\Annotations\Name', + ], ]; } + /** + * @phpstan-return list + */ public function getAnnotationVarTypeArrayProviderInvalid() { //({attribute name}, {type declared type}, {attribute value} , {given type or class}) @@ -498,21 +518,49 @@ public function getAnnotationVarTypeArrayProviderInvalid() ['arrayOfAnnotations', AnnotationTargetAll::class, 'true', 'boolean'], ['arrayOfAnnotations', AnnotationTargetAll::class, 'false', 'boolean'], - ['arrayOfAnnotations', AnnotationTargetAll::class, '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,true}', 'boolean'], - ['arrayOfAnnotations', AnnotationTargetAll::class, '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,true}', 'boolean'], - ['arrayOfAnnotations', AnnotationTargetAll::class, '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,1.2}', 'double'], - ['arrayOfAnnotations', AnnotationTargetAll::class, '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,@AnnotationExtendsAnnotationTargetAll,"str"}', 'string'], + [ + 'arrayOfAnnotations', + AnnotationTargetAll::class, + '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,true}', + 'boolean', + ], + [ + 'arrayOfAnnotations', + AnnotationTargetAll::class, + '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,true}', + 'boolean', + ], + [ + 'arrayOfAnnotations', + AnnotationTargetAll::class, + '{@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll,1.2}', + 'double', + ], + [ + 'arrayOfAnnotations', + AnnotationTargetAll::class, + '{ + @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll, + @AnnotationExtendsAnnotationTargetAll, + "str" + }', + 'string', + ], ]; } /** * @dataProvider getAnnotationVarTypeProviderValid */ - public function testAnnotationWithVarType($attribute, $value): void + public function testAnnotationWithVarType(string $attribute, string $value): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::$invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); $result = $parser->parse($docblock, $context); @@ -525,11 +573,19 @@ public function testAnnotationWithVarType($attribute, $value): void /** * @dataProvider getAnnotationVarTypeProviderInvalid */ - public function testAnnotationWithVarTypeError($attribute, $type, $value, $given): void - { + public function testAnnotationWithVarTypeError( + string $attribute, + string $type, + string $value, + string $given + ): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); try { @@ -537,7 +593,10 @@ public function testAnnotationWithVarTypeError($attribute, $type, $value, $given $this->fail(); } catch (AnnotationException $exc) { self::assertStringMatchesFormat( - '[Type Error] Attribute "' . $attribute . '" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType declared on property SomeClassName::invalidProperty. expects a(n) %A' . $type . ', but got ' . $given . '.', + '[Type Error] Attribute "' . $attribute . + '" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType' . + ' declared on property SomeClassName::invalidProperty. expects a(n) %A' . + $type . ', but got ' . $given . '.', $exc->getMessage() ); } @@ -546,11 +605,19 @@ public function testAnnotationWithVarTypeError($attribute, $type, $value, $given /** * @dataProvider getAnnotationVarTypeArrayProviderInvalid */ - public function testAnnotationWithVarTypeArrayError($attribute, $type, $value, $given): void - { + public function testAnnotationWithVarTypeArrayError( + string $attribute, + string $type, + string $value, + string $given + ): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); try { @@ -558,7 +625,10 @@ public function testAnnotationWithVarTypeArrayError($attribute, $type, $value, $ $this->fail(); } catch (AnnotationException $exc) { self::assertStringMatchesFormat( - '[Type Error] Attribute "' . $attribute . '" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType declared on property SomeClassName::invalidProperty. expects either a(n) %A' . $type . ', or an array of %A' . $type . 's, but got ' . $given . '.', + '[Type Error] Attribute "' . $attribute . + '" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType' . + ' declared on property SomeClassName::invalidProperty. expects either a(n) %A' . + $type . ', or an array of %A' . $type . 's, but got ' . $given . '.', $exc->getMessage() ); } @@ -567,11 +637,15 @@ public function testAnnotationWithVarTypeArrayError($attribute, $type, $value, $ /** * @dataProvider getAnnotationVarTypeProviderValid */ - public function testAnnotationWithAttributes($attribute, $value): void + public function testAnnotationWithAttributes(string $attribute, string $value): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::$invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); $result = $parser->parse($docblock, $context); @@ -585,36 +659,66 @@ public function testAnnotationWithAttributes($attribute, $value): void /** * @dataProvider getAnnotationVarTypeProviderInvalid */ - public function testAnnotationWithAttributesError($attribute, $type, $value, $given): void - { + public function testAnnotationWithAttributesError( + string $attribute, + string $type, + string $value, + string $given + ): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); try { $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString("[Type Error] Attribute \"$attribute\" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes declared on property SomeClassName::invalidProperty. expects a(n) $type, but got $given.", $exc->getMessage()); + self::assertStringContainsString(sprintf( + '[Type Error] Attribute "%s" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes' . + ' declared on property SomeClassName::invalidProperty. expects a(n) %s, but got %s.', + $attribute, + $type, + $given + ), $exc->getMessage()); } } /** * @dataProvider getAnnotationVarTypeArrayProviderInvalid */ - public function testAnnotationWithAttributesWithVarTypeArrayError($attribute, $type, $value, $given): void - { + public function testAnnotationWithAttributesWithVarTypeArrayError( + string $attribute, + string $type, + string $value, + string $given + ): void { $parser = $this->createTestParser(); $context = 'property SomeClassName::invalidProperty.'; - $docblock = sprintf('@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', $attribute, $value); + $docblock = sprintf( + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes(%s = %s)', + $attribute, + $value + ); $parser->setTarget(Target::TARGET_PROPERTY); try { $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString("[Type Error] Attribute \"$attribute\" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes declared on property SomeClassName::invalidProperty. expects either a(n) $type, or an array of {$type}s, but got $given.", $exc->getMessage()); + self::assertStringContainsString(sprintf( + '[Type Error] Attribute "%s" of' . + ' @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithAttributes declared' . + ' on property SomeClassName::invalidProperty. expects either a(n) %s, or an array of %ss, but got %s.', + $attribute, + $type, + $type, + $given + ), $exc->getMessage()); } } @@ -624,7 +728,8 @@ public function testAnnotationWithRequiredAttributes(): void $context = 'property SomeClassName::invalidProperty.'; $parser->setTarget(Target::TARGET_PROPERTY); - $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes("Some Value", annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; + $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes' . + '("Some Value", annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; $result = $parser->parse($docblock); self::assertCount(1, $result); @@ -641,15 +746,27 @@ public function testAnnotationWithRequiredAttributes(): void $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString('Attribute "annot" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes declared on property SomeClassName::invalidProperty. expects a(n) Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation. This value should not be null.', $exc->getMessage()); + self::assertStringContainsString( + 'Attribute "annot" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes' . + ' declared on property SomeClassName::invalidProperty. expects a(n)' . + ' Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation.' . + ' This value should not be null.', + $exc->getMessage() + ); } - $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes(annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; + $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes' . + '(annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; try { $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString('Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes declared on property SomeClassName::invalidProperty. expects a(n) string. This value should not be null.', $exc->getMessage()); + self::assertStringContainsString( + 'Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributes' . + ' declared on property SomeClassName::invalidProperty. expects a(n) string.' . + ' This value should not be null.', + $exc->getMessage() + ); } } @@ -659,7 +776,8 @@ public function testAnnotationWithRequiredAttributesWithoutConstructor(): void $context = 'property SomeClassName::invalidProperty.'; $parser->setTarget(Target::TARGET_PROPERTY); - $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor("Some Value", annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; + $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor' . + '("Some Value", annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; $result = $parser->parse($docblock); self::assertCount(1, $result); @@ -667,20 +785,36 @@ public function testAnnotationWithRequiredAttributesWithoutConstructor(): void self::assertEquals('Some Value', $result[0]->value); self::assertInstanceOf(Fixtures\AnnotationTargetAnnotation::class, $result[0]->annot); - $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor("Some Value")'; + $docblock = <<<'ANNOTATION' +@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor("Some Value") +ANNOTATION; try { $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString('Attribute "annot" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor declared on property SomeClassName::invalidProperty. expects a(n) \Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation. This value should not be null.', $exc->getMessage()); + self::assertStringContainsString( + 'Attribute "annot" of' . + ' @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor' . + ' declared on property SomeClassName::invalidProperty. expects a(n)' . + ' \Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation.' . + ' This value should not be null.', + $exc->getMessage() + ); } - $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor(annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; + $docblock = '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor' . + '(annot = @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation)'; try { $parser->parse($docblock, $context); $this->fail(); } catch (AnnotationException $exc) { - self::assertStringContainsString('Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor declared on property SomeClassName::invalidProperty. expects a(n) string. This value should not be null.', $exc->getMessage()); + self::assertStringContainsString( + 'Attribute "value" of' . + ' @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithRequiredAttributesWithoutConstructor' . + ' declared on property SomeClassName::invalidProperty. expects a(n) string.' . + ' This value should not be null.', + $exc->getMessage() + ); } } @@ -693,7 +827,10 @@ public function testAnnotationEnumeratorException(): void $parser->setIgnoreNotImportedAnnotations(false); $parser->setTarget(Target::TARGET_PROPERTY); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum declared on property SomeClassName::invalidProperty. accept only [ONE, TWO, THREE], but got FOUR.'); + $this->expectExceptionMessage( + 'Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnum declared' . + ' on property SomeClassName::invalidProperty. accepts only [ONE, TWO, THREE], but got FOUR.' + ); $parser->parse($docblock, $context); } @@ -706,7 +843,11 @@ public function testAnnotationEnumeratorLiteralException(): void $parser->setIgnoreNotImportedAnnotations(false); $parser->setTarget(Target::TARGET_PROPERTY); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnumLiteral declared on property SomeClassName::invalidProperty. accept only [AnnotationEnumLiteral::ONE, AnnotationEnumLiteral::TWO, AnnotationEnumLiteral::THREE], but got 4.'); + $this->expectExceptionMessage( + 'Attribute "value" of @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationEnumLiteral declared' . + ' on property SomeClassName::invalidProperty. accepts only' . + ' [AnnotationEnumLiteral::ONE, AnnotationEnumLiteral::TWO, AnnotationEnumLiteral::THREE], but got 4.' + ); $parser->parse($docblock, $context); } @@ -732,8 +873,12 @@ public function testAnnotationEnumInvalidLiteralDeclarationException(): void $parser->parse($docblock); } - public function getConstantsProvider() + /** + * @phpstan-return array + */ + public function getConstantsProvider(): array { + $provider = []; $provider[] = [ '@AnnotationWithConstants(PHP_EOL)', PHP_EOL, @@ -774,8 +919,14 @@ public function getConstantsProvider() '@AnnotationWithConstants(\Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_VALUE)', InterfaceWithConstants::SOME_VALUE, ]; - $provider[] = [ - '@AnnotationWithConstants({AnnotationWithConstants::STRING, AnnotationWithConstants::INTEGER, AnnotationWithConstants::FLOAT})', + $provider[] = [<<<'ANNOTATION' +@AnnotationWithConstants({ + AnnotationWithConstants::STRING, + AnnotationWithConstants::INTEGER, + AnnotationWithConstants::FLOAT +}) +ANNOTATION +, [AnnotationWithConstants::STRING, AnnotationWithConstants::INTEGER, AnnotationWithConstants::FLOAT], ]; $provider[] = [ @@ -784,24 +935,30 @@ public function getConstantsProvider() })', [AnnotationWithConstants::STRING => AnnotationWithConstants::INTEGER], ]; - $provider[] = [ - '@AnnotationWithConstants({ - Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = AnnotationWithConstants::INTEGER - })', + $provider[] = [<<<'ANNOTATION' +@AnnotationWithConstants({ + Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = AnnotationWithConstants::INTEGER +}) +ANNOTATION +, [InterfaceWithConstants::SOME_KEY => AnnotationWithConstants::INTEGER], ]; - $provider[] = [ - '@AnnotationWithConstants({ - \Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = AnnotationWithConstants::INTEGER - })', + $provider[] = [<<<'ANNOTATION' +@AnnotationWithConstants({ + \Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = AnnotationWithConstants::INTEGER +}) +ANNOTATION +, [InterfaceWithConstants::SOME_KEY => AnnotationWithConstants::INTEGER], ]; - $provider[] = [ - '@AnnotationWithConstants({ - AnnotationWithConstants::STRING = AnnotationWithConstants::INTEGER, - ClassWithConstants::SOME_KEY = ClassWithConstants::SOME_VALUE, - Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = InterfaceWithConstants::SOME_VALUE - })', + $provider[] = [<<<'ANNOTATION' +@AnnotationWithConstants({ + AnnotationWithConstants::STRING = AnnotationWithConstants::INTEGER, + ClassWithConstants::SOME_KEY = ClassWithConstants::SOME_VALUE, + Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_KEY = InterfaceWithConstants::SOME_VALUE +}) +ANNOTATION +, [ AnnotationWithConstants::STRING => AnnotationWithConstants::INTEGER, ClassWithConstants::SOME_KEY => ClassWithConstants::SOME_VALUE, @@ -821,7 +978,8 @@ public function getConstantsProvider() AnnotationWithConstants::class, ]; $provider[] = [ - '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithConstants(Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithConstants::class)', + '@Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithConstants' . + '(Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithConstants::class)', AnnotationWithConstants::class, ]; @@ -829,9 +987,11 @@ public function getConstantsProvider() } /** + * @param mixed $expected + * * @dataProvider getConstantsProvider */ - public function testSupportClassConstants($docblock, $expected): void + public function testSupportClassConstants(string $docblock, $expected): void { $parser = $this->createTestParser(); $parser->setImports([ @@ -856,7 +1016,10 @@ public function testWithoutConstructorWhenIsNotDefaultValue(): void $parser->setTarget(Target::TARGET_CLASS); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('The annotation @SomeAnnotationClassNameWithoutConstructorAndProperties declared on does not accept any values, but got {"value":"Foo"}.'); + $this->expectExceptionMessage( + 'The annotation @SomeAnnotationClassNameWithoutConstructorAndProperties declared on ' . + ' does not accept any values, but got {"value":"Foo"}.' + ); $parser->parse($docblock); } @@ -871,14 +1034,17 @@ public function testWithoutConstructorWhenHasNoProperties(): void $parser->setTarget(Target::TARGET_CLASS); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('The annotation @SomeAnnotationClassNameWithoutConstructorAndProperties declared on does not accept any values, but got {"value":"Foo"}.'); + $this->expectExceptionMessage( + 'The annotation @SomeAnnotationClassNameWithoutConstructorAndProperties declared on ' . + ' does not accept any values, but got {"value":"Foo"}.' + ); $parser->parse($docblock); } public function testAnnotationTargetSyntaxError(): void { $parser = $this->createTestParser(); - $context = 'class ' . 'SomeClassName'; + $context = 'class SomeClassName'; $docblock = <<setTarget(Target::TARGET_CLASS); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError."); + $this->expectExceptionMessage( + "Expected namespace separator or identifier, got ')' at position 24" . + ' in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.' + ); $parser->parse($docblock, $context); } public function testAnnotationWithInvalidTargetDeclarationError(): void { $parser = $this->createTestParser(); - $context = 'class ' . 'SomeClassName'; + $context = 'class SomeClassName'; $docblock = <<setTarget(Target::TARGET_CLASS); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid Target "Foo". Available targets: [ALL, CLASS, METHOD, PROPERTY, ANNOTATION]'); + $this->expectExceptionMessage( + 'Invalid Target "Foo". Available targets: [ALL, CLASS, METHOD, PROPERTY, ANNOTATION]' + ); $parser->parse($docblock, $context); } public function testAnnotationWithTargetEmptyError(): void { $parser = $this->createTestParser(); - $context = 'class ' . 'SomeClassName'; + $context = 'class SomeClassName'; $docblock = << + */ + public function provideTestIgnoreWholeNamespaces(): array { return [ ['Namespace', '@Namespace'], @@ -1064,11 +1238,17 @@ public function testAnnotationThrowsExceptionWhenAtSignIsNotFollowedByIdentifier */ public function testAutoloadAnnotation(): void { - self::assertFalse(class_exists('Doctrine\Tests\Common\Annotations\Fixture\Annotation\Autoload', false), 'Pre-condition: Doctrine\Tests\Common\Annotations\Fixture\Annotation\Autoload not allowed to be loaded.'); + self::assertFalse( + class_exists('Doctrine\Tests\Common\Annotations\Fixture\Annotation\Autoload', false), + 'Pre-condition: Doctrine\Tests\Common\Annotations\Fixture\Annotation\Autoload not allowed to be loaded.' + ); $parser = new DocParser(); - AnnotationRegistry::registerAutoloadNamespace('Doctrine\Tests\Common\Annotations\Fixtures\Annotation', __DIR__ . '/../../../../'); + AnnotationRegistry::registerAutoloadNamespace( + 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation', + __DIR__ . '/../../../../' + ); $parser->setImports([ 'autoload' => Fixtures\Annotation\Autoload::class, @@ -1079,7 +1259,7 @@ public function testAutoloadAnnotation(): void self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotations[0]); } - public function createTestParser() + public function createTestParser(): DocParser { $parser = new DocParser(); $parser->setIgnoreNotImportedAnnotations(true); @@ -1098,7 +1278,9 @@ public function testSyntaxErrorWithContextDescription(): void { $parser = $this->createTestParser(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("Expected PlainValue, got ''' at position 10 in class \Doctrine\Tests\Common\Annotations\Name"); + $this->expectExceptionMessage( + "Expected PlainValue, got ''' at position 10 in class \Doctrine\Tests\Common\Annotations\Name" + ); $parser->parse("@Name(foo='bar')", 'class \Doctrine\Tests\Common\Annotations\Name'); } @@ -1200,7 +1382,7 @@ public function testCastNegativeFloat(): void self::assertIsFloat($annot->value); } - public function testSetValuesExeption(): void + public function testSetValuesException(): void { $docblock = <<expectException(AnnotationException::class); - $this->expectExceptionMessage('[Creation Error] The annotation @SomeAnnotationClassNameWithoutConstructor declared on some class does not have a property named "invalidaProperty". Available properties: data, name'); + $this->expectExceptionMessage( + '[Creation Error] The annotation @SomeAnnotationClassNameWithoutConstructor declared' . + ' on some class does not have a property named "invalidaProperty". +Available properties: data, name' + ); $this->createTestParser()->parse($docblock, 'some class'); } @@ -1217,7 +1403,10 @@ public function testInvalidIdentifierInAnnotation(): void { $parser = $this->createTestParser(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage("[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_IDENTIFIER or Doctrine\Common\Annotations\DocLexer::T_TRUE or Doctrine\Common\Annotations\DocLexer::T_FALSE or Doctrine\Common\Annotations\DocLexer::T_NULL, got '3.42' at position 5."); + $this->expectExceptionMessage('[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_IDENTIFIER' . + ' or Doctrine\Common\Annotations\DocLexer::T_TRUE' . + ' or Doctrine\Common\Annotations\DocLexer::T_FALSE' . + " or Doctrine\Common\Annotations\DocLexer::T_NULL, got '3.42' at position 5."); $parser->parse('@Foo\3.42'); } @@ -1353,8 +1542,12 @@ public function testWillParseAnnotationSucceededByANonImmediateDash(): void /** @Annotation */ class SettingsAnnotation { + /** @var mixed[] */ public $settings; + /** + * @param mixed[] $settings + */ public function __construct($settings) { $this->settings = $settings; @@ -1364,7 +1557,10 @@ public function __construct($settings) /** @Annotation */ class SomeAnnotationClassNameWithoutConstructor { + /** @var mixed */ public $data; + + /** @var mixed */ public $name; } @@ -1376,7 +1572,10 @@ public function __construct() $this->data = 'Some data'; } + /** @var mixed */ public $data; + + /** @var mixed */ public $name; } @@ -1409,12 +1608,14 @@ class AnnotationExtendsAnnotationTargetAll extends AnnotationTargetAll /** @Annotation */ class Name extends Annotation { + /** @var mixed */ public $foo; } /** @Annotation */ class Marker { + /** @var mixed */ public $value; } diff --git a/tests/Doctrine/Tests/Common/Annotations/DummyClass.php b/tests/Doctrine/Tests/Common/Annotations/DummyClass.php index f3e6a1ed0..303109bcd 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DummyClass.php +++ b/tests/Doctrine/Tests/Common/Annotations/DummyClass.php @@ -18,16 +18,17 @@ class DummyClass * @var mixed * @DummyAnnotation(dummyValue="fieldHello") */ - private $field1; + public $field1; /** + * @var mixed; * @DummyJoinTable(name="join_table", * joinColumns={@DummyJoinColumn(name="col1", referencedColumnName="col2")}, * inverseJoinColumns={ * @DummyJoinColumn(name="col3", referencedColumnName="col4") * }) */ - private $field2; + public $field2; /** * Gets the value of field1. diff --git a/tests/Doctrine/Tests/Common/Annotations/FileCacheReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/FileCacheReaderTest.php index eb99f766c..a92f245a0 100644 --- a/tests/Doctrine/Tests/Common/Annotations/FileCacheReaderTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/FileCacheReaderTest.php @@ -16,6 +16,7 @@ class FileCacheReaderTest extends AbstractReaderTest { + /** @var string */ private $cacheDir; protected function getReader(): Reader diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Route.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Route.php index b09c2994d..df0631f38 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Route.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Route.php @@ -7,5 +7,6 @@ class Route { /** @var string @Required */ public $pattern; + /** @var mixed */ public $name; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Secure.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Secure.php index 16a218201..5767e08c4 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Secure.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Secure.php @@ -7,8 +7,12 @@ /** @Annotation */ class Secure { - private $roles; + /** @var mixed */ + public $roles; + /** + * @param mixed[] $values + */ public function __construct(array $values) { if (is_string($values['value'])) { diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Template.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Template.php index 1c243f21f..b6bb93c71 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Template.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Annotation/Template.php @@ -5,8 +5,12 @@ /** @Annotation */ class Template { - private $name; + /** @var mixed */ + public $name; + /** + * @param mixed[] $values + */ public function __construct(array $values) { $this->name = $values['value'] ?? null; diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAll.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAll.php index 82a6d844f..7807c23cb 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAll.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAll.php @@ -8,7 +8,10 @@ */ class AnnotationTargetAll { + /** @var mixed */ public $data; + /** @var mixed */ public $name; + /** @var mixed */ public $target; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAnnotation.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAnnotation.php index 2865c9db0..eb5a7a6de 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAnnotation.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetAnnotation.php @@ -8,7 +8,10 @@ */ final class AnnotationTargetAnnotation { + /** @var mixed */ public $data; + /** @var mixed */ public $name; + /** @var mixed */ public $target; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetClass.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetClass.php index fa2b81d85..c06f62f57 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetClass.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetClass.php @@ -8,7 +8,10 @@ */ final class AnnotationTargetClass { + /** @var mixed */ public $data; + /** @var mixed */ public $name; + /** @var mixed */ public $target; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetMethod.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetMethod.php index b10ac69c0..3832f211a 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetMethod.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetMethod.php @@ -8,7 +8,10 @@ */ final class AnnotationTargetMethod { + /** @var mixed */ public $data; + /** @var mixed */ public $name; + /** @var mixed */ public $target; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetPropertyMethod.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetPropertyMethod.php index a043be280..981fa2e19 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetPropertyMethod.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationTargetPropertyMethod.php @@ -8,7 +8,10 @@ */ final class AnnotationTargetPropertyMethod { + /** @var mixed */ public $data; + /** @var mixed */ public $name; + /** @var mixed */ public $target; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithAttributes.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithAttributes.php index 940db7f67..f890b8002 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithAttributes.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithAttributes.php @@ -8,38 +8,52 @@ * @Annotation * @Target("ALL") * @Attributes({ - @Attribute("mixed", type = "mixed"), - @Attribute("boolean", type = "boolean"), - @Attribute("bool", type = "bool"), - @Attribute("float", type = "float"), - @Attribute("string", type = "string"), - @Attribute("integer", type = "integer"), - @Attribute("array", type = "array"), - @Attribute("arrayOfIntegers", type = "array"), - @Attribute("arrayOfStrings", type = "string[]"), - @Attribute("annotation", type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll"), - @Attribute("arrayOfAnnotations", type = "array"), + @Attribute("mixed", type = "mixed"), + @Attribute("boolean", type = "boolean"), + @Attribute("bool", type = "bool"), + @Attribute("float", type = "float"), + @Attribute("string", type = "string"), + @Attribute("integer", type = "integer"), + @Attribute("array", type = "array"), + @Attribute("arrayOfIntegers", type = "array"), + @Attribute("arrayOfStrings", type = "string[]"), + @Attribute("annotation", type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll"), + @Attribute("arrayOfAnnotations", type = "array"), }) */ final class AnnotationWithAttributes { - final public function __construct(array $data) + /** + * @param mixed[] $data + */ + public function __construct(array $data) { foreach ($data as $key => $value) { $this->$key = $value; } } + /** @var mixed */ private $mixed; + /** @var bool */ private $boolean; + /** @var bool */ private $bool; + /** @var float */ private $float; + /** @var string */ private $string; + /** @var integer */ private $integer; + /** @var mixed[] */ private $array; + /** @var object */ private $annotation; + /** @var int[] */ private $arrayOfIntegers; + /** @var string[] */ private $arrayOfStrings; + /** @var object[] */ private $arrayOfAnnotations; /** @@ -82,13 +96,13 @@ public function getString() return $this->string; } - public function getInteger() + public function getInteger(): int { return $this->integer; } /** - * @return array + * @return mixed[] */ public function getArray() { @@ -108,7 +122,7 @@ public function getAnnotation() */ public function getArrayOfStrings() { - return $this->arrayOfIntegers; + return $this->arrayOfStrings; } /** diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithRequiredAttributes.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithRequiredAttributes.php index 6599ce6b3..5a750ebfa 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithRequiredAttributes.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithRequiredAttributes.php @@ -9,12 +9,19 @@ * @Target("ALL") * @Attributes({ @Attribute("value", required = true , type = "string"), - @Attribute("annot", required = true , type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation"), + @Attribute( + "annot", + required = true , + type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation" + ), }) */ final class AnnotationWithRequiredAttributes { - final public function __construct(array $data) + /** + * @param mixed[] $data + */ + public function __construct(array $data) { foreach ($data as $key => $value) { $this->$key = $value; diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Api.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Api.php index 389c77f6f..97c03a03d 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Api.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Api.php @@ -1,5 +1,7 @@ * @extends ClassWithPHPStanExtendsAnnotationsGeneric */ -class ClassWithPHPStanGenericsAnnotations extends ClassWithPHPStanExtendsAnnotationsGeneric implements WithPHPStanExtendsAnnotationsInterface +class ClassWithPHPStanGenericsAnnotations extends ClassWithPHPStanExtendsAnnotationsGeneric implements + WithPHPStanExtendsAnnotations { /** * @use GenericPHPStanTrait diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithPhpCsSuppressAnnotation.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithPhpCsSuppressAnnotation.php index 3bfcfbbd6..61fa3b320 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithPhpCsSuppressAnnotation.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithPhpCsSuppressAnnotation.php @@ -5,7 +5,7 @@ class ClassWithPhpCsSuppressAnnotation { /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint */ public function foo($parameterWithoutTypehint): void { diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Controller.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Controller.php index a733957f0..0fe25cbda 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Controller.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Controller.php @@ -12,28 +12,34 @@ class Controller { /** + * @return mixed[] + * * @Route("/", name="_demo") * @Template() */ - public function indexAction() + public function indexAction(): array { return []; } /** + * @return mixed[] + * * @Route("/hello/{name}", name="_demo_hello") * @Template() */ - public function helloAction($name) + public function helloAction(string $name): array { return ['name' => $name]; } /** + * @return mixed[] + * * @Route("/contact", name="_demo_contact") * @Template() */ - public function contactAction() + public function contactAction(): array { $form = ContactForm::create($this->get('form.context'), 'contact'); @@ -70,7 +76,8 @@ private function createObjectIdentity(ObjectIdentityInterface $oid): void */ private function createOrRetrieveClassId($classType) { - if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) { + $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn(); + if ($id !== false) { return $id; } @@ -89,7 +96,8 @@ private function createOrRetrieveClassId($classType) */ private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid) { - if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) { + $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn(); + if ($id !== false) { return $id; } @@ -148,8 +156,8 @@ private function regenerateAncestorRelations(AclInterface $acl): void /** * This processes changes on an ACE related property (classFieldAces, or objectFieldAces). * - * @param string $name - * @param array $changes + * @param string $name + * @param mixed[] $changes */ private function updateFieldAceProperty($name, array $changes): void { @@ -176,8 +184,21 @@ private function updateFieldAceProperty($name, array $changes): void $objectIdentityId = $name === 'classFieldAces' ? null : $ace->getAcl()->getId(); - $this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure())); - $aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn(); + $this->connection->executeQuery($this->getInsertAccessControlEntrySql( + $classId, + $objectIdentityId, + $field, + $i, + $sid, + $ace->getStrategy(), + $ace->getMask(), + $ace->isGranting(), + $ace->isAuditSuccess(), + $ace->isAuditFailure() + )); + $aceId = $this->connection->executeQuery( + $this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i) + )->fetchColumn(); $this->loadedAces[$aceId] = $ace; $aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id'); @@ -206,8 +227,8 @@ private function updateFieldAceProperty($name, array $changes): void /** * This processes changes on an ACE related property (classAces, or objectAces). * - * @param string $name - * @param array $changes + * @param string $name + * @param mixed[] $changes */ private function updateAceProperty($name, array $changes): void { @@ -235,8 +256,21 @@ private function updateAceProperty($name, array $changes): void $objectIdentityId = $name === 'classAces' ? null : $ace->getAcl()->getId(); - $this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure())); - $aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn(); + $this->connection->executeQuery($this->getInsertAccessControlEntrySql( + $classId, + $objectIdentityId, + null, + $i, + $sid, + $ace->getStrategy(), + $ace->getMask(), + $ace->isGranting(), + $ace->isAuditSuccess(), + $ace->isAuditFailure() + )); + $aceId = $this->connection->executeQuery( + $this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i) + )->fetchColumn(); $this->loadedAces[$aceId] = $ace; $aceIdProperty = new \ReflectionProperty($ace, 'id'); @@ -281,11 +315,17 @@ private function updateAces(\SplObjectStorage $aces): void } if (isset($propertyChanges['auditSuccess'])) { - $sets[] = sprintf('audit_success = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditSuccess'][1])); + $sets[] = sprintf( + 'audit_success = %s', + $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditSuccess'][1]) + ); } if (isset($propertyChanges['auditFailure'])) { - $sets[] = sprintf('audit_failure = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1])); + $sets[] = sprintf( + 'audit_failure = %s', + $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1]) + ); } $this->connection->executeQuery($this->getUpdateAccessControlEntrySql($ace->getId(), $sets)); diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithParentClass.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithParentClass.php index 7bb3593a0..15c78ee36 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithParentClass.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithParentClass.php @@ -12,10 +12,12 @@ class ControllerWithParentClass extends AbstractController { /** + * @return mixed[] + * * @Route("/", name="_demo") * @Template() */ - public function indexAction() + public function indexAction(): array { return []; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithTrait.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithTrait.php index 61a558079..900009a3c 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithTrait.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/ControllerWithTrait.php @@ -15,10 +15,12 @@ class ControllerWithTrait use SecretRouteTrait; /** + * @return mixed[] + * * @Route("/", name="_demo") * @Template() */ - public function indexAction() + public function indexAction(): array { return []; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/TestInterface.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/HereForTesting.php similarity index 88% rename from tests/Doctrine/Tests/Common/Annotations/Fixtures/TestInterface.php rename to tests/Doctrine/Tests/Common/Annotations/Fixtures/HereForTesting.php index 82c272777..36d226d15 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/TestInterface.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/HereForTesting.php @@ -4,7 +4,7 @@ use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure; -interface TestInterface +interface HereForTesting { /** * @Secure diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedAtPropertyLevel.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedAtPropertyLevel.php index 559e825d1..57baae74c 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedAtPropertyLevel.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedAtPropertyLevel.php @@ -4,6 +4,9 @@ class AnnotatedAtPropertyLevel { - /** @SomePropertyAnnotationNamespace\Subnamespace\Name */ - private $property; + /** + * @var mixed + * @SomePropertyAnnotationNamespace\Subnamespace\Name + */ + public $property; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedWithAlias.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedWithAlias.php index 41edb6d4a..f1217ea58 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedWithAlias.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/IgnoredNamespaces/AnnotatedWithAlias.php @@ -6,6 +6,9 @@ class AnnotatedWithAlias { - /** @SomeAlias\Name */ - private $property; + /** + * @var mixed + * @SomeAlias\Name + */ + public $property; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php index 035640a76..eebc3d6b5 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/InterfaceThatExtendsAnInterface.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\Common\Annotations\Fixtures; use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route; +use Doctrine\Tests\Common\Annotations\Fixtures\EmptyInterface; /** * @Route("/someprefix") diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespacedSingleClassLOC1000.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespacedSingleClassLOC1000.php index 9bee839bb..93441da5f 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespacedSingleClassLOC1000.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/NamespacedSingleClassLOC1000.php @@ -14,17 +14,26 @@ class NamespacedSingleClassLOC1000 public const TEST8 = 1234567890; public const TEST9 = 1234567890; + /** @var null */ private $test1 = null; + /** @var null */ private $test2 = null; + /** @var null */ private $test3 = null; + /** @var null */ private $test4 = null; + /** @var null */ private $test5 = null; + /** @var null */ private $test6 = null; + /** @var null */ private $test7 = null; + /** @var null */ private $test8 = null; + /** @var null */ private $test9 = null; - public function test1() + public function test1(): string { echo $this->test1; echo $this->test2; @@ -49,7 +58,7 @@ public function test1() return $val; } - public function test2() + public function test2(): string { echo $this->test1; echo $this->test2; @@ -74,7 +83,7 @@ public function test2() return $val; } - public function test3() + public function test3(): string { echo $this->test1; echo $this->test2; @@ -99,7 +108,7 @@ public function test3() return $val; } - public function test4() + public function test4(): string { echo $this->test1; echo $this->test2; @@ -124,7 +133,7 @@ public function test4() return $val; } - public function test5() + public function test5(): string { echo $this->test1; echo $this->test2; @@ -149,7 +158,7 @@ public function test5() return $val; } - public function test6() + public function test6(): string { echo $this->test1; echo $this->test2; @@ -174,7 +183,7 @@ public function test6() return $val; } - public function test7() + public function test7(): string { echo $this->test1; echo $this->test2; @@ -199,7 +208,7 @@ public function test7() return $val; } - public function test8() + public function test8(): string { echo $this->test1; echo $this->test2; @@ -224,7 +233,7 @@ public function test8() return $val; } - public function test9() + public function test9(): string { echo $this->test1; echo $this->test2; @@ -249,7 +258,7 @@ public function test9() return $val; } - public function test10() + public function test10(): string { echo $this->test1; echo $this->test2; @@ -274,7 +283,7 @@ public function test10() return $val; } - public function test11() + public function test11(): string { echo $this->test1; echo $this->test2; @@ -299,7 +308,7 @@ public function test11() return $val; } - public function test12() + public function test12(): string { echo $this->test1; echo $this->test2; @@ -324,7 +333,7 @@ public function test12() return $val; } - public function test13() + public function test13(): string { echo $this->test1; echo $this->test2; @@ -349,7 +358,7 @@ public function test13() return $val; } - public function test14() + public function test14(): string { echo $this->test1; echo $this->test2; @@ -374,7 +383,7 @@ public function test14() return $val; } - public function test15() + public function test15(): string { echo $this->test1; echo $this->test2; @@ -399,7 +408,7 @@ public function test15() return $val; } - public function test16() + public function test16(): string { echo $this->test1; echo $this->test2; @@ -424,7 +433,7 @@ public function test16() return $val; } - public function test17() + public function test17(): string { echo $this->test1; echo $this->test2; @@ -449,7 +458,7 @@ public function test17() return $val; } - public function test18() + public function test18(): string { echo $this->test1; echo $this->test2; @@ -474,7 +483,7 @@ public function test18() return $val; } - public function test19() + public function test19(): string { echo $this->test1; echo $this->test2; @@ -499,7 +508,7 @@ public function test19() return $val; } - public function test20() + public function test20(): string { echo $this->test1; echo $this->test2; @@ -524,7 +533,7 @@ public function test20() return $val; } - public function test21() + public function test21(): string { echo $this->test1; echo $this->test2; @@ -549,7 +558,7 @@ public function test21() return $val; } - public function test22() + public function test22(): string { echo $this->test1; echo $this->test2; @@ -574,7 +583,7 @@ public function test22() return $val; } - public function test23() + public function test23(): string { echo $this->test1; echo $this->test2; @@ -599,7 +608,7 @@ public function test23() return $val; } - public function test24() + public function test24(): string { echo $this->test1; echo $this->test2; @@ -624,7 +633,7 @@ public function test24() return $val; } - public function test25() + public function test25(): string { echo $this->test1; echo $this->test2; @@ -649,7 +658,7 @@ public function test25() return $val; } - public function test26() + public function test26(): string { echo $this->test1; echo $this->test2; @@ -674,7 +683,7 @@ public function test26() return $val; } - public function test27() + public function test27(): string { echo $this->test1; echo $this->test2; @@ -699,7 +708,7 @@ public function test27() return $val; } - public function test28() + public function test28(): string { echo $this->test1; echo $this->test2; @@ -724,7 +733,7 @@ public function test28() return $val; } - public function test29() + public function test29(): string { echo $this->test1; echo $this->test2; @@ -749,7 +758,7 @@ public function test29() return $val; } - public function test30() + public function test30(): string { echo $this->test1; echo $this->test2; @@ -774,7 +783,7 @@ public function test30() return $val; } - public function test31() + public function test31(): string { echo $this->test1; echo $this->test2; @@ -799,7 +808,7 @@ public function test31() return $val; } - public function test32() + public function test32(): string { echo $this->test1; echo $this->test2; @@ -824,7 +833,7 @@ public function test32() return $val; } - public function test33() + public function test33(): string { echo $this->test1; echo $this->test2; @@ -849,7 +858,7 @@ public function test33() return $val; } - public function test34() + public function test34(): string { echo $this->test1; echo $this->test2; @@ -874,7 +883,7 @@ public function test34() return $val; } - public function test35() + public function test35(): string { echo $this->test1; echo $this->test2; @@ -899,7 +908,7 @@ public function test35() return $val; } - public function test36() + public function test36(): string { echo $this->test1; echo $this->test2; @@ -924,7 +933,7 @@ public function test36() return $val; } - public function test37() + public function test37(): string { echo $this->test1; echo $this->test2; @@ -949,7 +958,7 @@ public function test37() return $val; } - public function test38() + public function test38(): string { echo $this->test1; echo $this->test2; @@ -974,7 +983,7 @@ public function test38() return $val; } - public function test39() + public function test39(): string { echo $this->test1; echo $this->test2; diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php index ec0ba1beb..efb5b455b 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php @@ -12,17 +12,26 @@ class SingleClassLOC1000 public const TEST8 = 1234567890; public const TEST9 = 1234567890; + /** @var null */ private $test1 = null; + /** @var null */ private $test2 = null; + /** @var null */ private $test3 = null; + /** @var null */ private $test4 = null; + /** @var null */ private $test5 = null; + /** @var null */ private $test6 = null; + /** @var null */ private $test7 = null; + /** @var null */ private $test8 = null; + /** @var null */ private $test9 = null; - public function test1() + public function test1(): string { echo $this->test1; echo $this->test2; @@ -47,7 +56,7 @@ public function test1() return $val; } - public function test2() + public function test2(): string { echo $this->test1; echo $this->test2; @@ -72,7 +81,7 @@ public function test2() return $val; } - public function test3() + public function test3(): string { echo $this->test1; echo $this->test2; @@ -97,7 +106,7 @@ public function test3() return $val; } - public function test4() + public function test4(): string { echo $this->test1; echo $this->test2; @@ -122,7 +131,7 @@ public function test4() return $val; } - public function test5() + public function test5(): string { echo $this->test1; echo $this->test2; @@ -147,7 +156,7 @@ public function test5() return $val; } - public function test6() + public function test6(): string { echo $this->test1; echo $this->test2; @@ -172,7 +181,7 @@ public function test6() return $val; } - public function test7() + public function test7(): string { echo $this->test1; echo $this->test2; @@ -197,7 +206,7 @@ public function test7() return $val; } - public function test8() + public function test8(): string { echo $this->test1; echo $this->test2; @@ -222,7 +231,7 @@ public function test8() return $val; } - public function test9() + public function test9(): string { echo $this->test1; echo $this->test2; @@ -247,7 +256,7 @@ public function test9() return $val; } - public function test10() + public function test10(): string { echo $this->test1; echo $this->test2; @@ -272,7 +281,7 @@ public function test10() return $val; } - public function test11() + public function test11(): string { echo $this->test1; echo $this->test2; @@ -297,7 +306,7 @@ public function test11() return $val; } - public function test12() + public function test12(): string { echo $this->test1; echo $this->test2; @@ -322,7 +331,7 @@ public function test12() return $val; } - public function test13() + public function test13(): string { echo $this->test1; echo $this->test2; @@ -347,7 +356,7 @@ public function test13() return $val; } - public function test14() + public function test14(): string { echo $this->test1; echo $this->test2; @@ -372,7 +381,7 @@ public function test14() return $val; } - public function test15() + public function test15(): string { echo $this->test1; echo $this->test2; @@ -397,7 +406,7 @@ public function test15() return $val; } - public function test16() + public function test16(): string { echo $this->test1; echo $this->test2; @@ -422,7 +431,7 @@ public function test16() return $val; } - public function test17() + public function test17(): string { echo $this->test1; echo $this->test2; @@ -447,7 +456,7 @@ public function test17() return $val; } - public function test18() + public function test18(): string { echo $this->test1; echo $this->test2; @@ -472,7 +481,7 @@ public function test18() return $val; } - public function test19() + public function test19(): string { echo $this->test1; echo $this->test2; @@ -497,7 +506,7 @@ public function test19() return $val; } - public function test20() + public function test20(): string { echo $this->test1; echo $this->test2; @@ -522,7 +531,7 @@ public function test20() return $val; } - public function test21() + public function test21(): string { echo $this->test1; echo $this->test2; @@ -547,7 +556,7 @@ public function test21() return $val; } - public function test22() + public function test22(): string { echo $this->test1; echo $this->test2; @@ -572,7 +581,7 @@ public function test22() return $val; } - public function test23() + public function test23(): string { echo $this->test1; echo $this->test2; @@ -597,7 +606,7 @@ public function test23() return $val; } - public function test24() + public function test24(): string { echo $this->test1; echo $this->test2; @@ -622,7 +631,7 @@ public function test24() return $val; } - public function test25() + public function test25(): string { echo $this->test1; echo $this->test2; @@ -647,7 +656,7 @@ public function test25() return $val; } - public function test26() + public function test26(): string { echo $this->test1; echo $this->test2; @@ -672,7 +681,7 @@ public function test26() return $val; } - public function test27() + public function test27(): string { echo $this->test1; echo $this->test2; @@ -697,7 +706,7 @@ public function test27() return $val; } - public function test28() + public function test28(): string { echo $this->test1; echo $this->test2; @@ -722,7 +731,7 @@ public function test28() return $val; } - public function test29() + public function test29(): string { echo $this->test1; echo $this->test2; @@ -747,7 +756,7 @@ public function test29() return $val; } - public function test30() + public function test30(): string { echo $this->test1; echo $this->test2; @@ -772,7 +781,7 @@ public function test30() return $val; } - public function test31() + public function test31(): string { echo $this->test1; echo $this->test2; @@ -797,7 +806,7 @@ public function test31() return $val; } - public function test32() + public function test32(): string { echo $this->test1; echo $this->test2; @@ -822,7 +831,7 @@ public function test32() return $val; } - public function test33() + public function test33(): string { echo $this->test1; echo $this->test2; @@ -847,7 +856,7 @@ public function test33() return $val; } - public function test34() + public function test34(): string { echo $this->test1; echo $this->test2; @@ -872,7 +881,7 @@ public function test34() return $val; } - public function test35() + public function test35(): string { echo $this->test1; echo $this->test2; @@ -897,7 +906,7 @@ public function test35() return $val; } - public function test36() + public function test36(): string { echo $this->test1; echo $this->test2; @@ -922,7 +931,7 @@ public function test36() return $val; } - public function test37() + public function test37(): string { echo $this->test1; echo $this->test2; @@ -947,7 +956,7 @@ public function test37() return $val; } - public function test38() + public function test38(): string { echo $this->test1; echo $this->test2; @@ -972,7 +981,7 @@ public function test38() return $val; } - public function test39() + public function test39(): string { echo $this->test1; echo $this->test2; diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/TraitWithAnnotatedMethod.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/TraitWithAnnotatedMethod.php index ab1fcde46..aba7c562a 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/TraitWithAnnotatedMethod.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/TraitWithAnnotatedMethod.php @@ -6,7 +6,10 @@ trait TraitWithAnnotatedMethod { - /** @Autoload */ + /** + * @var mixed + * @Autoload + */ public $traitProperty; /** diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Traits/SecretRouteTrait.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Traits/SecretRouteTrait.php index 7c27ad018..81b4d7de2 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Fixtures/Traits/SecretRouteTrait.php +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/Traits/SecretRouteTrait.php @@ -8,10 +8,12 @@ trait SecretRouteTrait { /** + * @return mixed[] + * * @Route("/secret", name="_secret") * @Template() */ - public function secretAction() + public function secretAction(): array { return []; } diff --git a/tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php b/tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php index f10bf279a..d533bee4e 100644 --- a/tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php @@ -81,7 +81,7 @@ public function testParseClassWhenClassIsNotNamespaced(): void public function testParseClassWhenClassIsInterface(): void { $parser = new PhpParser(); - $class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\TestInterface'); + $class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\HereForTesting'); self::assertEquals([ 'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure', diff --git a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM141Test.php b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM141Test.php index 50ab4d556..875ebe99f 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM141Test.php +++ b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM141Test.php @@ -39,6 +39,7 @@ public function testAnnotationNotPrefixed(): void */ class DCOM141Annotation { + /** @var mixed */ public $classPath; } diff --git a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM55Test.php b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM55Test.php index 3ffc9f52e..46e921d88 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM55Test.php +++ b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM55Test.php @@ -18,7 +18,15 @@ public function testIssue(): void $class = new ReflectionClass(__NAMESPACE__ . '\\Dummy'); $reader = new AnnotationReader(); $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('[Semantical Error] The class "Doctrine\Tests\Common\Annotations\Fixtures\Controller" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Doctrine\Tests\Common\Annotations\Fixtures\Controller". If it is indeed no annotation, then you need to add @IgnoreAnnotation("Controller") to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Ticket\Dummy.'); + $this->expectExceptionMessage( + '[Semantical Error] The class "Doctrine\Tests\Common\Annotations\Fixtures\Controller"' . + ' is not annotated with @Annotation. +Are you sure this class can be used as annotation? +If so, then you need to add @Annotation to the _class_ doc comment of' . + ' "Doctrine\Tests\Common\Annotations\Fixtures\Controller". +If it is indeed no annotation, then you need to add @IgnoreAnnotation("Controller")' . + ' to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Ticket\Dummy.' + ); $reader->getClassAnnotations($class); }