From 5ea3cbf8cfc5d6d51fd56d85a1d455fba891b5f0 Mon Sep 17 00:00:00 2001 From: Chuck Burgess Date: Wed, 31 Jan 2018 08:57:30 -0600 Subject: [PATCH] add missing typehints and return types; --- src/DocBlock.php | 4 ++-- src/DocBlock/Description.php | 2 +- src/DocBlock/DescriptionFactory.php | 2 +- src/DocBlock/StandardTagFactory.php | 8 ++++---- src/DocBlock/Tags/Example.php | 2 +- src/DocBlock/Tags/Method.php | 10 +++++----- src/DocBlock/Tags/Reference/Url.php | 2 +- src/DocBlockFactory.php | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/DocBlock.php b/src/DocBlock.php index 13cb383..55eb7ae 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -133,7 +133,7 @@ final class DocBlock * * @return Tag[] */ - public function getTags() + public function getTags(): array { return $this->tags; } @@ -146,7 +146,7 @@ final class DocBlock * * @return Tag[] */ - public function getTagsByName(string $name) + public function getTagsByName(string $name): array { $result = []; diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index a83efcb..bf13504 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -72,7 +72,7 @@ class Description * * @return Tag[] */ - public function getTags() + public function getTags(): array { return $this->tags; } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 5da07e1..bda6c5e 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -61,7 +61,7 @@ class DescriptionFactory * * @return string[] A series of tokens of which the description text is composed. */ - private function lex(string $contents) + private function lex(string $contents): array { $contents = $this->removeSuperfluousStartingWhitespace($contents); diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 106b6b4..2c34994 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -163,7 +163,7 @@ final class StandardTagFactory implements TagFactory * * @return string[] */ - private function extractTagParts(string $tagLine) + private function extractTagParts(string $tagLine): array { $matches = []; if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { @@ -222,7 +222,7 @@ final class StandardTagFactory implements TagFactory * @return mixed[] A series of values that can be passed to the Factory Method of the tag whose parameters * is provided with this method. */ - private function getArgumentsForParametersFromWiring($parameters, $locator) + private function getArgumentsForParametersFromWiring($parameters, $locator): array { $arguments = []; foreach ($parameters as $index => $parameter) { @@ -251,7 +251,7 @@ final class StandardTagFactory implements TagFactory * * @return \ReflectionParameter[] */ - private function fetchParametersForHandlerFactoryMethod(string $handlerClassName) + private function fetchParametersForHandlerFactoryMethod(string $handlerClassName): array { if (! isset($this->tagHandlerParameterCache[$handlerClassName])) { $methodReflection = new \ReflectionMethod($handlerClassName, 'create'); @@ -271,7 +271,7 @@ final class StandardTagFactory implements TagFactory * * @return mixed[] */ - private function getServiceLocatorWithDynamicParameters(TypeContext $context, string $tagName, string $tagBody) + private function getServiceLocatorWithDynamicParameters(TypeContext $context, string $tagName, string $tagBody): array { $locator = array_merge( $this->serviceLocator, diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 437a227..9685bf4 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -81,7 +81,7 @@ final class Example extends BaseTag /** * {@inheritdoc} */ - public static function create(string $body) + public static function create(string $body): ?Tag { // File component: File path in quotes or File URI / Source information if (! preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 2862731..e2ffb01 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -92,12 +92,12 @@ final class Method extends BaseTag implements Factory\StaticMethod )? # Return type (?: - ( + ( (?:[\w\|_\\\\]*\$this[\w\|_\\\\]*) | (?: (?:[\w\|_\\\\]+) - # array notation + # array notation (?:\[\])* )* ) @@ -170,7 +170,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** * @return string[] */ - public function getArguments() + public function getArguments(): array { return $this->arguments; } @@ -204,7 +204,7 @@ final class Method extends BaseTag implements Factory\StaticMethod . ($this->description ? ' ' . $this->description->render() : '')); } - private function filterArguments($arguments) + private function filterArguments(array $arguments = []): array { foreach ($arguments as &$argument) { if (is_string($argument)) { @@ -227,7 +227,7 @@ final class Method extends BaseTag implements Factory\StaticMethod return $arguments; } - private static function stripRestArg($argument) + private static function stripRestArg(string $argument): string { if (strpos($argument, '...') === 0) { $argument = trim(substr($argument, 3)); diff --git a/src/DocBlock/Tags/Reference/Url.php b/src/DocBlock/Tags/Reference/Url.php index 847423b..698d032 100644 --- a/src/DocBlock/Tags/Reference/Url.php +++ b/src/DocBlock/Tags/Reference/Url.php @@ -28,7 +28,7 @@ final class Url implements Reference /** * Url constructor. */ - public function __construct($uri) + public function __construct(string $uri) { Assert::stringNotEmpty($uri); $this->uri = $uri; diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 67c147f..4383bc5 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -127,7 +127,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface * * @return string[] containing the template marker (if any), summary, description and a string containing the tags. */ - private function splitDocBlock(string $comment) + private function splitDocBlock(string $comment): array { // Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This // method does not split tags so we return this verbatim as the fourth result (tags). This saves us the @@ -227,7 +227,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface /** * @return string[] */ - private function splitTagBlockIntoTagLines(string $tags) + private function splitTagBlockIntoTagLines(string $tags): array { $result = []; foreach (explode("\n", $tags) as $tag_line) {