diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 82280e1..a688b6a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,21 +1,35 @@ - - The coding standard for phpDocumentor. + + The coding standard for this library. src tests/unit - */tests/unit/Types/ContextFactoryTest.php + */tests/unit/Types/ContextFactoryTest\.php + + + + + - */src/*/Abstract*.php + */src/*/Abstract*\.php - */src/PseudoTypes/False_.php - */src/PseudoTypes/True_.php + */src/PseudoTypes/False_\.php + */src/PseudoTypes/True_\.php + + + + + */src/Types/ContextFactory\.php + + + */src/Types/ContextFactory\.php diff --git a/src/FqsenResolver.php b/src/FqsenResolver.php index 6447a01..068fa20 100644 --- a/src/FqsenResolver.php +++ b/src/FqsenResolver.php @@ -15,6 +15,7 @@ use InvalidArgumentException; use phpDocumentor\Reflection\Types\Context; + use function explode; use function implode; use function strpos; @@ -29,7 +30,7 @@ class FqsenResolver /** @var string Definition of the NAMESPACE operator in PHP */ private const OPERATOR_NAMESPACE = '\\'; - public function resolve(string $fqsen, ?Context $context = null) : Fqsen + public function resolve(string $fqsen, ?Context $context = null): Fqsen { if ($context === null) { $context = new Context(''); @@ -45,7 +46,7 @@ public function resolve(string $fqsen, ?Context $context = null) : Fqsen /** * Tests whether the given type is a Fully Qualified Structural Element Name. */ - private function isFqsen(string $type) : bool + private function isFqsen(string $type): bool { return strpos($type, self::OPERATOR_NAMESPACE) === 0; } @@ -56,7 +57,7 @@ private function isFqsen(string $type) : bool * * @throws InvalidArgumentException When type is not a valid FQSEN. */ - private function resolvePartialStructuralElementName(string $type, Context $context) : Fqsen + private function resolvePartialStructuralElementName(string $type, Context $context): Fqsen { $typeParts = explode(self::OPERATOR_NAMESPACE, $type, 2); diff --git a/src/PseudoType.php b/src/PseudoType.php index f94cff5..dd91ed7 100644 --- a/src/PseudoType.php +++ b/src/PseudoType.php @@ -15,5 +15,5 @@ interface PseudoType extends Type { - public function underlyingType() : Type; + public function underlyingType(): Type; } diff --git a/src/PseudoTypes/CallableString.php b/src/PseudoTypes/CallableString.php index e9c7c14..b693456 100644 --- a/src/PseudoTypes/CallableString.php +++ b/src/PseudoTypes/CallableString.php @@ -24,7 +24,7 @@ */ final class CallableString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'callable-string'; } diff --git a/src/PseudoTypes/False_.php b/src/PseudoTypes/False_.php index fea5baa..4ec6885 100644 --- a/src/PseudoTypes/False_.php +++ b/src/PseudoTypes/False_.php @@ -16,6 +16,7 @@ use phpDocumentor\Reflection\PseudoType; use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\Boolean; + use function class_alias; /** @@ -25,12 +26,12 @@ */ final class False_ extends Boolean implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new Boolean(); } - public function __toString() : string + public function __toString(): string { return 'false'; } diff --git a/src/PseudoTypes/HtmlEscapedString.php b/src/PseudoTypes/HtmlEscapedString.php index 7343517..aa4d8db 100644 --- a/src/PseudoTypes/HtmlEscapedString.php +++ b/src/PseudoTypes/HtmlEscapedString.php @@ -24,7 +24,7 @@ */ final class HtmlEscapedString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'html-escaped-string'; } diff --git a/src/PseudoTypes/LowercaseString.php b/src/PseudoTypes/LowercaseString.php index 8fddbaa..6325492 100644 --- a/src/PseudoTypes/LowercaseString.php +++ b/src/PseudoTypes/LowercaseString.php @@ -24,7 +24,7 @@ */ final class LowercaseString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'lowercase-string'; } diff --git a/src/PseudoTypes/NonEmptyLowercaseString.php b/src/PseudoTypes/NonEmptyLowercaseString.php index bf24aaa..8640016 100644 --- a/src/PseudoTypes/NonEmptyLowercaseString.php +++ b/src/PseudoTypes/NonEmptyLowercaseString.php @@ -24,7 +24,7 @@ */ final class NonEmptyLowercaseString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'non-empty-lowercase-string'; } diff --git a/src/PseudoTypes/NonEmptyString.php b/src/PseudoTypes/NonEmptyString.php index f67c239..d72d127 100644 --- a/src/PseudoTypes/NonEmptyString.php +++ b/src/PseudoTypes/NonEmptyString.php @@ -24,7 +24,7 @@ */ final class NonEmptyString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'non-empty-string'; } diff --git a/src/PseudoTypes/NumericString.php b/src/PseudoTypes/NumericString.php index 64300f6..b62aa45 100644 --- a/src/PseudoTypes/NumericString.php +++ b/src/PseudoTypes/NumericString.php @@ -24,7 +24,7 @@ */ final class NumericString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'numeric-string'; } diff --git a/src/PseudoTypes/PositiveInteger.php b/src/PseudoTypes/PositiveInteger.php index 88ac7ed..63b5094 100644 --- a/src/PseudoTypes/PositiveInteger.php +++ b/src/PseudoTypes/PositiveInteger.php @@ -24,7 +24,7 @@ */ final class PositiveInteger extends Integer implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new Integer(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'positive-int'; } diff --git a/src/PseudoTypes/TraitString.php b/src/PseudoTypes/TraitString.php index 4e2f5df..ac217c2 100644 --- a/src/PseudoTypes/TraitString.php +++ b/src/PseudoTypes/TraitString.php @@ -24,7 +24,7 @@ */ final class TraitString extends String_ implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new String_(); } @@ -32,7 +32,7 @@ public function underlyingType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'trait-string'; } diff --git a/src/PseudoTypes/True_.php b/src/PseudoTypes/True_.php index 766c26c..dc970b3 100644 --- a/src/PseudoTypes/True_.php +++ b/src/PseudoTypes/True_.php @@ -16,6 +16,7 @@ use phpDocumentor\Reflection\PseudoType; use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\Boolean; + use function class_alias; /** @@ -25,12 +26,12 @@ */ final class True_ extends Boolean implements PseudoType { - public function underlyingType() : Type + public function underlyingType(): Type { return new Boolean(); } - public function __toString() : string + public function __toString(): string { return 'true'; } diff --git a/src/Type.php b/src/Type.php index d2b86df..c71d8b0 100644 --- a/src/Type.php +++ b/src/Type.php @@ -21,5 +21,5 @@ interface Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string; + public function __toString(): string; } diff --git a/src/TypeResolver.php b/src/TypeResolver.php index 6b5327d..2aa31f8 100644 --- a/src/TypeResolver.php +++ b/src/TypeResolver.php @@ -29,6 +29,7 @@ use phpDocumentor\Reflection\Types\Object_; use phpDocumentor\Reflection\Types\String_; use RuntimeException; + use function array_key_exists; use function array_pop; use function array_values; @@ -42,6 +43,7 @@ use function strpos; use function strtolower; use function trim; + use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_NO_EMPTY; @@ -137,7 +139,7 @@ public function __construct(?FqsenResolver $fqsenResolver = null) * * @param string $type The relative or absolute type. */ - public function resolve(string $type, ?Context $context = null) : Type + public function resolve(string $type, ?Context $context = null): Type { $type = trim($type); if (!$type) { @@ -173,7 +175,7 @@ public function resolve(string $type, ?Context $context = null) : Type * @param int $parserContext on of self::PARSER_* constants, indicating * the context where we are in the parsing */ - private function parseTypes(ArrayIterator $tokens, Context $context, int $parserContext) : Type + private function parseTypes(ArrayIterator $tokens, Context $context, int $parserContext): Type { $types = []; $token = ''; @@ -193,11 +195,12 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser ); } - if (!in_array($parserContext, [ - self::PARSER_IN_COMPOUND, - self::PARSER_IN_ARRAY_EXPRESSION, - self::PARSER_IN_COLLECTION_EXPRESSION, - ], true) + if ( + !in_array($parserContext, [ + self::PARSER_IN_COMPOUND, + self::PARSER_IN_ARRAY_EXPRESSION, + self::PARSER_IN_COLLECTION_EXPRESSION, + ], true) ) { throw new RuntimeException( 'Unexpected type separator' @@ -207,11 +210,12 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser $compoundToken = $token; $tokens->next(); } elseif ($token === '?') { - if (!in_array($parserContext, [ - self::PARSER_IN_COMPOUND, - self::PARSER_IN_ARRAY_EXPRESSION, - self::PARSER_IN_COLLECTION_EXPRESSION, - ], true) + if ( + !in_array($parserContext, [ + self::PARSER_IN_COMPOUND, + self::PARSER_IN_ARRAY_EXPRESSION, + self::PARSER_IN_COLLECTION_EXPRESSION, + ], true) ) { throw new RuntimeException( 'Unexpected nullable character' @@ -256,7 +260,8 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser } $tokens->next(); - } elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION + } elseif ( + $parserContext === self::PARSER_IN_COLLECTION_EXPRESSION && ($token === '>' || trim($token) === ',') ) { break; @@ -326,13 +331,15 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser * * @psalm-mutation-free */ - private function resolveSingleType(string $type, Context $context) : object + private function resolveSingleType(string $type, Context $context): object { switch (true) { case $this->isKeyword($type): return $this->resolveKeyword($type); + case $this->isFqsen($type): return $this->resolveTypedObject($type); + case $this->isPartialStructuralElementName($type): return $this->resolveTypedObject($type, $context); @@ -352,7 +359,7 @@ private function resolveSingleType(string $type, Context $context) : object * * @psalm-param class-string $typeClassName */ - public function addKeyword(string $keyword, string $typeClassName) : void + public function addKeyword(string $keyword, string $typeClassName): void { if (!class_exists($typeClassName)) { throw new InvalidArgumentException( @@ -385,7 +392,7 @@ public function addKeyword(string $keyword, string $typeClassName) : void * * @psalm-mutation-free */ - private function isKeyword(string $type) : bool + private function isKeyword(string $type): bool { return array_key_exists(strtolower($type), $this->keywords); } @@ -397,7 +404,7 @@ private function isKeyword(string $type) : bool * * @psalm-mutation-free */ - private function isPartialStructuralElementName(string $type) : bool + private function isPartialStructuralElementName(string $type): bool { return ($type[0] !== self::OPERATOR_NAMESPACE) && !$this->isKeyword($type); } @@ -407,7 +414,7 @@ private function isPartialStructuralElementName(string $type) : bool * * @psalm-mutation-free */ - private function isFqsen(string $type) : bool + private function isFqsen(string $type): bool { return strpos($type, self::OPERATOR_NAMESPACE) === 0; } @@ -417,7 +424,7 @@ private function isFqsen(string $type) : bool * * @psalm-mutation-free */ - private function resolveKeyword(string $type) : Type + private function resolveKeyword(string $type): Type { $className = $this->keywords[strtolower($type)]; @@ -429,7 +436,7 @@ private function resolveKeyword(string $type) : Type * * @psalm-mutation-free */ - private function resolveTypedObject(string $type, ?Context $context = null) : Object_ + private function resolveTypedObject(string $type, ?Context $context = null): Object_ { return new Object_($this->fqsenResolver->resolve($type, $context)); } @@ -439,7 +446,7 @@ private function resolveTypedObject(string $type, ?Context $context = null) : Ob * * @param ArrayIterator $tokens */ - private function resolveClassString(ArrayIterator $tokens, Context $context) : Type + private function resolveClassString(ArrayIterator $tokens, Context $context): Type { $tokens->next(); @@ -472,7 +479,7 @@ private function resolveClassString(ArrayIterator $tokens, Context $context) : T * * @param ArrayIterator $tokens */ - private function resolveInterfaceString(ArrayIterator $tokens, Context $context) : Type + private function resolveInterfaceString(ArrayIterator $tokens, Context $context): Type { $tokens->next(); @@ -507,14 +514,16 @@ private function resolveInterfaceString(ArrayIterator $tokens, Context $context) * * @return Array_|Iterable_|Collection */ - private function resolveCollection(ArrayIterator $tokens, Type $classType, Context $context) : Type + private function resolveCollection(ArrayIterator $tokens, Type $classType, Context $context): Type { $isArray = ((string) $classType === 'array'); $isIterable = ((string) $classType === 'iterable'); // allow only "array", "iterable" or class name before "<" - if (!$isArray && !$isIterable - && (!$classType instanceof Object_ || $classType->getFqsen() === null)) { + if ( + !$isArray && !$isIterable + && (!$classType instanceof Object_ || $classType->getFqsen() === null) + ) { throw new RuntimeException( $classType . ' is not a collection' ); @@ -532,7 +541,8 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte if ($isArray) { // check the key type for an "array" collection. We allow only // strings or integers. - if (!$keyType instanceof String_ && + if ( + !$keyType instanceof String_ && !$keyType instanceof Integer && !$keyType instanceof Compound ) { @@ -543,7 +553,8 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte if ($keyType instanceof Compound) { foreach ($keyType->getIterator() as $item) { - if (!$item instanceof String_ && + if ( + !$item instanceof String_ && !$item instanceof Integer ) { throw new RuntimeException( @@ -590,7 +601,7 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte /** * @psalm-pure */ - private function makeCollectionFromObject(Object_ $object, Type $valueType, ?Type $keyType = null) : Collection + private function makeCollectionFromObject(Object_ $object, Type $valueType, ?Type $keyType = null): Collection { return new Collection($object->getFqsen(), $valueType, $keyType); } diff --git a/src/Types/AbstractList.php b/src/Types/AbstractList.php index bbea4f1..b674862 100644 --- a/src/Types/AbstractList.php +++ b/src/Types/AbstractList.php @@ -48,7 +48,7 @@ public function __construct(?Type $valueType = null, ?Type $keyType = null) /** * Returns the type for the keys of this array. */ - public function getKeyType() : Type + public function getKeyType(): Type { return $this->keyType ?? $this->defaultKeyType; } @@ -56,7 +56,7 @@ public function getKeyType() : Type /** * Returns the value for the keys of this array. */ - public function getValueType() : Type + public function getValueType(): Type { return $this->valueType; } @@ -64,7 +64,7 @@ public function getValueType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { if ($this->keyType) { return 'array<' . $this->keyType . ',' . $this->valueType . '>'; diff --git a/src/Types/AggregatedType.php b/src/Types/AggregatedType.php index 9522295..472a1cd 100644 --- a/src/Types/AggregatedType.php +++ b/src/Types/AggregatedType.php @@ -15,6 +15,7 @@ use ArrayIterator; use IteratorAggregate; use phpDocumentor\Reflection\Type; + use function array_key_exists; use function implode; @@ -53,7 +54,7 @@ public function __construct(array $types, string $token) /** * Returns the type at the given index. */ - public function get(int $index) : ?Type + public function get(int $index): ?Type { if (!$this->has($index)) { return null; @@ -65,7 +66,7 @@ public function get(int $index) : ?Type /** * Tests if this compound type has a type with the given index. */ - public function has(int $index) : bool + public function has(int $index): bool { return array_key_exists($index, $this->types); } @@ -73,7 +74,7 @@ public function has(int $index) : bool /** * Tests if this compound type contains the given type. */ - public function contains(Type $type) : bool + public function contains(Type $type): bool { foreach ($this->types as $typePart) { // if the type is duplicate; do not add it @@ -88,7 +89,7 @@ public function contains(Type $type) : bool /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return implode($this->token, $this->types); } @@ -96,7 +97,7 @@ public function __toString() : string /** * @return ArrayIterator */ - public function getIterator() : ArrayIterator + public function getIterator(): ArrayIterator { return new ArrayIterator($this->types); } @@ -104,7 +105,7 @@ public function getIterator() : ArrayIterator /** * @psalm-suppress ImpureMethodCall */ - private function add(Type $type) : void + private function add(Type $type): void { if ($type instanceof self) { foreach ($type->getIterator() as $subType) { diff --git a/src/Types/ArrayKey.php b/src/Types/ArrayKey.php index df21a45..60e0b48 100644 --- a/src/Types/ArrayKey.php +++ b/src/Types/ArrayKey.php @@ -27,7 +27,7 @@ public function __construct() parent::__construct([new String_(), new Integer()], '|'); } - public function __toString() : string + public function __toString(): string { return 'array-key'; } diff --git a/src/Types/Boolean.php b/src/Types/Boolean.php index 9163b51..8b1a3f3 100644 --- a/src/Types/Boolean.php +++ b/src/Types/Boolean.php @@ -25,7 +25,7 @@ class Boolean implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'bool'; } diff --git a/src/Types/Callable_.php b/src/Types/Callable_.php index 1522325..4e67aa4 100644 --- a/src/Types/Callable_.php +++ b/src/Types/Callable_.php @@ -25,7 +25,7 @@ final class Callable_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'callable'; } diff --git a/src/Types/ClassString.php b/src/Types/ClassString.php index f847f17..a0e5e95 100644 --- a/src/Types/ClassString.php +++ b/src/Types/ClassString.php @@ -37,7 +37,7 @@ public function __construct(?Fqsen $fqsen = null) /** * Returns the FQSEN associated with this object. */ - public function getFqsen() : ?Fqsen + public function getFqsen(): ?Fqsen { return $this->fqsen; } @@ -45,7 +45,7 @@ public function getFqsen() : ?Fqsen /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { if ($this->fqsen === null) { return 'class-string'; diff --git a/src/Types/Collection.php b/src/Types/Collection.php index 84b4463..943cc22 100644 --- a/src/Types/Collection.php +++ b/src/Types/Collection.php @@ -47,7 +47,7 @@ public function __construct(?Fqsen $fqsen, Type $valueType, ?Type $keyType = nul /** * Returns the FQSEN associated with this object. */ - public function getFqsen() : ?Fqsen + public function getFqsen(): ?Fqsen { return $this->fqsen; } @@ -55,7 +55,7 @@ public function getFqsen() : ?Fqsen /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { $objectType = (string) ($this->fqsen ?? 'object'); diff --git a/src/Types/Context.php b/src/Types/Context.php index c134d7c..79aadaf 100644 --- a/src/Types/Context.php +++ b/src/Types/Context.php @@ -50,7 +50,6 @@ final class Context * * @param string $namespace The namespace where this DocBlock resides in. * @param string[] $namespaceAliases List of namespace aliases => Fully Qualified Namespace. - * * @psalm-param array $namespaceAliases */ public function __construct(string $namespace, array $namespaceAliases = []) @@ -77,7 +76,7 @@ public function __construct(string $namespace, array $namespaceAliases = []) /** * Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in. */ - public function getNamespace() : string + public function getNamespace(): string { return $this->namespace; } @@ -87,10 +86,9 @@ public function getNamespace() : string * the alias for the imported Namespace. * * @return string[] - * * @psalm-return array */ - public function getNamespaceAliases() : array + public function getNamespaceAliases(): array { return $this->namespaceAliases; } diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 9430641..892ee0f 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -23,6 +23,7 @@ use Reflector; use RuntimeException; use UnexpectedValueException; + use function define; use function defined; use function file_exists; @@ -34,10 +35,13 @@ use function substr; use function token_get_all; use function trim; + use const T_AS; use const T_CLASS; use const T_CURLY_OPEN; use const T_DOLLAR_OPEN_CURLY_BRACES; +use const T_NAME_FULLY_QUALIFIED; +use const T_NAME_QUALIFIED; use const T_NAMESPACE; use const T_NS_SEPARATOR; use const T_STRING; @@ -73,7 +77,7 @@ final class ContextFactory * * @see Context for more information on Contexts. */ - public function createFromReflector(Reflector $reflector) : Context + public function createFromReflector(Reflector $reflector): Context { if ($reflector instanceof ReflectionClass) { //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable @@ -101,7 +105,7 @@ public function createFromReflector(Reflector $reflector) : Context throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector)); } - private function createFromReflectionParameter(ReflectionParameter $parameter) : Context + private function createFromReflectionParameter(ReflectionParameter $parameter): Context { $class = $parameter->getDeclaringClass(); if (!$class) { @@ -111,21 +115,21 @@ private function createFromReflectionParameter(ReflectionParameter $parameter) : return $this->createFromReflectionClass($class); } - private function createFromReflectionMethod(ReflectionMethod $method) : Context + private function createFromReflectionMethod(ReflectionMethod $method): Context { $class = $method->getDeclaringClass(); return $this->createFromReflectionClass($class); } - private function createFromReflectionProperty(ReflectionProperty $property) : Context + private function createFromReflectionProperty(ReflectionProperty $property): Context { $class = $property->getDeclaringClass(); return $this->createFromReflectionClass($class); } - private function createFromReflectionClassConstant(ReflectionClassConstant $constant) : Context + private function createFromReflectionClassConstant(ReflectionClassConstant $constant): Context { //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable /** @phpstan-var ReflectionClass $class */ @@ -137,7 +141,7 @@ private function createFromReflectionClassConstant(ReflectionClassConstant $cons /** * @phpstan-param ReflectionClass $class */ - private function createFromReflectionClass(ReflectionClass $class) : Context + private function createFromReflectionClass(ReflectionClass $class): Context { $fileName = $class->getFileName(); $namespace = $class->getNamespaceName(); @@ -163,7 +167,7 @@ private function createFromReflectionClass(ReflectionClass $class) : Context * this method first normalizes. * @param string $fileContents The file's contents to retrieve the aliases from with the given namespace. */ - public function createForNamespace(string $namespace, string $fileContents) : Context + public function createForNamespace(string $namespace, string $fileContents): Context { $namespace = trim($namespace, '\\'); $useStatements = []; @@ -184,8 +188,10 @@ public function createForNamespace(string $namespace, string $fileContents) : Co $firstBraceFound = false; while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) { $currentToken = $tokens->current(); - if ($currentToken === '{' - || in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)) { + if ( + $currentToken === '{' + || in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true) + ) { if (!$firstBraceFound) { $firstBraceFound = true; } @@ -220,7 +226,7 @@ public function createForNamespace(string $namespace, string $fileContents) : Co * * @param ArrayIterator $tokens */ - private function parseNamespace(ArrayIterator $tokens) : string + private function parseNamespace(ArrayIterator $tokens): string { // skip to the first string or namespace separator $this->skipToNextStringOrNamespaceSeparator($tokens); @@ -241,10 +247,9 @@ private function parseNamespace(ArrayIterator $tokens) : string * @param ArrayIterator $tokens * * @return string[] - * * @psalm-return array */ - private function parseUseStatement(ArrayIterator $tokens) : array + private function parseUseStatement(ArrayIterator $tokens): array { $uses = []; @@ -266,7 +271,7 @@ private function parseUseStatement(ArrayIterator $tokens) : array * * @param ArrayIterator $tokens */ - private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void + private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens): void { while ($tokens->valid()) { $currentToken = $tokens->current(); @@ -293,12 +298,11 @@ private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : v * @param ArrayIterator $tokens * * @return string[] + * @psalm-return array * * @psalm-suppress TypeDoesNotContainType - * - * @psalm-return array */ - private function extractUseStatements(ArrayIterator $tokens) : array + private function extractUseStatements(ArrayIterator $tokens): array { $extractedUseStatements = []; $groupedNs = ''; diff --git a/src/Types/Expression.php b/src/Types/Expression.php index 4a8ae1f..da5f65d 100644 --- a/src/Types/Expression.php +++ b/src/Types/Expression.php @@ -36,7 +36,7 @@ public function __construct(Type $valueType) /** * Returns the value for the keys of this array. */ - public function getValueType() : Type + public function getValueType(): Type { return $this->valueType; } @@ -44,7 +44,7 @@ public function getValueType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return '(' . $this->valueType . ')'; } diff --git a/src/Types/Float_.php b/src/Types/Float_.php index e70ce7d..86138c0 100644 --- a/src/Types/Float_.php +++ b/src/Types/Float_.php @@ -25,7 +25,7 @@ final class Float_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'float'; } diff --git a/src/Types/Integer.php b/src/Types/Integer.php index 858d4ab..10ce3c5 100644 --- a/src/Types/Integer.php +++ b/src/Types/Integer.php @@ -25,7 +25,7 @@ class Integer implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'int'; } diff --git a/src/Types/InterfaceString.php b/src/Types/InterfaceString.php index 8400bef..9836961 100644 --- a/src/Types/InterfaceString.php +++ b/src/Types/InterfaceString.php @@ -37,7 +37,7 @@ public function __construct(?Fqsen $fqsen = null) /** * Returns the FQSEN associated with this object. */ - public function getFqsen() : ?Fqsen + public function getFqsen(): ?Fqsen { return $this->fqsen; } @@ -45,7 +45,7 @@ public function getFqsen() : ?Fqsen /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { if ($this->fqsen === null) { return 'interface-string'; diff --git a/src/Types/Iterable_.php b/src/Types/Iterable_.php index a03a7cd..1ca069f 100644 --- a/src/Types/Iterable_.php +++ b/src/Types/Iterable_.php @@ -23,7 +23,7 @@ final class Iterable_ extends AbstractList /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { if ($this->keyType) { return 'iterable<' . $this->keyType . ',' . $this->valueType . '>'; diff --git a/src/Types/Mixed_.php b/src/Types/Mixed_.php index 2fedff4..56d1b6d 100644 --- a/src/Types/Mixed_.php +++ b/src/Types/Mixed_.php @@ -25,7 +25,7 @@ final class Mixed_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'mixed'; } diff --git a/src/Types/Null_.php b/src/Types/Null_.php index f5994d9..7ae802c 100644 --- a/src/Types/Null_.php +++ b/src/Types/Null_.php @@ -25,7 +25,7 @@ final class Null_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'null'; } diff --git a/src/Types/Nullable.php b/src/Types/Nullable.php index 80aaf4e..a946935 100644 --- a/src/Types/Nullable.php +++ b/src/Types/Nullable.php @@ -36,7 +36,7 @@ public function __construct(Type $realType) /** * Provide access to the actual type directly, if needed. */ - public function getActualType() : Type + public function getActualType(): Type { return $this->realType; } @@ -44,7 +44,7 @@ public function getActualType() : Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return '?' . $this->realType->__toString(); } diff --git a/src/Types/Object_.php b/src/Types/Object_.php index 4cfe2a0..90dee57 100644 --- a/src/Types/Object_.php +++ b/src/Types/Object_.php @@ -16,6 +16,7 @@ use InvalidArgumentException; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Type; + use function strpos; /** @@ -52,12 +53,12 @@ public function __construct(?Fqsen $fqsen = null) /** * Returns the FQSEN associated with this object. */ - public function getFqsen() : ?Fqsen + public function getFqsen(): ?Fqsen { return $this->fqsen; } - public function __toString() : string + public function __toString(): string { if ($this->fqsen) { return (string) $this->fqsen; diff --git a/src/Types/Parent_.php b/src/Types/Parent_.php index 08900ab..3483859 100644 --- a/src/Types/Parent_.php +++ b/src/Types/Parent_.php @@ -27,7 +27,7 @@ final class Parent_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'parent'; } diff --git a/src/Types/Resource_.php b/src/Types/Resource_.php index 2d4a794..1998ee0 100644 --- a/src/Types/Resource_.php +++ b/src/Types/Resource_.php @@ -25,7 +25,7 @@ final class Resource_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'resource'; } diff --git a/src/Types/Scalar.php b/src/Types/Scalar.php index 00ac369..80241c2 100644 --- a/src/Types/Scalar.php +++ b/src/Types/Scalar.php @@ -25,7 +25,7 @@ final class Scalar implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'scalar'; } diff --git a/src/Types/Self_.php b/src/Types/Self_.php index 7fa13fa..5096126 100644 --- a/src/Types/Self_.php +++ b/src/Types/Self_.php @@ -27,7 +27,7 @@ final class Self_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'self'; } diff --git a/src/Types/Static_.php b/src/Types/Static_.php index 568400c..6fe365f 100644 --- a/src/Types/Static_.php +++ b/src/Types/Static_.php @@ -32,7 +32,7 @@ final class Static_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'static'; } diff --git a/src/Types/String_.php b/src/Types/String_.php index 010682a..a4bb47f 100644 --- a/src/Types/String_.php +++ b/src/Types/String_.php @@ -25,7 +25,7 @@ class String_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'string'; } diff --git a/src/Types/This.php b/src/Types/This.php index 58cb3af..602fc69 100644 --- a/src/Types/This.php +++ b/src/Types/This.php @@ -28,7 +28,7 @@ final class This implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return '$this'; } diff --git a/src/Types/Void_.php b/src/Types/Void_.php index 5cabad5..3836bdc 100644 --- a/src/Types/Void_.php +++ b/src/Types/Void_.php @@ -28,7 +28,7 @@ final class Void_ implements Type /** * Returns a rendered output of the Type as it would be used in a DocBlock. */ - public function __toString() : string + public function __toString(): string { return 'void'; } diff --git a/tests/unit/CollectionResolverTest.php b/tests/unit/CollectionResolverTest.php index cc118a2..f86826e 100644 --- a/tests/unit/CollectionResolverTest.php +++ b/tests/unit/CollectionResolverTest.php @@ -33,7 +33,7 @@ class CollectionResolverTest extends TestCase * @covers ::resolve * @covers ::__construct */ - public function testResolvingCollection() : void + public function testResolvingCollection(): void { $fixture = new TypeResolver(); @@ -61,7 +61,7 @@ public function testResolvingCollection() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingCollectionWithKeyType() : void + public function testResolvingCollectionWithKeyType(): void { $fixture = new TypeResolver(); @@ -91,7 +91,7 @@ public function testResolvingCollectionWithKeyType() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingArrayCollection() : void + public function testResolvingArrayCollection(): void { $fixture = new TypeResolver(); @@ -117,7 +117,7 @@ public function testResolvingArrayCollection() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingArrayCollectionWithKey() : void + public function testResolvingArrayCollectionWithKey(): void { $fixture = new TypeResolver(); @@ -143,7 +143,7 @@ public function testResolvingArrayCollectionWithKey() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingArrayCollectionWithKeyAndWhitespace() : void + public function testResolvingArrayCollectionWithKeyAndWhitespace(): void { $fixture = new TypeResolver(); @@ -169,7 +169,7 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingArrayCollectionWithKeyAndTooManyWhitespace() : void + public function testResolvingArrayCollectionWithKeyAndTooManyWhitespace(): void { $this->expectException('InvalidArgumentException'); $fixture = new TypeResolver(); @@ -186,7 +186,7 @@ public function testResolvingArrayCollectionWithKeyAndTooManyWhitespace() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingCollectionOfCollection() : void + public function testResolvingCollectionOfCollection(): void { $fixture = new TypeResolver(); @@ -215,7 +215,7 @@ public function testResolvingCollectionOfCollection() : void * @covers ::__construct * @covers ::resolve */ - public function testBadArrayCollectionKey() : void + public function testBadArrayCollectionKey(): void { $this->expectException('RuntimeException'); $this->expectExceptionMessage('An array can have only integers or strings as keys'); @@ -227,7 +227,7 @@ public function testBadArrayCollectionKey() : void * @covers ::__construct * @covers ::resolve */ - public function testMissingStartCollection() : void + public function testMissingStartCollection(): void { $this->expectException('RuntimeException'); $this->expectExceptionMessage('Unexpected collection operator "<", class name is missing'); @@ -239,7 +239,7 @@ public function testMissingStartCollection() : void * @covers ::__construct * @covers ::resolve */ - public function testMissingEndCollection() : void + public function testMissingEndCollection(): void { $this->expectException('RuntimeException'); $this->expectExceptionMessage('Collection: ">" is missing'); @@ -251,7 +251,7 @@ public function testMissingEndCollection() : void * @covers ::__construct * @covers ::resolve */ - public function testBadCollectionClass() : void + public function testBadCollectionClass(): void { $this->expectException('RuntimeException'); $this->expectExceptionMessage('string is not a collection'); @@ -268,7 +268,7 @@ public function testBadCollectionClass() : void * @covers ::__construct * @covers ::resolve */ - public function testResolvingCollectionAsArray() : void + public function testResolvingCollectionAsArray(): void { $fixture = new TypeResolver(); diff --git a/tests/unit/FqsenResolverTest.php b/tests/unit/FqsenResolverTest.php index 4e56aac..2cecc5f 100644 --- a/tests/unit/FqsenResolverTest.php +++ b/tests/unit/FqsenResolverTest.php @@ -25,7 +25,7 @@ final class FqsenResolverTest extends TestCase /** * @covers ::resolve */ - public function testResolveFqsen() : void + public function testResolveFqsen(): void { $fqsenResolver = new FqsenResolver(); @@ -38,7 +38,7 @@ public function testResolveFqsen() : void /** * @covers ::resolve */ - public function testResolveFqsenWithEmoji() : void + public function testResolveFqsenWithEmoji(): void { $fqsenResolver = new FqsenResolver(); @@ -51,7 +51,7 @@ public function testResolveFqsenWithEmoji() : void /** * @covers ::resolve */ - public function testResolveWithoutContext() : void + public function testResolveWithoutContext(): void { $fqsenResolver = new FqsenResolver(); @@ -62,7 +62,7 @@ public function testResolveWithoutContext() : void /** * @covers ::resolve */ - public function testResolveFromAlias() : void + public function testResolveFromAlias(): void { $fqsenResolver = new FqsenResolver(); @@ -75,7 +75,7 @@ public function testResolveFromAlias() : void /** * @covers ::resolve */ - public function testResolveFromPartialAlias() : void + public function testResolveFromPartialAlias(): void { $fqsenResolver = new FqsenResolver(); @@ -85,7 +85,7 @@ public function testResolveFromPartialAlias() : void static::assertSame('\some\other\ns', (string) $result); } - public function testResolveThrowsExceptionWhenGarbageInputIsPassed() : void + public function testResolveThrowsExceptionWhenGarbageInputIsPassed(): void { $this->expectException('InvalidArgumentException'); $fqsenResolver = new FqsenResolver(); diff --git a/tests/unit/PseudoTypes/FalseTest.php b/tests/unit/PseudoTypes/FalseTest.php index 5367e24..e97c6f7 100644 --- a/tests/unit/PseudoTypes/FalseTest.php +++ b/tests/unit/PseudoTypes/FalseTest.php @@ -24,7 +24,7 @@ final class FalseTest extends TestCase /** * @covers ::underlyingType */ - public function testExposesUnderlyingType() : void + public function testExposesUnderlyingType(): void { $false = new False_(); @@ -34,7 +34,7 @@ public function testExposesUnderlyingType() : void /** * @covers ::__toString */ - public function testFalseStringifyCorrectly() : void + public function testFalseStringifyCorrectly(): void { $false = new False_(); @@ -44,7 +44,7 @@ public function testFalseStringifyCorrectly() : void /** * @covers \phpDocumentor\Reflection\PseudoTypes\False_ */ - public function testCanBeInstantiatedUsingDeprecatedFqsen() : void + public function testCanBeInstantiatedUsingDeprecatedFqsen(): void { $false = new \phpDocumentor\Reflection\Types\False_(); diff --git a/tests/unit/PseudoTypes/TrueTest.php b/tests/unit/PseudoTypes/TrueTest.php index d1d5b16..ec610b2 100644 --- a/tests/unit/PseudoTypes/TrueTest.php +++ b/tests/unit/PseudoTypes/TrueTest.php @@ -24,7 +24,7 @@ class TrueTest extends TestCase /** * @covers ::underlyingType */ - public function testExposesUnderlyingType() : void + public function testExposesUnderlyingType(): void { $true = new True_(); @@ -34,7 +34,7 @@ public function testExposesUnderlyingType() : void /** * @covers ::__toString */ - public function testTrueStringifyCorrectly() : void + public function testTrueStringifyCorrectly(): void { $true = new True_(); @@ -44,7 +44,7 @@ public function testTrueStringifyCorrectly() : void /** * @covers \phpDocumentor\Reflection\PseudoTypes\True_ */ - public function testCanBeInstantiatedUsingDeprecatedFqsen() : void + public function testCanBeInstantiatedUsingDeprecatedFqsen(): void { $true = new \phpDocumentor\Reflection\Types\True_(); diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index aa191b7..2b16e93 100644 --- a/tests/unit/TypeResolverTest.php +++ b/tests/unit/TypeResolverTest.php @@ -29,6 +29,7 @@ use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; use stdClass; + use function get_class; /** @@ -47,7 +48,7 @@ class TypeResolverTest extends TestCase * * @dataProvider provideKeywords */ - public function testResolvingKeywords(string $keyword, string $expectedClass) : void + public function testResolvingKeywords(string $keyword, string $expectedClass): void { $fixture = new TypeResolver(); @@ -67,7 +68,7 @@ public function testResolvingKeywords(string $keyword, string $expectedClass) : * * @dataProvider provideClassStrings */ - public function testResolvingClassStrings(string $classString, bool $throwsException) : void + public function testResolvingClassStrings(string $classString, bool $throwsException): void { $fixture = new TypeResolver(); @@ -91,7 +92,7 @@ public function testResolvingClassStrings(string $classString, bool $throwsExcep * * @dataProvider provideInterfaceStrings */ - public function testResolvingInterfaceStrings(string $interfaceString, bool $throwsException) : void + public function testResolvingInterfaceStrings(string $interfaceString, bool $throwsException): void { $fixture = new TypeResolver(); @@ -116,7 +117,7 @@ public function testResolvingInterfaceStrings(string $interfaceString, bool $thr * * @dataProvider provideFqcn */ - public function testResolvingFQSENs(string $fqsen) : void + public function testResolvingFQSENs(string $fqsen): void { $fixture = new TypeResolver(); @@ -137,7 +138,7 @@ public function testResolvingFQSENs(string $fqsen) : void * @covers ::resolve * @covers :: */ - public function testResolvingRelativeQSENsBasedOnNamespace() : void + public function testResolvingRelativeQSENsBasedOnNamespace(): void { $fixture = new TypeResolver(); @@ -158,7 +159,7 @@ public function testResolvingRelativeQSENsBasedOnNamespace() : void * @covers ::resolve * @covers :: */ - public function testResolvingRelativeQSENsBasedOnNamespaceAlias() : void + public function testResolvingRelativeQSENsBasedOnNamespaceAlias(): void { $fixture = new TypeResolver(); @@ -181,7 +182,7 @@ public function testResolvingRelativeQSENsBasedOnNamespaceAlias() : void * @covers ::resolve * @covers :: */ - public function testResolvingTypedArrays() : void + public function testResolvingTypedArrays(): void { $fixture = new TypeResolver(); @@ -202,7 +203,7 @@ public function testResolvingTypedArrays() : void * @covers ::resolve * @covers :: */ - public function testResolvingNullableTypes() : void + public function testResolvingNullableTypes(): void { $fixture = new TypeResolver(); @@ -222,7 +223,7 @@ public function testResolvingNullableTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingNestedTypedArrays() : void + public function testResolvingNestedTypedArrays(): void { $fixture = new TypeResolver(); @@ -253,7 +254,7 @@ public function testResolvingNestedTypedArrays() : void * @covers ::resolve * @covers :: */ - public function testResolvingCompoundTypes() : void + public function testResolvingCompoundTypes(): void { $fixture = new TypeResolver(); @@ -283,7 +284,7 @@ public function testResolvingCompoundTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingAmpersandCompoundTypes() : void + public function testResolvingAmpersandCompoundTypes(): void { $fixture = new TypeResolver(); @@ -320,7 +321,7 @@ public function testResolvingAmpersandCompoundTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingMixedCompoundTypes() : void + public function testResolvingMixedCompoundTypes(): void { $fixture = new TypeResolver(); @@ -369,7 +370,7 @@ public function testResolvingMixedCompoundTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingCompoundTypedArrayTypes() : void + public function testResolvingCompoundTypedArrayTypes(): void { $fixture = new TypeResolver(); @@ -402,7 +403,7 @@ public function testResolvingCompoundTypedArrayTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingNullableCompoundTypes() : void + public function testResolvingNullableCompoundTypes(): void { $fixture = new TypeResolver(); @@ -423,7 +424,7 @@ public function testResolvingNullableCompoundTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingArrayExpressionObjectsTypes() : void + public function testResolvingArrayExpressionObjectsTypes(): void { $fixture = new TypeResolver(); @@ -456,7 +457,7 @@ public function testResolvingArrayExpressionObjectsTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingArrayExpressionSimpleTypes() : void + public function testResolvingArrayExpressionSimpleTypes(): void { $fixture = new TypeResolver(); @@ -492,7 +493,7 @@ public function testResolvingArrayExpressionSimpleTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingArrayOfArrayExpressionTypes() : void + public function testResolvingArrayOfArrayExpressionTypes(): void { $fixture = new TypeResolver(); @@ -527,7 +528,7 @@ public function testResolvingArrayOfArrayExpressionTypes() : void * @covers ::resolve * @covers :: */ - public function testReturnEmptyCompoundOnAnUnclosedArrayExpressionType() : void + public function testReturnEmptyCompoundOnAnUnclosedArrayExpressionType(): void { $fixture = new TypeResolver(); @@ -549,7 +550,7 @@ public function testReturnEmptyCompoundOnAnUnclosedArrayExpressionType() : void * @covers ::resolve * @covers :: */ - public function testResolvingArrayExpressionOrCompoundTypes() : void + public function testResolvingArrayExpressionOrCompoundTypes(): void { $fixture = new TypeResolver(); @@ -590,7 +591,7 @@ public function testResolvingArrayExpressionOrCompoundTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingIterableExpressionSimpleTypes() : void + public function testResolvingIterableExpressionSimpleTypes(): void { $fixture = new TypeResolver(); @@ -632,7 +633,7 @@ public function testResolvingIterableExpressionSimpleTypes() : void * @covers ::resolve * @covers :: */ - public function testResolvingCompoundTypesWithTwoArrays() : void + public function testResolvingCompoundTypesWithTwoArrays(): void { $fixture = new TypeResolver(); @@ -659,7 +660,7 @@ public function testResolvingCompoundTypesWithTwoArrays() : void * @covers ::__construct * @covers ::addKeyword */ - public function testAddingAKeyword() : void + public function testAddingAKeyword(): void { // Assign $typeMock = self::createStub(Type::class); @@ -680,7 +681,7 @@ public function testAddingAKeyword() : void * @covers ::__construct * @covers ::addKeyword */ - public function testAddingAKeywordFailsIfTypeClassDoesNotExist() : void + public function testAddingAKeywordFailsIfTypeClassDoesNotExist(): void { $this->expectException('InvalidArgumentException'); $fixture = new TypeResolver(); @@ -693,7 +694,7 @@ public function testAddingAKeywordFailsIfTypeClassDoesNotExist() : void * @covers ::__construct * @covers ::addKeyword */ - public function testAddingAKeywordFailsIfTypeClassDoesNotImplementTypeInterface() : void + public function testAddingAKeywordFailsIfTypeClassDoesNotImplementTypeInterface(): void { $this->expectException('InvalidArgumentException'); $fixture = new TypeResolver(); @@ -706,7 +707,7 @@ public function testAddingAKeywordFailsIfTypeClassDoesNotImplementTypeInterface( * @covers ::__construct * @covers ::resolve */ - public function testExceptionIsThrownIfTypeIsEmpty() : void + public function testExceptionIsThrownIfTypeIsEmpty(): void { $this->expectException('InvalidArgumentException'); $fixture = new TypeResolver(); @@ -718,7 +719,7 @@ public function testExceptionIsThrownIfTypeIsEmpty() : void * * @return string[][] */ - public function provideKeywords() : array + public function provideKeywords(): array { return [ ['string', Types\String_::class], @@ -764,7 +765,7 @@ public function provideKeywords() : array * * @return (string|bool)[][] */ - public function provideClassStrings() : array + public function provideClassStrings(): array { return [ ['class-string<\phpDocumentor\Reflection>', false], @@ -778,7 +779,7 @@ public function provideClassStrings() : array * * @return (string|bool)[][] */ - public function provideInterfaceStrings() : array + public function provideInterfaceStrings(): array { return [ ['interface-string<\phpDocumentor\Reflection>', false], @@ -792,7 +793,7 @@ public function provideInterfaceStrings() : array * * @return string[][] */ - public function provideFqcn() : array + public function provideFqcn(): array { return [ 'namespace' => ['\phpDocumentor\Reflection'], @@ -807,7 +808,7 @@ public function provideFqcn() : array * @covers ::__construct * @covers ::resolve */ - public function testArrayKeyValueSpecification() : void + public function testArrayKeyValueSpecification(): void { $fixture = new TypeResolver(); $type = $fixture->resolve('array>', new Context('')); diff --git a/tests/unit/Types/ArrayKeyTest.php b/tests/unit/Types/ArrayKeyTest.php index 5ee5a67..88d511c 100644 --- a/tests/unit/Types/ArrayKeyTest.php +++ b/tests/unit/Types/ArrayKeyTest.php @@ -24,7 +24,7 @@ final class ArrayKeyTest extends TestCase * @covers ::__construct * @covers ::__toString */ - public function testArrayKeyCanBeConstructedAndStringifiedCorrectly() : void + public function testArrayKeyCanBeConstructedAndStringifiedCorrectly(): void { $this->assertSame('array-key', (string) (new ArrayKey())); } @@ -34,7 +34,7 @@ public function testArrayKeyCanBeConstructedAndStringifiedCorrectly() : void * * @covers ::getIterator */ - public function testArrayKeyCanBeIterated() : void + public function testArrayKeyCanBeIterated(): void { $types = [String_::class, Integer::class]; diff --git a/tests/unit/Types/ArrayTest.php b/tests/unit/Types/ArrayTest.php index 3ae55a4..88117c1 100644 --- a/tests/unit/Types/ArrayTest.php +++ b/tests/unit/Types/ArrayTest.php @@ -24,7 +24,7 @@ class ArrayTest extends TestCase * @dataProvider provideArrays * @covers ::__toString */ - public function testArrayStringifyCorrectly(Array_ $array, string $expectedString) : void + public function testArrayStringifyCorrectly(Array_ $array, string $expectedString): void { $this->assertSame($expectedString, (string) $array); } @@ -32,7 +32,7 @@ public function testArrayStringifyCorrectly(Array_ $array, string $expectedStrin /** * @return mixed[] */ - public function provideArrays() : array + public function provideArrays(): array { return [ 'simple array' => [new Array_(), 'array'], diff --git a/tests/unit/Types/BooleanTest.php b/tests/unit/Types/BooleanTest.php index 9e2b0e2..9bbf93c 100644 --- a/tests/unit/Types/BooleanTest.php +++ b/tests/unit/Types/BooleanTest.php @@ -23,7 +23,7 @@ final class BooleanTest extends TestCase /** * @covers ::__toString */ - public function testBooleanStringifyCorrectly() : void + public function testBooleanStringifyCorrectly(): void { $type = new Boolean(); diff --git a/tests/unit/Types/ClassStringTest.php b/tests/unit/Types/ClassStringTest.php index 37c9173..8f77e76 100644 --- a/tests/unit/Types/ClassStringTest.php +++ b/tests/unit/Types/ClassStringTest.php @@ -25,7 +25,7 @@ class ClassStringTest extends TestCase * @dataProvider provideClassStrings * @covers ::__toString */ - public function testClassStringStringifyCorrectly(ClassString $array, string $expectedString) : void + public function testClassStringStringifyCorrectly(ClassString $array, string $expectedString): void { $this->assertSame($expectedString, (string) $array); } @@ -33,7 +33,7 @@ public function testClassStringStringifyCorrectly(ClassString $array, string $ex /** * @return mixed[] */ - public function provideClassStrings() : array + public function provideClassStrings(): array { return [ 'generic class string' => [new ClassString(), 'class-string'], diff --git a/tests/unit/Types/CollectionTest.php b/tests/unit/Types/CollectionTest.php index 2793ba4..c48f3f2 100644 --- a/tests/unit/Types/CollectionTest.php +++ b/tests/unit/Types/CollectionTest.php @@ -25,7 +25,7 @@ class CollectionTest extends TestCase * @dataProvider provideCollections * @covers ::__toString */ - public function testCollectionStringifyCorrectly(Collection $collection, string $expectedString) : void + public function testCollectionStringifyCorrectly(Collection $collection, string $expectedString): void { $this->assertSame($expectedString, (string) $collection); } @@ -33,7 +33,7 @@ public function testCollectionStringifyCorrectly(Collection $collection, string /** * @return mixed[] */ - public function provideCollections() : array + public function provideCollections(): array { return [ 'simple collection' => [ diff --git a/tests/unit/Types/CompoundTest.php b/tests/unit/Types/CompoundTest.php index 05fdb24..d5e08af 100644 --- a/tests/unit/Types/CompoundTest.php +++ b/tests/unit/Types/CompoundTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use TypeError; + use function iterator_to_array; /** @@ -25,7 +26,7 @@ final class CompoundTest extends TestCase /** * @covers ::__construct */ - public function testCompoundCannotBeConstructedFromType() : void + public function testCompoundCannotBeConstructedFromType(): void { $this->expectException(TypeError::class); new Compound(['foo']); @@ -38,7 +39,7 @@ public function testCompoundCannotBeConstructedFromType() : void * * @covers ::get */ - public function testCompoundGetType() : void + public function testCompoundGetType(): void { $integer = new Integer(); @@ -51,7 +52,7 @@ public function testCompoundGetType() : void * * @covers ::get */ - public function testCompoundGetNotExistingType() : void + public function testCompoundGetNotExistingType(): void { $this->assertNull((new Compound([]))->get(0)); } @@ -62,7 +63,7 @@ public function testCompoundGetNotExistingType() : void * * @covers ::has */ - public function testCompoundHasIndex() : void + public function testCompoundHasIndex(): void { $this->assertTrue((new Compound([new Integer()]))->has(0)); } @@ -72,7 +73,7 @@ public function testCompoundHasIndex() : void * * @covers ::has */ - public function testCompoundDoesNotHasIndex() : void + public function testCompoundDoesNotHasIndex(): void { $this->assertFalse((new Compound([]))->has(0)); } @@ -83,7 +84,7 @@ public function testCompoundDoesNotHasIndex() : void * * @covers ::contains */ - public function testCompoundContainsType() : void + public function testCompoundContainsType(): void { $this->assertTrue((new Compound([new Integer()]))->contains(new Integer())); } @@ -95,7 +96,7 @@ public function testCompoundContainsType() : void * * @covers ::contains */ - public function testCompoundDoesNotContainType() : void + public function testCompoundDoesNotContainType(): void { $this->assertFalse((new Compound([new Integer()]))->contains(new String_())); } @@ -107,7 +108,7 @@ public function testCompoundDoesNotContainType() : void * @covers ::__construct * @covers ::__toString */ - public function testCompoundCanBeConstructedAndStringifiedCorrectly() : void + public function testCompoundCanBeConstructedAndStringifiedCorrectly(): void { $this->assertSame('int|bool', (string) (new Compound([new Integer(), new Boolean()]))); } @@ -119,7 +120,7 @@ public function testCompoundCanBeConstructedAndStringifiedCorrectly() : void * @covers ::__construct * @covers ::__toString */ - public function testCompoundDoesNotContainDuplicates() : void + public function testCompoundDoesNotContainDuplicates(): void { $compound = new Compound([new Integer(), new Integer(), new Boolean()]); @@ -134,7 +135,7 @@ public function testCompoundDoesNotContainDuplicates() : void * * @covers ::getIterator */ - public function testCompoundCanBeIterated() : void + public function testCompoundCanBeIterated(): void { $types = [new Integer(), new Boolean()]; diff --git a/tests/unit/Types/ContextTest.php b/tests/unit/Types/ContextTest.php index e65b71f..045706a 100644 --- a/tests/unit/Types/ContextTest.php +++ b/tests/unit/Types/ContextTest.php @@ -24,7 +24,7 @@ class ContextTest extends TestCase * @covers ::__construct * @covers ::getNamespace */ - public function testProvidesANormalizedNamespace() : void + public function testProvidesANormalizedNamespace(): void { $fixture = new Context('\My\Space'); $this->assertSame('My\Space', $fixture->getNamespace()); @@ -34,7 +34,7 @@ public function testProvidesANormalizedNamespace() : void * @covers ::__construct * @covers ::getNamespace */ - public function testInterpretsNamespaceNamedGlobalAsRootNamespace() : void + public function testInterpretsNamespaceNamedGlobalAsRootNamespace(): void { $fixture = new Context('global'); $this->assertSame('', $fixture->getNamespace()); @@ -44,7 +44,7 @@ public function testInterpretsNamespaceNamedGlobalAsRootNamespace() : void * @covers ::__construct * @covers ::getNamespace */ - public function testInterpretsNamespaceNamedDefaultAsRootNamespace() : void + public function testInterpretsNamespaceNamedDefaultAsRootNamespace(): void { $fixture = new Context('default'); $this->assertSame('', $fixture->getNamespace()); @@ -54,7 +54,7 @@ public function testInterpretsNamespaceNamedDefaultAsRootNamespace() : void * @covers ::__construct * @covers ::getNamespaceAliases */ - public function testProvidesNormalizedNamespaceAliases() : void + public function testProvidesNormalizedNamespaceAliases(): void { $fixture = new Context('', ['Space' => '\My\Space']); $this->assertSame(['Space' => 'My\Space'], $fixture->getNamespaceAliases()); diff --git a/tests/unit/Types/InterfaceStringTest.php b/tests/unit/Types/InterfaceStringTest.php index f4afc8a..19d2001 100644 --- a/tests/unit/Types/InterfaceStringTest.php +++ b/tests/unit/Types/InterfaceStringTest.php @@ -25,7 +25,7 @@ class InterfaceStringTest extends TestCase * @dataProvider provideInterfaceStrings * @covers ::__toString */ - public function testInterfaceStringStringifyCorrectly(InterfaceString $array, string $expectedString) : void + public function testInterfaceStringStringifyCorrectly(InterfaceString $array, string $expectedString): void { $this->assertSame($expectedString, (string) $array); } @@ -33,7 +33,7 @@ public function testInterfaceStringStringifyCorrectly(InterfaceString $array, st /** * @return mixed[] */ - public function provideInterfaceStrings() : array + public function provideInterfaceStrings(): array { return [ 'generic interface string' => [new InterfaceString(), 'interface-string'], diff --git a/tests/unit/Types/IterableTest.php b/tests/unit/Types/IterableTest.php index d22d983..6184160 100644 --- a/tests/unit/Types/IterableTest.php +++ b/tests/unit/Types/IterableTest.php @@ -24,7 +24,7 @@ class IterableTest extends TestCase * @covers ::__toString * @dataProvider provideIterables */ - public function testIterableStringifyCorrectly(Iterable_ $iterable, string $expectedString) : void + public function testIterableStringifyCorrectly(Iterable_ $iterable, string $expectedString): void { $this->assertSame($expectedString, (string) $iterable); } @@ -32,7 +32,7 @@ public function testIterableStringifyCorrectly(Iterable_ $iterable, string $expe /** * @return mixed[] */ - public function provideIterables() : array + public function provideIterables(): array { return [ 'simple iterable' => [new Iterable_(), 'iterable'], diff --git a/tests/unit/Types/NullableTest.php b/tests/unit/Types/NullableTest.php index f6fe2b2..1b41c6e 100644 --- a/tests/unit/Types/NullableTest.php +++ b/tests/unit/Types/NullableTest.php @@ -24,7 +24,7 @@ class NullableTest extends TestCase * @covers ::__construct * @covers ::getActualType */ - public function testNullableTypeWrapsCorrectly() : void + public function testNullableTypeWrapsCorrectly(): void { $realType = new String_(); @@ -36,7 +36,7 @@ public function testNullableTypeWrapsCorrectly() : void /** * @covers ::__toString */ - public function testNullableStringifyCorrectly() : void + public function testNullableStringifyCorrectly(): void { $this->assertSame('?string', (string) new Nullable(new String_())); }