From d874c4d14ae558dbefa9609b7e37dfa9dc90b0dc Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Mon, 27 Nov 2017 00:02:27 +0100 Subject: [PATCH] add strict_types and typehints --- src/DocBlock.php | 28 +++++++++---------- src/DocBlock/Description.php | 12 ++++---- src/DocBlock/DescriptionFactory.php | 14 ++++------ src/DocBlock/ExampleFinder.php | 19 ++++++------- src/DocBlock/Serializer.php | 13 ++++----- src/DocBlock/StandardTagFactory.php | 24 ++++++++-------- src/DocBlock/Tag.php | 5 ++-- src/DocBlock/TagFactory.php | 10 +++---- src/DocBlock/Tags/Author.php | 13 +++++---- src/DocBlock/Tags/BaseTag.php | 5 ++-- src/DocBlock/Tags/Covers.php | 12 ++++---- src/DocBlock/Tags/Deprecated.php | 16 +++++++---- src/DocBlock/Tags/Example.php | 20 ++++++------- src/DocBlock/Tags/Factory/StaticMethod.php | 5 ++-- src/DocBlock/Tags/Factory/Strategy.php | 3 +- src/DocBlock/Tags/Formatter.php | 6 ++-- .../Tags/Formatter/AlignFormatter.php | 6 ++-- .../Tags/Formatter/PassthroughFormatter.php | 6 ++-- src/DocBlock/Tags/Generic.php | 15 +++++----- src/DocBlock/Tags/Link.php | 12 ++++---- src/DocBlock/Tags/Method.php | 11 ++++---- src/DocBlock/Tags/Param.php | 14 +++++----- src/DocBlock/Tags/Property.php | 12 ++++---- src/DocBlock/Tags/PropertyRead.php | 12 ++++---- src/DocBlock/Tags/PropertyWrite.php | 12 ++++---- src/DocBlock/Tags/Reference/Fqsen.php | 5 ++-- src/DocBlock/Tags/Reference/Reference.php | 3 +- src/DocBlock/Tags/Reference/Url.php | 3 +- src/DocBlock/Tags/Return_.php | 11 ++++---- src/DocBlock/Tags/See.php | 10 +++---- src/DocBlock/Tags/Since.php | 16 +++++++---- src/DocBlock/Tags/Source.php | 12 +++++--- src/DocBlock/Tags/Throws.php | 11 ++++---- src/DocBlock/Tags/Uses.php | 12 ++++---- src/DocBlock/Tags/Var_.php | 12 ++++---- src/DocBlock/Tags/Version.php | 16 +++++++---- src/DocBlockFactory.php | 19 ++++++------- src/DocBlockFactoryInterface.php | 10 +++---- 38 files changed, 230 insertions(+), 215 deletions(-) diff --git a/src/DocBlock.php b/src/DocBlock.php index 46605b7..7d38a4f 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -1,4 +1,5 @@ -summary; } @@ -85,7 +85,7 @@ final class DocBlock /** * @return DocBlock\Description */ - public function getDescription() + public function getDescription(): DocBlock\Description { return $this->description; } @@ -95,7 +95,7 @@ final class DocBlock * * @return Types\Context */ - public function getContext() + public function getContext(): Types\Context { return $this->context; } @@ -105,7 +105,7 @@ final class DocBlock * * @return Location */ - public function getLocation() + public function getLocation(): Location { return $this->location; } @@ -131,7 +131,7 @@ final class DocBlock * * @return boolean */ - public function isTemplateStart() + public function isTemplateStart(): bool { return $this->isTemplateStart; } @@ -143,7 +143,7 @@ final class DocBlock * * @return boolean */ - public function isTemplateEnd() + public function isTemplateEnd(): bool { return $this->isTemplateEnd; } @@ -166,7 +166,7 @@ final class DocBlock * * @return Tag[] */ - public function getTagsByName($name) + public function getTagsByName(string $name) { Assert::string($name); @@ -191,7 +191,7 @@ final class DocBlock * * @return bool */ - public function hasTag($name) + public function hasTag(string $name): bool { Assert::string($name); @@ -210,7 +210,6 @@ final class DocBlock * * @param Tag $tag The tag to remove. * - * @return void */ public function removeTag(Tag $tagToRemove) { @@ -227,7 +226,6 @@ final class DocBlock * * @param Tag $tag The tag to add. * - * @return void */ private function addTag(Tag $tag) { diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index 25a79e0..811a0f7 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -1,4 +1,5 @@ -bodyTemplate = $bodyTemplate; $this->tags = $tags; } @@ -84,11 +83,10 @@ class Description * Renders this description as a string where the provided formatter will format the tags in the expected string * format. * - * @param Formatter|null $formatter * * @return string */ - public function render(Formatter $formatter = null) + public function render(Formatter $formatter = null): string { if ($formatter === null) { $formatter = new PassthroughFormatter(); @@ -107,7 +105,7 @@ class Description * * @return string */ - public function __toString() + public function __toString(): string { return $this->render(); } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 48f9c21..54453f6 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -1,4 +1,5 @@ -parse($this->lex($contents), $context); @@ -68,7 +67,7 @@ class DescriptionFactory * * @return string[] A series of tokens of which the description text is composed. */ - private function lex($contents) + private function lex(string $contents) { $contents = $this->removeSuperfluousStartingWhitespace($contents); @@ -103,7 +102,7 @@ class DescriptionFactory ) \}/Sux', $contents, - null, + 0, PREG_SPLIT_DELIM_CAPTURE ); } @@ -112,7 +111,6 @@ class DescriptionFactory * Parses the stream of tokens in to a new set of tokens containing Tags. * * @param string[] $tokens - * @param TypeContext $context * * @return string[]|Tag[] */ @@ -156,7 +154,7 @@ class DescriptionFactory * * @return string */ - private function removeSuperfluousStartingWhitespace($contents) + private function removeSuperfluousStartingWhitespace(string $contents): string { $lines = explode("\n", $contents); diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index 571ed74..8b77160 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -1,4 +1,5 @@ -getFilePath(); @@ -49,9 +49,8 @@ class ExampleFinder * * @param string $directory * - * @return void */ - public function setSourceDirectory($directory = '') + public function setSourceDirectory(string $directory = '') { $this->sourceDirectory = $directory; } @@ -61,7 +60,7 @@ class ExampleFinder * * @return string */ - public function getSourceDirectory() + public function getSourceDirectory(): string { return $this->sourceDirectory; } @@ -101,7 +100,7 @@ class ExampleFinder * * @return string|null */ - private function getExampleFileContents($filename) + private function getExampleFileContents(string $filename) { $normalizedPath = null; @@ -133,7 +132,7 @@ class ExampleFinder * * @return string */ - private function getExamplePathFromExampleDirectory($file) + private function getExamplePathFromExampleDirectory(string $file): string { return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; } @@ -146,7 +145,7 @@ class ExampleFinder * * @return string */ - private function constructExamplePath($directory, $file) + private function constructExamplePath(string $directory, string $file): string { return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; } @@ -158,7 +157,7 @@ class ExampleFinder * * @return string */ - private function getExamplePathFromSource($file) + private function getExamplePathFromSource(string $file): string { return sprintf( '%s%s%s', diff --git a/src/DocBlock/Serializer.php b/src/DocBlock/Serializer.php index 0f355f5..1ed4a2c 100644 --- a/src/DocBlock/Serializer.php +++ b/src/DocBlock/Serializer.php @@ -1,4 +1,5 @@ -indentString, $this->indent); $firstIndent = $this->isFirstLineIndented ? $indent : ''; @@ -114,11 +115,10 @@ class Serializer } /** - * @param DocBlock $docblock * @param $wrapLength * @return string */ - private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength) + private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength): string { $text = $docblock->getSummary() . ((string)$docblock->getDescription() ? "\n\n" . $docblock->getDescription() : ''); @@ -131,13 +131,12 @@ class Serializer } /** - * @param DocBlock $docblock * @param $wrapLength * @param $indent * @param $comment * @return string */ - private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment) + private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment): string { foreach ($docblock->getTags() as $tag) { $tagText = $this->tagFormatter->format($tag); diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 5a8143c..736afe5 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -1,4 +1,5 @@ -serviceLocator[$name] = $value; } @@ -141,7 +141,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function registerTagHandler($tagName, $handler) + public function registerTagHandler(string $tagName, string $handler) { Assert::stringNotEmpty($tagName); Assert::stringNotEmpty($handler); @@ -164,7 +164,7 @@ final class StandardTagFactory implements TagFactory * * @return string[] */ - private function extractTagParts($tagLine) + private function extractTagParts(string $tagLine) { $matches = []; if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { @@ -186,11 +186,10 @@ final class StandardTagFactory implements TagFactory * * @param string $body * @param string $name - * @param TypeContext $context * * @return Tag|null */ - private function createTag($body, $name, TypeContext $context) + private function createTag(string $body, string $name, TypeContext $context) { $handlerClassName = $this->findHandlerClassName($name, $context); $arguments = $this->getArgumentsForParametersFromWiring( @@ -205,11 +204,10 @@ final class StandardTagFactory implements TagFactory * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). * * @param string $tagName - * @param TypeContext $context * * @return string */ - private function findHandlerClassName($tagName, TypeContext $context) + private function findHandlerClassName(string $tagName, TypeContext $context): string { $handlerClassName = Generic::class; if (isset($this->tagHandlerMappings[$tagName])) { @@ -264,7 +262,7 @@ final class StandardTagFactory implements TagFactory * * @return \ReflectionParameter[] */ - private function fetchParametersForHandlerFactoryMethod($handlerClassName) + private function fetchParametersForHandlerFactoryMethod(string $handlerClassName) { if (! isset($this->tagHandlerParameterCache[$handlerClassName])) { $methodReflection = new \ReflectionMethod($handlerClassName, 'create'); @@ -284,7 +282,7 @@ final class StandardTagFactory implements TagFactory * * @return mixed[] */ - private function getServiceLocatorWithDynamicParameters(TypeContext $context, $tagName, $tagBody) + private function getServiceLocatorWithDynamicParameters(TypeContext $context, string $tagName, string $tagBody) { $locator = array_merge( $this->serviceLocator, @@ -307,7 +305,7 @@ final class StandardTagFactory implements TagFactory * * @return bool */ - private function isAnnotation($tagContent) + private function isAnnotation(string $tagContent): bool { // 1. Contains a namespace separator // 2. Contains parenthesis diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index e765367..e6d4b88 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -1,4 +1,5 @@ -authorName; } @@ -61,7 +62,7 @@ final class Author extends BaseTag implements Factory\StaticMethod * * @return string The author's email. */ - public function getEmail() + public function getEmail(): string { return $this->authorEmail; } @@ -71,7 +72,7 @@ final class Author extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : ''); } @@ -83,7 +84,7 @@ final class Author extends BaseTag implements Factory\StaticMethod * * @return static */ - public static function create($body) + public static function create(string $body) { Assert::string($body); diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php index 14bb717..2fbe558 100644 --- a/src/DocBlock/Tags/BaseTag.php +++ b/src/DocBlock/Tags/BaseTag.php @@ -1,4 +1,5 @@ -name; } diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 8d65403..e7e5b73 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -1,4 +1,5 @@ -resolve($parts[0], $context), - $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) + $descriptionFactory->create($parts[1] ?? '', $context) ); } @@ -66,7 +66,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod * * @return Fqsen */ - public function getReference() + public function getReference(): Fqsen { return $this->refers; } @@ -76,7 +76,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index 822c305..4ce0224 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -1,4 +1,5 @@ -create(isset($matches[2]) ? $matches[2] : '', $context) + $descriptionFactory->create($matches[2] ?? '', $context) ); } @@ -80,7 +84,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod * * @return string */ - public function getVersion() + public function getVersion(): string { return $this->version; } @@ -90,7 +94,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->version . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index ecb199b..8c92355 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -1,4 +1,5 @@ -filePath = $filePath; @@ -53,7 +53,7 @@ final class Example extends BaseTag $this->lineCount = $lineCount; $this->name = 'example'; if ($description !== null) { - $this->description = trim($description); + $this->description = trim((string) $description); } $this->isURI = $isURI; @@ -81,7 +81,7 @@ final class Example extends BaseTag /** * {@inheritdoc} */ - public static function create($body) + public static function create(string $body) { // File component: File path in quotes or File URI / Source information if (! preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { @@ -131,7 +131,7 @@ final class Example extends BaseTag * @return string Path to a file to use as an example. * May also be an absolute URI. */ - public function getFilePath() + public function getFilePath(): string { return $this->filePath; } @@ -141,7 +141,7 @@ final class Example extends BaseTag * * @return string */ - public function __toString() + public function __toString(): string { return $this->filePath . ($this->description ? ' ' . $this->description : ''); } @@ -153,7 +153,7 @@ final class Example extends BaseTag * * @return bool */ - private function isUriRelative($uri) + private function isUriRelative(string $uri): bool { return false === strpos($uri, ':'); } @@ -161,7 +161,7 @@ final class Example extends BaseTag /** * @return int */ - public function getStartingLine() + public function getStartingLine(): int { return $this->startingLine; } @@ -169,7 +169,7 @@ final class Example extends BaseTag /** * @return int */ - public function getLineCount() + public function getLineCount(): int { return $this->lineCount; } diff --git a/src/DocBlock/Tags/Factory/StaticMethod.php b/src/DocBlock/Tags/Factory/StaticMethod.php index 98aea45..b0673bd 100644 --- a/src/DocBlock/Tags/Factory/StaticMethod.php +++ b/src/DocBlock/Tags/Factory/StaticMethod.php @@ -1,4 +1,5 @@ -getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string)$tag; } diff --git a/src/DocBlock/Tags/Formatter/PassthroughFormatter.php b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php index 4e2c576..18d672d 100644 --- a/src/DocBlock/Tags/Formatter/PassthroughFormatter.php +++ b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php @@ -1,4 +1,5 @@ -getName() . ' ' . (string)$tag); } diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index e4c53e0..c94c196 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -1,4 +1,5 @@ -validateTagName($name); @@ -42,14 +43,13 @@ class Generic extends BaseTag implements Factory\StaticMethod * * @param string $body * @param string $name - * @param DescriptionFactory $descriptionFactory * @param TypeContext $context * * @return static */ public static function create( - $body, - $name = '', + string $body, + string $name = '', DescriptionFactory $descriptionFactory = null, TypeContext $context = null ) { @@ -67,7 +67,7 @@ class Generic extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->description ? $this->description->render() : ''); } @@ -77,9 +77,8 @@ class Generic extends BaseTag implements Factory\StaticMethod * * @param string $name * - * @return void */ - private function validateTagName($name) + private function validateTagName(string $name) { if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { throw new \InvalidArgumentException( diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index 9c0e367..b246bff 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -1,4 +1,5 @@ -link; } @@ -70,7 +70,7 @@ final class Link extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->link . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 7522529..65ceb44 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -1,4 +1,5 @@ -methodName; } @@ -181,7 +182,7 @@ final class Method extends BaseTag implements Factory\StaticMethod * * @return bool TRUE if the method declaration is for a static method, FALSE otherwise. */ - public function isStatic() + public function isStatic(): bool { return $this->isStatic; } @@ -189,7 +190,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** * @return Type */ - public function getReturnType() + public function getReturnType(): Type { return $this->returnType; } diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 7d699d8..73d31ce 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -1,4 +1,5 @@ -variableName; } @@ -121,7 +121,7 @@ final class Param extends BaseTag implements Factory\StaticMethod * * @return boolean */ - public function isVariadic() + public function isVariadic(): bool { return $this->isVariadic; } @@ -131,7 +131,7 @@ final class Param extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->type ? $this->type . ' ' : '') . ($this->isVariadic() ? '...' : '') diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index f0ef7c0..6f9f4ac 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -1,4 +1,5 @@ -variableName; } @@ -109,7 +109,7 @@ class Property extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->type ? $this->type . ' ' : '') . '$' . $this->variableName diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index e41c0c1..2757213 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -1,4 +1,5 @@ -variableName; } @@ -109,7 +109,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->type ? $this->type . ' ' : '') . '$' . $this->variableName diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index cfdb0ed..68131e8 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -1,4 +1,5 @@ -variableName; } @@ -109,7 +109,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->type ? $this->type . ' ' : '') . '$' . $this->variableName diff --git a/src/DocBlock/Tags/Reference/Fqsen.php b/src/DocBlock/Tags/Reference/Fqsen.php index dc7b8b6..3ba076b 100644 --- a/src/DocBlock/Tags/Reference/Fqsen.php +++ b/src/DocBlock/Tags/Reference/Fqsen.php @@ -1,4 +1,5 @@ -fqsen; } diff --git a/src/DocBlock/Tags/Reference/Reference.php b/src/DocBlock/Tags/Reference/Reference.php index a3ffd24..c02e7f0 100644 --- a/src/DocBlock/Tags/Reference/Reference.php +++ b/src/DocBlock/Tags/Reference/Reference.php @@ -1,4 +1,5 @@ -resolve(isset($parts[0]) ? $parts[0] : '', $context); - $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context); + $type = $typeResolver->resolve($parts[0] ?? '', $context); + $description = $descriptionFactory->create($parts[1] ?? '', $context); return new static($type, $description); } @@ -60,7 +61,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod * * @return Type */ - public function getType() + public function getType(): Type { return $this->type; } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 9e9e723..dab2ce0 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -1,4 +1,5 @@ -refers; } @@ -81,7 +81,7 @@ class See extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 835fb0d..a40d61f 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -1,4 +1,5 @@ -create(isset($matches[2]) ? $matches[2] : '', $context) + $descriptionFactory->create($matches[2] ?? '', $context) ); } @@ -77,7 +81,7 @@ final class Since extends BaseTag implements Factory\StaticMethod * * @return string */ - public function getVersion() + public function getVersion(): string { return $this->version; } @@ -87,7 +91,7 @@ final class Since extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->version . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index 247b1b3..1fc9e96 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -1,4 +1,5 @@ -startingLine; } diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 349e773..5051c4e 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -1,4 +1,5 @@ -resolve(isset($parts[0]) ? $parts[0] : '', $context); - $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context); + $type = $typeResolver->resolve($parts[0] ?? '', $context); + $description = $descriptionFactory->create($parts[1] ?? '', $context); return new static($type, $description); } @@ -60,7 +61,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod * * @return Type */ - public function getType() + public function getType(): Type { return $this->type; } diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index 00dc3e3..34d129e 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -1,4 +1,5 @@ -resolve($parts[0], $context), - $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) + $descriptionFactory->create($parts[1] ?? '', $context) ); } @@ -66,7 +66,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod * * @return Fqsen */ - public function getReference() + public function getReference(): Fqsen { return $this->refers; } @@ -76,7 +76,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->refers . ' ' . $this->description->render(); } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index 8907c95..6e49dab 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -1,4 +1,5 @@ -variableName; } @@ -109,7 +109,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return ($this->type ? $this->type . ' ' : '') . (empty($this->variableName) ? null : ('$' . $this->variableName)) diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index 7bb0420..7aa193a 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -1,4 +1,5 @@ -create(isset($matches[2]) ? $matches[2] : '', $context) + $descriptionFactory->create($matches[2] ?? '', $context) ); } @@ -77,7 +81,7 @@ final class Version extends BaseTag implements Factory\StaticMethod * * @return string */ - public function getVersion() + public function getVersion(): string { return $this->version; } @@ -87,7 +91,7 @@ final class Version extends BaseTag implements Factory\StaticMethod * * @return string */ - public function __toString() + public function __toString(): string { return $this->version . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 1bdb8f4..e1d8467 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -1,4 +1,5 @@ -filterTagBlock($tags); if (!$tags) { @@ -239,7 +238,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface * * @return string[] */ - private function splitTagBlockIntoTagLines($tags) + private function splitTagBlockIntoTagLines(string $tags) { $result = []; foreach (explode("\n", $tags) as $tag_line) { @@ -257,7 +256,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface * @param $tags * @return string */ - private function filterTagBlock($tags) + private function filterTagBlock($tags): string { $tags = trim($tags); if (!$tags) { diff --git a/src/DocBlockFactoryInterface.php b/src/DocBlockFactoryInterface.php index b353342..151134f 100644 --- a/src/DocBlockFactoryInterface.php +++ b/src/DocBlockFactoryInterface.php @@ -1,4 +1,5 @@ -