From aee984014b2ff59ae33c3b05a11904b29790aae9 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2019 10:54:12 +0200 Subject: [PATCH 01/10] Apply new code style --- phpcs.xml.dist | 30 +++ src/DocBlock.php | 38 ++-- src/DocBlock/Description.php | 15 +- src/DocBlock/DescriptionFactory.php | 33 ++- src/DocBlock/ExampleFinder.php | 35 ++-- src/DocBlock/Serializer.php | 86 +++++--- src/DocBlock/StandardTagFactory.php | 121 ++++++----- src/DocBlock/Tag.php | 12 +- src/DocBlock/TagFactory.php | 63 +++--- src/DocBlock/Tags/Author.php | 29 ++- src/DocBlock/Tags/BaseTag.php | 15 +- src/DocBlock/Tags/Covers.php | 18 +- src/DocBlock/Tags/Deprecated.php | 20 +- src/DocBlock/Tags/Example.php | 62 +++--- src/DocBlock/Tags/Factory/StaticMethod.php | 6 +- src/DocBlock/Tags/Factory/Strategy.php | 19 -- src/DocBlock/Tags/Formatter.php | 8 +- .../Tags/Formatter/AlignFormatter.php | 21 +- .../Tags/Formatter/PassthroughFormatter.php | 11 +- src/DocBlock/Tags/Generic.php | 25 +-- src/DocBlock/Tags/Link.php | 33 +-- src/DocBlock/Tags/Method.php | 65 ++++-- src/DocBlock/Tags/Param.php | 55 +++-- src/DocBlock/Tags/Property.php | 32 +-- src/DocBlock/Tags/PropertyRead.php | 32 +-- src/DocBlock/Tags/PropertyWrite.php | 32 +-- src/DocBlock/Tags/Reference/Fqsen.php | 19 +- src/DocBlock/Tags/Reference/Reference.php | 12 +- src/DocBlock/Tags/Reference/Url.php | 19 +- src/DocBlock/Tags/Return_.php | 18 +- src/DocBlock/Tags/See.php | 21 +- src/DocBlock/Tags/Since.php | 20 +- src/DocBlock/Tags/Source.php | 31 +-- src/DocBlock/Tags/Throws.php | 18 +- src/DocBlock/Tags/Uses.php | 18 +- src/DocBlock/Tags/Var_.php | 28 ++- src/DocBlock/Tags/Version.php | 26 +-- src/DocBlockFactory.php | 73 ++++--- src/DocBlockFactoryInterface.php | 9 +- .../DocblocksWithAnnotationsTest.php | 6 +- .../integration/InterpretingDocBlocksTest.php | 6 +- .../ReconstitutingADocBlockTest.php | 6 +- tests/integration/UsingTagsTest.php | 6 +- .../unit/DocBlock/DescriptionFactoryTest.php | 82 ++++---- tests/unit/DocBlock/DescriptionTest.php | 51 ++--- tests/unit/DocBlock/ExampleFinderTest.php | 17 +- tests/unit/DocBlock/SerializerTest.php | 64 +++--- .../unit/DocBlock/StandardTagFactoryTest.php | 159 ++++++++------- tests/unit/DocBlock/Tags/AuthorTest.php | 37 ++-- tests/unit/DocBlock/Tags/CoversTest.php | 42 ++-- tests/unit/DocBlock/Tags/DeprecatedTest.php | 48 +++-- tests/unit/DocBlock/Tags/ExampleTest.php | 36 ++-- .../Tags/Formatter/AlignFormatterTest.php | 32 +-- .../Formatter/PassthroughFormatterTest.php | 22 +- tests/unit/DocBlock/Tags/GenericTest.php | 42 ++-- tests/unit/DocBlock/Tags/LinkTest.php | 43 ++-- tests/unit/DocBlock/Tags/MethodTest.php | 192 +++++++++--------- tests/unit/DocBlock/Tags/ParamTest.php | 56 ++--- tests/unit/DocBlock/Tags/PropertyReadTest.php | 54 ++--- tests/unit/DocBlock/Tags/PropertyTest.php | 54 ++--- .../unit/DocBlock/Tags/PropertyWriteTest.php | 54 ++--- tests/unit/DocBlock/Tags/ReturnTest.php | 46 +++-- tests/unit/DocBlock/Tags/SeeTest.php | 60 +++--- tests/unit/DocBlock/Tags/SinceTest.php | 45 ++-- tests/unit/DocBlock/Tags/SourceTest.php | 54 ++--- tests/unit/DocBlock/Tags/ThrowsTest.php | 46 +++-- tests/unit/DocBlock/Tags/UsesTest.php | 46 +++-- tests/unit/DocBlock/Tags/VarTest.php | 57 +++--- tests/unit/DocBlock/Tags/VersionTest.php | 45 ++-- tests/unit/DocBlockFactoryTest.php | 111 +++++----- tests/unit/DocBlockTest.php | 100 ++++----- 71 files changed, 1661 insertions(+), 1286 deletions(-) create mode 100644 phpcs.xml.dist delete mode 100644 src/DocBlock/Tags/Factory/Strategy.php diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..c030e8d --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,30 @@ + + + The coding standard for phpDocumentor. + + src + tests/unit + */tests/unit/Types/ContextFactoryTest.php + + + *\.php + + + + + + + + */src/*_.php + + + + */src/*/Abstract*.php + + + + + + + + diff --git a/src/DocBlock.php b/src/DocBlock.php index 55eb7ae..a5b9f5c 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -41,8 +41,8 @@ final class DocBlock /** * @param DocBlock\Tag[] $tags - * @param Types\Context $context The context in which the DocBlock occurs. - * @param Location $location The location within the file that this DocBlock occurs in. + * @param Types\Context $context The context in which the DocBlock occurs. + * @param Location $location The location within the file that this DocBlock occurs in. */ public function __construct( string $summary = '', @@ -55,25 +55,25 @@ final class DocBlock ) { Assert::allIsInstanceOf($tags, Tag::class); - $this->summary = $summary; + $this->summary = $summary; $this->description = $description ?: new DocBlock\Description(''); foreach ($tags as $tag) { $this->addTag($tag); } - $this->context = $context; + $this->context = $context; $this->location = $location; - $this->isTemplateEnd = $isTemplateEnd; + $this->isTemplateEnd = $isTemplateEnd; $this->isTemplateStart = $isTemplateStart; } - public function getSummary(): string + public function getSummary() : string { return $this->summary; } - public function getDescription(): DocBlock\Description + public function getDescription() : DocBlock\Description { return $this->description; } @@ -81,7 +81,7 @@ final class DocBlock /** * Returns the current context. */ - public function getContext(): ?Types\Context + public function getContext() : ?Types\Context { return $this->context; } @@ -89,7 +89,7 @@ final class DocBlock /** * Returns the current location. */ - public function getLocation(): ?Location + public function getLocation() : ?Location { return $this->location; } @@ -113,7 +113,7 @@ final class DocBlock * * @see self::isTemplateEnd() for the check whether a closing marker was provided. */ - public function isTemplateStart(): bool + public function isTemplateStart() : bool { return $this->isTemplateStart; } @@ -123,7 +123,7 @@ final class DocBlock * * @see self::isTemplateStart() for a more complete description of the Docblock Template functionality. */ - public function isTemplateEnd(): bool + public function isTemplateEnd() : bool { return $this->isTemplateEnd; } @@ -133,7 +133,7 @@ final class DocBlock * * @return Tag[] */ - public function getTags(): array + public function getTags() : array { return $this->tags; } @@ -146,7 +146,7 @@ final class DocBlock * * @return Tag[] */ - public function getTagsByName(string $name): array + public function getTagsByName(string $name) : array { $result = []; @@ -167,7 +167,7 @@ final class DocBlock * * @param string $name Tag name to check for. */ - public function hasTag(string $name): bool + public function hasTag(string $name) : bool { /** @var Tag $tag */ foreach ($this->getTags() as $tag) { @@ -184,7 +184,7 @@ final class DocBlock * * @param Tag $tagToRemove The tag to remove. */ - public function removeTag(Tag $tagToRemove): void + public function removeTag(Tag $tagToRemove) : void { foreach ($this->tags as $key => $tag) { if ($tag === $tagToRemove) { @@ -199,7 +199,7 @@ final class DocBlock * * @param Tag $tag The tag to add. */ - private function addTag(Tag $tag): void + private function addTag(Tag $tag) : void { $this->tags[] = $tag; } diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index bf13504..40299fc 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tags\Formatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; +use function vsprintf; /** * Object representing to description for a DocBlock. @@ -64,7 +65,7 @@ class Description public function __construct(string $bodyTemplate, array $tags = []) { $this->bodyTemplate = $bodyTemplate; - $this->tags = $tags; + $this->tags = $tags; } /** @@ -72,7 +73,7 @@ class Description * * @return Tag[] */ - public function getTags(): array + public function getTags() : array { return $this->tags; } @@ -81,7 +82,7 @@ class Description * Renders this description as a string where the provided formatter will format the tags in the expected string * format. */ - public function render(?Formatter $formatter = null): string + public function render(?Formatter $formatter = null) : string { if ($formatter === null) { $formatter = new PassthroughFormatter(); @@ -98,7 +99,7 @@ class Description /** * Returns a plain string representation of this description. */ - public function __toString(): string + public function __toString() : string { return $this->render(); } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index bda6c5e..458fac7 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Types\Context as TypeContext; +use const PREG_SPLIT_DELIM_CAPTURE; +use function count; +use function explode; +use function implode; +use function ltrim; +use function min; +use function preg_split; +use function str_replace; +use function strlen; +use function strpos; +use function substr; +use function trim; /** * Creates a new Description object given a body of text. @@ -48,7 +60,7 @@ class DescriptionFactory /** * Returns the parsed text of this description. */ - public function create(string $contents, ?TypeContext $context = null): Description + public function create(string $contents, ?TypeContext $context = null) : Description { [$text, $tags] = $this->parse($this->lex($contents), $context); @@ -58,10 +70,9 @@ class DescriptionFactory /** * Strips the contents from superfluous whitespace and splits the description into a series of tokens. * - * * @return string[] A series of tokens of which the description text is composed. */ - private function lex(string $contents): array + private function lex(string $contents) : array { $contents = $this->removeSuperfluousStartingWhitespace($contents); @@ -108,14 +119,14 @@ class DescriptionFactory * * @return string[]|Tag[] */ - private function parse($tokens, ?TypeContext $context = null): array + private function parse(array $tokens, ?TypeContext $context = null) : array { - $count = count($tokens); + $count = count($tokens); $tagCount = 0; - $tags = []; + $tags = []; for ($i = 1; $i < $count; $i += 2) { - $tags[] = $this->tagFactory->create($tokens[$i], $context); + $tags[] = $this->tagFactory->create($tokens[$i], $context); $tokens[$i] = '%' . ++$tagCount . '$s'; } @@ -144,7 +155,7 @@ class DescriptionFactory * If we do not normalize the indentation then we have superfluous whitespace on the second and subsequent * lines and this may cause rendering issues when, for example, using a Markdown converter. */ - private function removeSuperfluousStartingWhitespace(string $contents): string + private function removeSuperfluousStartingWhitespace(string $contents) : string { $lines = explode("\n", $contents); diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index b147e52..227894c 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tags\Example; +use const DIRECTORY_SEPARATOR; +use function array_slice; +use function file; +use function getcwd; +use function implode; +use function is_readable; +use function rtrim; +use function sprintf; +use function trim; /** * Class used to find an example file's location based on a given ExampleDescriptor. @@ -29,13 +38,13 @@ class ExampleFinder /** * Attempts to find the example contents for the given descriptor. */ - public function find(Example $example): string + public function find(Example $example) : string { $filename = $example->getFilePath(); $file = $this->getExampleFileContents($filename); if (!$file) { - return "** File not found : {$filename} **"; + return sprintf('** File not found : %s **', $filename); } return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount())); @@ -44,7 +53,7 @@ class ExampleFinder /** * Registers the project's root directory where an 'examples' folder can be expected. */ - public function setSourceDirectory(string $directory = ''): void + public function setSourceDirectory(string $directory = '') : void { $this->sourceDirectory = $directory; } @@ -52,7 +61,7 @@ class ExampleFinder /** * Returns the project's root directory where an 'examples' folder can be expected. */ - public function getSourceDirectory(): string + public function getSourceDirectory() : string { return $this->sourceDirectory; } @@ -62,7 +71,7 @@ class ExampleFinder * * @param string[] $directories */ - public function setExampleDirectories(array $directories): void + public function setExampleDirectories(array $directories) : void { $this->exampleDirectories = $directories; } @@ -72,7 +81,7 @@ class ExampleFinder * * @return string[] */ - public function getExampleDirectories() + public function getExampleDirectories() : array { return $this->exampleDirectories; } @@ -88,7 +97,7 @@ class ExampleFinder * 3. Checks the 'examples' folder in the current working directory for examples * 4. Checks the path relative to the current working directory for the given filename */ - private function getExampleFileContents(string $filename): ?string + private function getExampleFileContents(string $filename) : ?string { $normalizedPath = null; @@ -116,7 +125,7 @@ class ExampleFinder /** * Get example filepath based on the example directory inside your project. */ - private function getExamplePathFromExampleDirectory(string $file): string + private function getExamplePathFromExampleDirectory(string $file) : string { return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; } @@ -124,7 +133,7 @@ class ExampleFinder /** * Returns a path to the example file in the given directory.. */ - private function constructExamplePath(string $directory, string $file): string + private function constructExamplePath(string $directory, string $file) : string { return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; } @@ -132,7 +141,7 @@ class ExampleFinder /** * Get example filepath based on sourcecode. */ - private function getExamplePathFromSource(string $file): string + private function getExamplePathFromSource(string $file) : string { return sprintf( '%s%s%s', diff --git a/src/DocBlock/Serializer.php b/src/DocBlock/Serializer.php index d9cb075..e8a5c64 100644 --- a/src/DocBlock/Serializer.php +++ b/src/DocBlock/Serializer.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; +use function sprintf; +use function str_repeat; +use function str_replace; +use function strlen; +use function wordwrap; /** * Converts a DocBlock back from an object to a complete DocComment including Asterisks. @@ -32,25 +39,30 @@ class Serializer /** @var int|null The max length of a line. */ protected $lineLength; - /** @var DocBlock\Tags\Formatter A custom tag formatter. */ + /** @var Formatter A custom tag formatter. */ protected $tagFormatter; /** * Create a Serializer instance. * - * @param int $indent The number of times the indent string is repeated. - * @param string $indentString The string to indent the comment with. - * @param bool $indentFirstLine Whether to indent the first line. - * @param int|null $lineLength The max length of a line or NULL to disable line wrapping. - * @param DocBlock\Tags\Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter. + * @param int $indent The number of times the indent string is repeated. + * @param string $indentString The string to indent the comment with. + * @param bool $indentFirstLine Whether to indent the first line. + * @param int|null $lineLength The max length of a line or NULL to disable line wrapping. + * @param Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter. */ - public function __construct(int $indent = 0, string $indentString = ' ', bool $indentFirstLine = true, ?int $lineLength = null, ?DocBlock\Tags\Formatter $tagFormatter = null) - { - $this->indent = $indent; - $this->indentString = $indentString; + public function __construct( + int $indent = 0, + string $indentString = ' ', + bool $indentFirstLine = true, + ?int $lineLength = null, + ?Formatter $tagFormatter = null + ) { + $this->indent = $indent; + $this->indentString = $indentString; $this->isFirstLineIndented = $indentFirstLine; - $this->lineLength = $lineLength; - $this->tagFormatter = $tagFormatter ?: new DocBlock\Tags\Formatter\PassthroughFormatter(); + $this->lineLength = $lineLength; + $this->tagFormatter = $tagFormatter ?: new PassthroughFormatter(); } /** @@ -60,9 +72,9 @@ class Serializer * * @return string The serialized doc block. */ - public function getDocComment(DocBlock $docblock): string + public function getDocComment(DocBlock $docblock) : string { - $indent = str_repeat($this->indentString, $this->indent); + $indent = str_repeat($this->indentString, $this->indent); $firstIndent = $this->isFirstLineIndented ? $indent : ''; // 3 === strlen(' * ') $wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null; @@ -75,35 +87,41 @@ class Serializer ) ); - $comment = "{$firstIndent}/**\n"; + $comment = $firstIndent . "/**\n"; if ($text) { - $comment .= "{$indent} * {$text}\n"; - $comment .= "{$indent} *\n"; + $comment .= $indent . ' * ' . $text . "\n"; + $comment .= $indent . " *\n"; } $comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment); - $comment .= $indent . ' */'; - - return $comment; + return $comment . $indent . ' */'; } /** * @return mixed */ - private function removeTrailingSpaces($indent, $text) + private function removeTrailingSpaces(string $indent, string $text) { - return str_replace("\n{$indent} * \n", "\n{$indent} *\n", $text); + return str_replace( + sprintf("\n%s * \n", $indent), + sprintf("\n%s *\n", $indent), + $text + ); } /** * @return mixed */ - private function addAsterisksForEachLine($indent, $text) + private function addAsterisksForEachLine(string $indent, string $text) { - return str_replace("\n", "\n{$indent} * ", $text); + return str_replace( + "\n", + sprintf("\n%s * ", $indent), + $text + ); } - private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength): string + private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wrapLength) : string { $text = $docblock->getSummary() . ((string) $docblock->getDescription() ? "\n\n" . $docblock->getDescription() : ''); @@ -115,7 +133,7 @@ class Serializer return $text; } - private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment): string + private function addTagBlock(DocBlock $docblock, ?int $wrapLength, string $indent, string $comment) : string { foreach ($docblock->getTags() as $tag) { $tagText = $this->tagFormatter->format($tag); @@ -123,9 +141,13 @@ class Serializer $tagText = wordwrap($tagText, $wrapLength); } - $tagText = str_replace("\n", "\n{$indent} * ", $tagText); + $tagText = str_replace( + "\n", + sprintf("\n%s * ", $indent), + $tagText + ); - $comment .= "{$indent} * {$tagText}\n"; + $comment .= sprintf("%s * %s\n", $indent, $tagText); } return $comment; diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index b466cfc..b26f761 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; +use InvalidArgumentException; use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod; use phpDocumentor\Reflection\DocBlock\Tags\Generic; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; +use ReflectionMethod; +use ReflectionParameter; use Webmozart\Assert\Assert; +use function array_merge; +use function array_slice; +use function call_user_func_array; +use function count; +use function get_class; +use function preg_match; +use function strpos; /** * Creates a Tag object given the contents of a tag. @@ -42,7 +52,8 @@ final class StandardTagFactory implements TagFactory public const REGEX_TAGNAME = '[\w\-\_\\\\]+'; /** - * @var string[] An array with a tag as a key, and an FQCN to a class that handles it as an array value. + * @var string[] An array with a tag as a key, and an + * FQCN to a class that handles it as an array value. */ private $tagHandlerMappings = [ 'author' => '\phpDocumentor\Reflection\DocBlock\Tags\Author', @@ -67,13 +78,18 @@ final class StandardTagFactory implements TagFactory ]; /** - * @var \ReflectionParameter[][] a lazy-loading cache containing parameters for each tagHandler that has been used. + * @var string[] An array with a anotation s a key, and an + * FQCN to a class that handles it as an array value. + */ + private $annotationMappings = []; + + /** + * @var ReflectionParameter[][] a lazy-loading cache containing parameters + * for each tagHandler that has been used. */ private $tagHandlerParameterCache = []; - /** - * @var FqsenResolver - */ + /** @var FqsenResolver */ private $fqsenResolver; /** @@ -88,9 +104,9 @@ final class StandardTagFactory implements TagFactory * If no tag handlers are provided than the default list in the {@see self::$tagHandlerMappings} property * is used. * - * @param string[] $tagHandlers - * * @see self::registerTagHandler() to add a new tag handler to the existing default list. + * + * @param string[] $tagHandlers */ public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null) { @@ -105,16 +121,16 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function create(string $tagLine, ?TypeContext $context = null): ?Tag + public function create(string $tagLine, ?TypeContext $context = null) : ?Tag { - if (! $context) { + if (!$context) { $context = new TypeContext(''); } [$tagName, $tagBody] = $this->extractTagParts($tagLine); - if ($tagBody !== '' && $tagBody[0] === '[') { - throw new \InvalidArgumentException( + if ($tagBody !== '' && strpos($tagBody, '[') === 0) { + throw new InvalidArgumentException( 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' ); } @@ -125,7 +141,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function addParameter(string $name, $value): void + public function addParameter(string $name, $value) : void { $this->serviceLocator[$name] = $value; } @@ -133,7 +149,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function addService($service, $alias = null): void + public function addService($service, $alias = null) : void { $this->serviceLocator[$alias ?: get_class($service)] = $service; } @@ -141,7 +157,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function registerTagHandler(string $tagName, string $handler): void + public function registerTagHandler(string $tagName, string $handler) : void { Assert::stringNotEmpty($tagName); Assert::stringNotEmpty($handler); @@ -149,7 +165,7 @@ final class StandardTagFactory implements TagFactory Assert::implementsInterface($handler, StaticMethod::class); if (strpos($tagName, '\\') && $tagName[0] !== '\\') { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'A namespaced tag must have a leading backslash as it must be fully qualified' ); } @@ -160,14 +176,13 @@ final class StandardTagFactory implements TagFactory /** * Extracts all components for a tag. * - * * @return string[] */ - private function extractTagParts(string $tagLine): array + private function extractTagParts(string $tagLine) : array { $matches = []; - if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { - throw new \InvalidArgumentException( + if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { + throw new InvalidArgumentException( 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' ); } @@ -183,35 +198,35 @@ final class StandardTagFactory implements TagFactory * Creates a new tag object with the given name and body or returns null if the tag name was recognized but the * body was invalid. */ - private function createTag(string $body, string $name, TypeContext $context): ?Tag + private function createTag(string $body, string $name, TypeContext $context) : ?Tag { $handlerClassName = $this->findHandlerClassName($name, $context); - $arguments = $this->getArgumentsForParametersFromWiring( + $arguments = $this->getArgumentsForParametersFromWiring( $this->fetchParametersForHandlerFactoryMethod($handlerClassName), $this->getServiceLocatorWithDynamicParameters($context, $name, $body) ); try { return call_user_func_array([$handlerClassName, 'create'], $arguments); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { return null; - } + } } /** * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). */ - private function findHandlerClassName(string $tagName, TypeContext $context): string + private function findHandlerClassName(string $tagName, TypeContext $context) : string { $handlerClassName = Generic::class; if (isset($this->tagHandlerMappings[$tagName])) { $handlerClassName = $this->tagHandlerMappings[$tagName]; } elseif ($this->isAnnotation($tagName)) { // TODO: Annotation support is planned for a later stage and as such is disabled for now - // $tagName = (string)$this->fqsenResolver->resolve($tagName, $context); - // if (isset($this->annotationMappings[$tagName])) { - // $handlerClassName = $this->annotationMappings[$tagName]; - // } + $tagName = (string) $this->fqsenResolver->resolve($tagName, $context); + if (isset($this->annotationMappings[$tagName])) { + $handlerClassName = $this->annotationMappings[$tagName]; + } } return $handlerClassName; @@ -220,16 +235,16 @@ final class StandardTagFactory implements TagFactory /** * Retrieves the arguments that need to be passed to the Factory Method with the given Parameters. * - * @param \ReflectionParameter[] $parameters - * @param mixed[] $locator + * @param ReflectionParameter[] $parameters + * @param mixed[] $locator * * @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): array + private function getArgumentsForParametersFromWiring(array $parameters, array $locator) : array { $arguments = []; - foreach ($parameters as $index => $parameter) { + foreach ($parameters as $parameter) { $typeHint = $parameter->getClass() ? $parameter->getClass()->getName() : null; if (isset($locator[$typeHint])) { $arguments[] = $locator[$typeHint]; @@ -252,13 +267,12 @@ final class StandardTagFactory implements TagFactory * Retrieves a series of ReflectionParameter objects for the static 'create' method of the given * tag handler class name. * - * - * @return \ReflectionParameter[] + * @return ReflectionParameter[] */ - private function fetchParametersForHandlerFactoryMethod(string $handlerClassName): array + private function fetchParametersForHandlerFactoryMethod(string $handlerClassName) : array { - if (! isset($this->tagHandlerParameterCache[$handlerClassName])) { - $methodReflection = new \ReflectionMethod($handlerClassName, 'create'); + if (!isset($this->tagHandlerParameterCache[$handlerClassName])) { + $methodReflection = new ReflectionMethod($handlerClassName, 'create'); $this->tagHandlerParameterCache[$handlerClassName] = $methodReflection->getParameters(); } @@ -266,18 +280,24 @@ final class StandardTagFactory implements TagFactory } /** - * Returns a copy of this class' Service Locator with added dynamic parameters, such as the tag's name, body and - * Context. + * Returns a copy of this class' Service Locator with added dynamic parameters, + * such as the tag's name, body and Context. * - * @param TypeContext $context The Context (namespace and aliasses) that may be passed and is used to resolve FQSENs. - * @param string $tagName The name of the tag that may be passed onto the factory method of the Tag class. - * @param string $tagBody The body of the tag that may be passed onto the factory method of the Tag class. + * @param TypeContext $context The Context (namespace and aliasses) that may be + * passed and is used to resolve FQSENs. + * @param string $tagName The name of the tag that may be + * passed onto the factory method of the Tag class. + * @param string $tagBody The body of the tag that may be + * passed onto the factory method of the Tag class. * * @return mixed[] */ - private function getServiceLocatorWithDynamicParameters(TypeContext $context, string $tagName, string $tagBody): array - { - $locator = array_merge( + private function getServiceLocatorWithDynamicParameters( + TypeContext $context, + string $tagName, + string $tagBody + ) : array { + return array_merge( $this->serviceLocator, [ 'name' => $tagName, @@ -285,17 +305,14 @@ final class StandardTagFactory implements TagFactory TypeContext::class => $context, ] ); - - return $locator; } /** * Returns whether the given tag belongs to an annotation. * - * * @todo this method should be populated once we implement Annotation notation support. */ - private function isAnnotation(string $tagContent): bool + 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 76244b2..647f018 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -17,14 +17,14 @@ use phpDocumentor\Reflection\DocBlock\Tags\Formatter; interface Tag { - public function getName(): string; + public function getName() : string; /** * @return Tag|mixed Class that implements Tag */ public static function create(string $body); - public function render(?Formatter $formatter = null): string; + public function render(?Formatter $formatter = null) : string; - public function __toString(): string; + public function __toString() : string; } diff --git a/src/DocBlock/TagFactory.php b/src/DocBlock/TagFactory.php index 23425dc..e52e88d 100644 --- a/src/DocBlock/TagFactory.php +++ b/src/DocBlock/TagFactory.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; +use InvalidArgumentException; use phpDocumentor\Reflection\Types\Context as TypeContext; interface TagFactory @@ -35,9 +36,20 @@ interface TagFactory * * These parameters are injected at the last moment and will override any existing parameter with those names. * - * @param mixed $value + * @param mixed $value */ - public function addParameter(string $name, $value): void; + public function addParameter(string $name, $value) : void; + + /** + * Factory method responsible for instantiating the correct sub type. + * + * @param string $tagLine The text for this tag, including description. + * + * @return Tag A new tag object. + * + * @throws InvalidArgumentException If an invalid tag line was presented. + */ + public function create(string $tagLine, ?TypeContext $context = null) : ?Tag; /** * Registers a service with the Service Locator using the FQCN of the class or the alias, if provided. @@ -47,39 +59,26 @@ interface TagFactory * * Because interfaces are regularly used as type-hints this method provides an alias parameter; if the FQCN of the * interface is passed as alias then every time that interface is requested the provided service will be returned. - * - * @param object $service */ - public function addService($service): void; - - /** - * Factory method responsible for instantiating the correct sub type. - * - * @param string $tagLine The text for this tag, including description. - * - * @throws \InvalidArgumentException if an invalid tag line was presented. - * - * @return Tag A new tag object. - */ - public function create(string $tagLine, ?TypeContext $context = null): ?Tag; + public function addService(object $service) : void; /** * Registers a handler for tags. * - * If you want to use your own tags then you can use this method to instruct the TagFactory to register the name - * of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement the {@see Tag} interface (and thus - * the create method). + * If you want to use your own tags then you can use this method to instruct the TagFactory + * to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement + * the {@see Tag} interface (and thus the create method). * - * @param string $tagName Name of tag to register a handler for. When registering a namespaced tag, the full - * name, along with a prefixing slash MUST be provided. + * @param string $tagName Name of tag to register a handler for. When registering a namespaced tag, + * the full name, along with a prefixing slash MUST be provided. * @param string $handler FQCN of handler. * - * @throws \InvalidArgumentException if the tag name is not a string - * @throws \InvalidArgumentException if the tag name is namespaced (contains backslashes) but does not start with - * a backslash - * @throws \InvalidArgumentException if the handler is not a string - * @throws \InvalidArgumentException if the handler is not an existing class - * @throws \InvalidArgumentException if the handler does not implement the {@see Tag} interface + * @throws InvalidArgumentException If the tag name is not a string. + * @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but + * does not start with a backslash. + * @throws InvalidArgumentException If the handler is not a string. + * @throws InvalidArgumentException If the handler is not an existing class. + * @throws InvalidArgumentException If the handler does not implement the {@see Tag} interface. */ - public function registerTagHandler(string $tagName, string $handler): void; + public function registerTagHandler(string $tagName, string $handler) : void; } diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index 60f082c..4bebe49 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use InvalidArgumentException; +use const FILTER_VALIDATE_EMAIL; +use function filter_var; +use function preg_match; +use function strlen; +use function trim; + /** * Reflection class for an {@}author tag in a Docblock. */ @@ -33,10 +40,10 @@ final class Author extends BaseTag implements Factory\StaticMethod public function __construct(string $authorName, string $authorEmail) { if ($authorEmail && !filter_var($authorEmail, FILTER_VALIDATE_EMAIL)) { - throw new \InvalidArgumentException('The author tag does not have a valid e-mail address'); + throw new InvalidArgumentException('The author tag does not have a valid e-mail address'); } - $this->authorName = $authorName; + $this->authorName = $authorName; $this->authorEmail = $authorEmail; } @@ -45,7 +52,7 @@ final class Author extends BaseTag implements Factory\StaticMethod * * @return string The author's name. */ - public function getAuthorName(): string + public function getAuthorName() : string { return $this->authorName; } @@ -55,7 +62,7 @@ final class Author extends BaseTag implements Factory\StaticMethod * * @return string The author's email. */ - public function getEmail(): string + public function getEmail() : string { return $this->authorEmail; } @@ -63,7 +70,7 @@ final class Author extends BaseTag implements Factory\StaticMethod /** * Returns this tag in string form. */ - public function __toString(): string + public function __toString() : string { return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : ''); } @@ -71,7 +78,7 @@ final class Author extends BaseTag implements Factory\StaticMethod /** * Attempts to create a new Author object based on †he tag body. */ - public static function create(string $body): ?self + public static function create(string $body) : ?self { $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches); if (!$splitTagContent) { @@ -79,7 +86,7 @@ final class Author extends BaseTag implements Factory\StaticMethod } $authorName = trim($matches[1]); - $email = isset($matches[2]) ? trim($matches[2]) : ''; + $email = isset($matches[2]) ? trim($matches[2]) : ''; return new static($authorName, $email); } diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php index d844ed1..7a1b949 100644 --- a/src/DocBlock/Tags/BaseTag.php +++ b/src/DocBlock/Tags/BaseTag.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -32,17 +32,20 @@ abstract class BaseTag implements DocBlock\Tag * * @return string The name of this tag. */ - public function getName(): string + public function getName() : string { return $this->name; } + /** + * @return Description|string|null + */ public function getDescription() { return $this->description; } - public function render(?Formatter $formatter = null): string + public function render(?Formatter $formatter = null) : string { if ($formatter === null) { $formatter = new Formatter\PassthroughFormatter(); diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 162d14d..2a1ebf1 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -19,12 +19,14 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_split; /** * Reflection class for a @covers tag in a Docblock. */ final class Covers extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'covers'; /** @var Fqsen */ @@ -35,7 +37,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod */ public function __construct(Fqsen $refers, ?Description $description = null) { - $this->refers = $refers; + $this->refers = $refers; $this->description = $description; } @@ -47,7 +49,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?FqsenResolver $resolver = null, ?TypeContext $context = null - ): self { + ) : self { Assert::notEmpty($body); $parts = preg_split('/\s+/Su', $body, 2); @@ -61,7 +63,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod /** * Returns the structural element this tag refers to. */ - public function getReference(): Fqsen + public function getReference() : Fqsen { return $this->refers; } @@ -69,7 +71,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod /** * Returns a string representation of this tag. */ - public function __toString(): string + 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 0c9ff12..9883414 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -17,12 +17,14 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; /** * Reflection class for a {@}deprecated tag in a Docblock. */ final class Deprecated extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'deprecated'; /** @@ -44,11 +46,11 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod /** @var string The version vector. */ private $version = ''; - public function __construct($version = null, ?Description $description = null) + public function __construct(?string $version = null, ?Description $description = null) { Assert::nullOrStringNotEmpty($version); - $this->version = $version; + $this->version = $version; $this->description = $description; } @@ -59,7 +61,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod ?string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { if (empty($body)) { return new static(); } @@ -68,7 +70,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return new static( null, - null !== $descriptionFactory ? $descriptionFactory->create($body, $context) : null + $descriptionFactory !== null ? $descriptionFactory->create($body, $context) : null ); } @@ -81,7 +83,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod /** * Gets the version section of the tag. */ - public function getVersion(): ?string + public function getVersion() : ?string { return $this->version; } @@ -89,7 +91,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + 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 d43fe83..122d6d3 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Tag; use Webmozart\Assert\Assert; +use function array_key_exists; +use function preg_match; +use function rawurlencode; +use function str_replace; +use function strpos; +use function trim; /** * Reflection class for a {@}example tag in a Docblock. */ final class Example extends BaseTag { - /** - * @var string Path to a file to use as an example. May also be an absolute URI. - */ + /** @var string Path to a file to use as an example. May also be an absolute URI. */ private $filePath; /** @@ -32,26 +37,25 @@ final class Example extends BaseTag */ private $isURI = false; - /** - * @var int - */ + /** @var int */ private $startingLine; - /** - * @var int - */ + /** @var int */ private $lineCount; + /** + * @param string|Description|null $description + */ public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, $description) { Assert::notEmpty($filePath); Assert::greaterThanEq($startingLine, 0); Assert::greaterThanEq($lineCount, 0); - $this->filePath = $filePath; + $this->filePath = $filePath; $this->startingLine = $startingLine; - $this->lineCount = $lineCount; - $this->name = 'example'; + $this->lineCount = $lineCount; + $this->name = 'example'; if ($description !== null) { $this->description = trim((string) $description); } @@ -64,7 +68,7 @@ final class Example extends BaseTag */ public function getContent() { - if (null === $this->description) { + if ($this->description === null) { $filePath = '"' . $this->filePath . '"'; if ($this->isURI) { $filePath = $this->isUriRelative($this->filePath) @@ -81,24 +85,24 @@ final class Example extends BaseTag /** * {@inheritdoc} */ - public static function create(string $body): ?Tag + 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)) { + if (!preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { return null; } $filePath = null; - $fileUri = null; - if ('' !== $matches[1]) { + $fileUri = null; + if ($matches[1] !== '') { $filePath = $matches[1]; } else { $fileUri = $matches[2]; } $startingLine = 1; - $lineCount = 0; - $description = null; + $lineCount = 0; + $description = null; if (array_key_exists(3, $matches)) { $description = $matches[3]; @@ -117,7 +121,7 @@ final class Example extends BaseTag } return new static( - $filePath !== null ? $filePath : $fileUri, + $filePath ?? $fileUri, $fileUri !== null, $startingLine, $lineCount, @@ -131,7 +135,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(): string + public function getFilePath() : string { return $this->filePath; } @@ -139,7 +143,7 @@ final class Example extends BaseTag /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return $this->filePath . ($this->description ? ' ' . $this->description : ''); } @@ -147,17 +151,17 @@ final class Example extends BaseTag /** * Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute). */ - private function isUriRelative(string $uri): bool + private function isUriRelative(string $uri) : bool { - return false === strpos($uri, ':'); + return strpos($uri, ':') === false; } - public function getStartingLine(): int + public function getStartingLine() : int { return $this->startingLine; } - public function getLineCount(): int + public function getLineCount() : int { return $this->lineCount; } diff --git a/src/DocBlock/Tags/Factory/StaticMethod.php b/src/DocBlock/Tags/Factory/StaticMethod.php index 753985a..b21a3f0 100644 --- a/src/DocBlock/Tags/Factory/StaticMethod.php +++ b/src/DocBlock/Tags/Factory/StaticMethod.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ diff --git a/src/DocBlock/Tags/Factory/Strategy.php b/src/DocBlock/Tags/Factory/Strategy.php deleted file mode 100644 index d1d5a27..0000000 --- a/src/DocBlock/Tags/Factory/Strategy.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; - -interface Strategy -{ - public function create($body): void; -} diff --git a/src/DocBlock/Tags/Formatter.php b/src/DocBlock/Tags/Formatter.php index 68ff419..92fb9e6 100644 --- a/src/DocBlock/Tags/Formatter.php +++ b/src/DocBlock/Tags/Formatter.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -20,5 +20,5 @@ interface Formatter /** * Formats a tag into a string representation according to a specific format, such as Markdown. */ - public function format(Tag $tag): string; + public function format(Tag $tag) : string; } diff --git a/src/DocBlock/Tags/Formatter/AlignFormatter.php b/src/DocBlock/Tags/Formatter/AlignFormatter.php index 6a47f5d..b1a406c 100644 --- a/src/DocBlock/Tags/Formatter/AlignFormatter.php +++ b/src/DocBlock/Tags/Formatter/AlignFormatter.php @@ -1,4 +1,6 @@ - - * @copyright 2018 Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -16,6 +15,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use function max; +use function str_repeat; +use function strlen; class AlignFormatter implements Formatter { @@ -23,8 +25,6 @@ class AlignFormatter implements Formatter protected $maxLen = 0; /** - * Constructor. - * * @param Tag[] $tags All tags that should later be aligned with the formatter. */ public function __construct(array $tags) @@ -37,8 +37,13 @@ class AlignFormatter implements Formatter /** * Formats the given tag to return a simple plain text version. */ - public function format(Tag $tag): string + public function format(Tag $tag) : string { - return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string) $tag; + return '@' . $tag->getName() . + str_repeat( + ' ', + $this->maxLen - strlen($tag->getName()) + 1 + ) . + $tag; } } diff --git a/src/DocBlock/Tags/Formatter/PassthroughFormatter.php b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php index a143afa..f26d22f 100644 --- a/src/DocBlock/Tags/Formatter/PassthroughFormatter.php +++ b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -15,14 +15,15 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use function trim; class PassthroughFormatter implements Formatter { /** * Formats the given tag to return a simple plain text version. */ - public function format(Tag $tag): string + public function format(Tag $tag) : string { - return trim('@' . $tag->getName() . ' ' . (string) $tag); + return trim('@' . $tag->getName() . ' ' . $tag); } } diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index 444bad4..713a10c 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use InvalidArgumentException; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; /** * Parses a tag definition for a DocBlock. @@ -27,21 +29,20 @@ class Generic extends BaseTag implements Factory\StaticMethod /** * Parses a tag and populates the member variables. * - * @param string $name Name of the tag. + * @param string $name Name of the tag. * @param Description $description The contents of the given tag. */ public function __construct(string $name, ?Description $description = null) { $this->validateTagName($name); - $this->name = $name; + $this->name = $name; $this->description = $description; } /** * Creates a new tag that represents any unknown tag type. * - * * @return static */ public static function create( @@ -49,11 +50,11 @@ class Generic extends BaseTag implements Factory\StaticMethod string $name = '', ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($name); Assert::notNull($descriptionFactory); - $description = $descriptionFactory && $body !== "" ? $descriptionFactory->create($body, $context) : null; + $description = $descriptionFactory && $body !== '' ? $descriptionFactory->create($body, $context) : null; return new static($name, $description); } @@ -61,7 +62,7 @@ class Generic extends BaseTag implements Factory\StaticMethod /** * Returns the tag as a serialized string */ - public function __toString(): string + public function __toString() : string { return $this->description ? $this->description->render() : ''; } @@ -69,10 +70,10 @@ class Generic extends BaseTag implements Factory\StaticMethod /** * Validates if the tag name matches the expected format, otherwise throws an exception. */ - private function validateTagName(string $name): void + private function validateTagName(string $name) : void { - if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { - throw new \InvalidArgumentException( + if (!preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { + throw new InvalidArgumentException( 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' . 'hyphens and backslashes.' ); diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index 45953ed..475357f 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -1,14 +1,14 @@ - - * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -17,34 +17,39 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_split; /** * Reflection class for a @link tag in a Docblock. */ final class Link extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'link'; /** @var string */ - private $link = ''; + private $link; /** * Initializes a link to a URL. */ public function __construct(string $link, ?Description $description = null) { - $this->link = $link; + $this->link = $link; $this->description = $description; } /** * {@inheritdoc} */ - public static function create(string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null): self - { + public static function create( + string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ) : self { Assert::notNull($descriptionFactory); - $parts = preg_split('/\s+/Su', $body, 2); + $parts = preg_split('/\s+/Su', $body, 2); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; return new static($parts[0], $description); @@ -53,7 +58,7 @@ final class Link extends BaseTag implements Factory\StaticMethod /** * Gets the link */ - public function getLink(): string + public function getLink() : string { return $this->link; } @@ -61,7 +66,7 @@ final class Link extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + 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 e2ffb01..251cf03 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use InvalidArgumentException; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Type; @@ -20,12 +21,24 @@ use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use phpDocumentor\Reflection\Types\Void_; use Webmozart\Assert\Assert; +use function array_keys; +use function explode; +use function implode; +use function is_string; +use function preg_match; +use function sort; +use function strlen; +use function strpos; +use function substr; +use function trim; +use function var_export; /** * Reflection class for an {@}method in a Docblock. */ final class Method extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'method'; /** @var string */ @@ -40,11 +53,14 @@ final class Method extends BaseTag implements Factory\StaticMethod /** @var Type */ private $returnType; + /** + * @param mixed[][] $arguments $arguments + */ public function __construct( - $methodName, + string $methodName, array $arguments = [], ?Type $returnType = null, - $static = false, + bool $static = false, ?Description $description = null ) { Assert::stringNotEmpty($methodName); @@ -54,10 +70,10 @@ final class Method extends BaseTag implements Factory\StaticMethod $returnType = new Void_(); } - $this->methodName = $methodName; - $this->arguments = $this->filterArguments($arguments); - $this->returnType = $returnType; - $this->isStatic = $static; + $this->methodName = $methodName; + $this->arguments = $this->filterArguments($arguments); + $this->returnType = $returnType; + $this->isStatic = $static; $this->description = $description; } @@ -69,7 +85,7 @@ final class Method extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): ?self { + ) : ?self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); @@ -131,7 +147,7 @@ final class Method extends BaseTag implements Factory\StaticMethod $returnType = 'void'; } - $returnType = $typeResolver->resolve($returnType, $context); + $returnType = $typeResolver->resolve($returnType, $context); $description = $descriptionFactory->create($description, $context); if (is_string($arguments) && strlen($arguments) > 0) { @@ -145,7 +161,7 @@ final class Method extends BaseTag implements Factory\StaticMethod $argumentType = $typeResolver->resolve($argument[0], $context); $argumentName = ''; if (isset($argument[1])) { - $argument[1] = self::stripRestArg($argument[1]); + $argument[1] = self::stripRestArg($argument[1]); $argumentName = substr($argument[1], 1); } } @@ -162,7 +178,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** * Retrieves the method name. */ - public function getMethodName(): string + public function getMethodName() : string { return $this->methodName; } @@ -170,7 +186,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** * @return string[] */ - public function getArguments(): array + public function getArguments() : array { return $this->arguments; } @@ -180,17 +196,17 @@ 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(): bool + public function isStatic() : bool { return $this->isStatic; } - public function getReturnType(): Type + public function getReturnType() : Type { return $this->returnType; } - public function __toString(): string + public function __toString() : string { $arguments = []; foreach ($this->arguments as $argument) { @@ -204,21 +220,26 @@ final class Method extends BaseTag implements Factory\StaticMethod . ($this->description ? ' ' . $this->description->render() : '')); } - private function filterArguments(array $arguments = []): array + /** + * @param mixed[][] $arguments + * + * @return mixed[][] + */ + private function filterArguments(array $arguments = []) : array { foreach ($arguments as &$argument) { if (is_string($argument)) { $argument = ['name' => $argument]; } - if (! isset($argument['type'])) { + if (!isset($argument['type'])) { $argument['type'] = new Void_(); } $keys = array_keys($argument); sort($keys); if ($keys !== ['name', 'type']) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) ); } @@ -227,7 +248,7 @@ final class Method extends BaseTag implements Factory\StaticMethod return $arguments; } - private static function stripRestArg(string $argument): string + private static function stripRestArg(string $argument) : string { if (strpos($argument, '...') === 0) { $argument = trim(substr($argument, 3)); diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 5ebf1e8..5d02cb6 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,6 +19,13 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use const PREG_SPLIT_DELIM_CAPTURE; +use function array_shift; +use function implode; +use function preg_split; +use function strlen; +use function strpos; +use function substr; /** * Reflection class for the {@}param tag in a Docblock. @@ -37,12 +44,16 @@ final class Param extends BaseTag implements Factory\StaticMethod /** @var bool determines whether this is a variadic argument */ private $isVariadic = false; - public function __construct(string $variableName, ?Type $type = null, bool $isVariadic = false, ?Description $description = null) - { + public function __construct( + string $variableName, + ?Type $type = null, + bool $isVariadic = false, + ?Description $description = null + ) { $this->variableName = $variableName; - $this->type = $type; - $this->isVariadic = $isVariadic; - $this->description = $description; + $this->type = $type; + $this->isVariadic = $isVariadic; + $this->description = $description; } /** @@ -53,14 +64,14 @@ final class Param extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); - $type = null; + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; $variableName = ''; - $isVariadic = false; + $isVariadic = false; // if the first item that is encountered is not a variable; it is a type if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { @@ -69,12 +80,14 @@ final class Param extends BaseTag implements Factory\StaticMethod } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$' || substr($parts[0], 0, 4) === '...$')) { + if (isset($parts[0]) && (strlen($parts[0]) > 0) && + (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0) + ) { $variableName = array_shift($parts); array_shift($parts); if (substr($variableName, 0, 3) === '...') { - $isVariadic = true; + $isVariadic = true; $variableName = substr($variableName, 3); } @@ -91,7 +104,7 @@ final class Param extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName(): string + public function getVariableName() : string { return $this->variableName; } @@ -99,7 +112,7 @@ final class Param extends BaseTag implements Factory\StaticMethod /** * Returns the variable's type or null if unknown. */ - public function getType(): ?Type + public function getType() : ?Type { return $this->type; } @@ -107,7 +120,7 @@ final class Param extends BaseTag implements Factory\StaticMethod /** * Returns whether this tag is variadic. */ - public function isVariadic(): bool + public function isVariadic() : bool { return $this->isVariadic; } @@ -115,11 +128,11 @@ final class Param extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . ($this->isVariadic() ? '...' : '') - . '$' . $this->variableName - . ($this->description ? ' ' . $this->description : ''); + . ($this->isVariadic() ? '...' : '') + . '$' . $this->variableName + . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index c1316be..a81b3f0 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,6 +19,12 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use const PREG_SPLIT_DELIM_CAPTURE; +use function array_shift; +use function implode; +use function preg_split; +use function strlen; +use function substr; /** * Reflection class for a {@}property tag in a Docblock. @@ -37,8 +43,8 @@ class Property extends BaseTag implements Factory\StaticMethod public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; - $this->type = $type; - $this->description = $description; + $this->type = $type; + $this->description = $description; } /** @@ -49,12 +55,12 @@ class Property extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); - $type = null; + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type @@ -81,7 +87,7 @@ class Property extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName(): string + public function getVariableName() : string { return $this->variableName; } @@ -89,7 +95,7 @@ class Property extends BaseTag implements Factory\StaticMethod /** * Returns the variable's type or null if unknown. */ - public function getType(): ?Type + public function getType() : ?Type { return $this->type; } @@ -97,10 +103,10 @@ class Property extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName - . ($this->description ? ' ' . $this->description : ''); + . '$' . $this->variableName + . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index e1dd1cb..f98e332 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,6 +19,12 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use const PREG_SPLIT_DELIM_CAPTURE; +use function array_shift; +use function implode; +use function preg_split; +use function strlen; +use function substr; /** * Reflection class for a {@}property-read tag in a Docblock. @@ -37,8 +43,8 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; - $this->type = $type; - $this->description = $description; + $this->type = $type; + $this->description = $description; } /** @@ -49,12 +55,12 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); - $type = null; + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type @@ -81,7 +87,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName(): string + public function getVariableName() : string { return $this->variableName; } @@ -89,7 +95,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod /** * Returns the variable's type or null if unknown. */ - public function getType(): ?Type + public function getType() : ?Type { return $this->type; } @@ -97,10 +103,10 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName - . ($this->description ? ' ' . $this->description : ''); + . '$' . $this->variableName + . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 846e30a..8e45ab8 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,6 +19,12 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use const PREG_SPLIT_DELIM_CAPTURE; +use function array_shift; +use function implode; +use function preg_split; +use function strlen; +use function substr; /** * Reflection class for a {@}property-write tag in a Docblock. @@ -37,8 +43,8 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; - $this->type = $type; - $this->description = $description; + $this->type = $type; + $this->description = $description; } /** @@ -49,12 +55,12 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); - $type = null; + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type @@ -81,7 +87,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName(): string + public function getVariableName() : string { return $this->variableName; } @@ -89,7 +95,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod /** * Returns the variable's type or null if unknown. */ - public function getType(): ?Type + public function getType() : ?Type { return $this->type; } @@ -97,10 +103,10 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName - . ($this->description ? ' ' . $this->description : ''); + . '$' . $this->variableName + . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Reference/Fqsen.php b/src/DocBlock/Tags/Reference/Fqsen.php index 748ea3c..cede74c 100644 --- a/src/DocBlock/Tags/Reference/Fqsen.php +++ b/src/DocBlock/Tags/Reference/Fqsen.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; @@ -16,18 +16,13 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; use phpDocumentor\Reflection\Fqsen as RealFqsen; /** - * Fqsen reference used by {@see phpDocumentor\Reflection\DocBlock\Tags\See} + * Fqsen reference used by {@see \phpDocumentor\Reflection\DocBlock\Tags\See} */ final class Fqsen implements Reference { - /** - * @var RealFqsen - */ + /** @var RealFqsen */ private $fqsen; - /** - * Fqsen constructor. - */ public function __construct(RealFqsen $fqsen) { $this->fqsen = $fqsen; @@ -36,7 +31,7 @@ final class Fqsen implements Reference /** * @return string string representation of the referenced fqsen */ - public function __toString(): string + public function __toString() : string { return (string) $this->fqsen; } diff --git a/src/DocBlock/Tags/Reference/Reference.php b/src/DocBlock/Tags/Reference/Reference.php index 3950196..5eedcbc 100644 --- a/src/DocBlock/Tags/Reference/Reference.php +++ b/src/DocBlock/Tags/Reference/Reference.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; /** - * Interface for references in {@see phpDocumentor\Reflection\DocBlock\Tags\See} + * Interface for references in {@see \phpDocumentor\Reflection\DocBlock\Tags\See} */ interface Reference { - public function __toString(): string; + public function __toString() : string; } diff --git a/src/DocBlock/Tags/Reference/Url.php b/src/DocBlock/Tags/Reference/Url.php index 698d032..1b2374b 100644 --- a/src/DocBlock/Tags/Reference/Url.php +++ b/src/DocBlock/Tags/Reference/Url.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; @@ -16,25 +16,20 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; use Webmozart\Assert\Assert; /** - * Url reference used by {@see phpDocumentor\Reflection\DocBlock\Tags\See} + * Url reference used by {@see \phpDocumentor\Reflection\DocBlock\Tags\See} */ final class Url implements Reference { - /** - * @var string - */ + /** @var string */ private $uri; - /** - * Url constructor. - */ public function __construct(string $uri) { Assert::stringNotEmpty($uri); $this->uri = $uri; } - public function __toString(): string + public function __toString() : string { return $this->uri; } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index ae1d2e1..dac5036 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,12 +19,14 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_split; /** * Reflection class for a {@}return tag in a Docblock. */ final class Return_ extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'return'; /** @var Type */ @@ -32,7 +34,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod public function __construct(Type $type, ?Description $description = null) { - $this->type = $type; + $this->type = $type; $this->description = $description; } @@ -44,12 +46,12 @@ final class Return_ extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::allNotNull([$typeResolver, $descriptionFactory]); $parts = preg_split('/\s+/Su', $body, 2); - $type = $typeResolver->resolve($parts[0] ?? '', $context); + $type = $typeResolver->resolve($parts[0] ?? '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context); return new static($type, $description); @@ -58,12 +60,12 @@ final class Return_ extends BaseTag implements Factory\StaticMethod /** * Returns the type section of the variable. */ - public function getType(): Type + public function getType() : Type { return $this->type; } - public function __toString(): string + public function __toString() : string { return $this->type . ' ' . $this->description; } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index bc98297..218309e 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -21,12 +21,15 @@ use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; +use function preg_split; /** * Reflection class for an {@}see tag in a Docblock. */ class See extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'see'; /** @var Reference */ @@ -37,7 +40,7 @@ class See extends BaseTag implements Factory\StaticMethod */ public function __construct(Reference $refers, ?Description $description = null) { - $this->refers = $refers; + $this->refers = $refers; $this->description = $description; } @@ -49,10 +52,10 @@ class See extends BaseTag implements Factory\StaticMethod ?FqsenResolver $resolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::allNotNull([$resolver, $descriptionFactory]); - $parts = preg_split('/\s+/Su', $body, 2); + $parts = preg_split('/\s+/Su', $body, 2); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; // https://tools.ietf.org/html/rfc2396#section-3 @@ -66,7 +69,7 @@ class See extends BaseTag implements Factory\StaticMethod /** * Returns the ref of this tag. */ - public function getReference(): Reference + public function getReference() : Reference { return $this->refers; } @@ -74,7 +77,7 @@ class See extends BaseTag implements Factory\StaticMethod /** * Returns a string representation of this tag. */ - public function __toString(): string + 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 5af7dc2..4b96796 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -17,12 +17,14 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; /** * Reflection class for a {@}since tag in a Docblock. */ final class Since extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'since'; /** @@ -44,11 +46,11 @@ final class Since extends BaseTag implements Factory\StaticMethod /** @var string The version vector. */ private $version = ''; - public function __construct($version = null, ?Description $description = null) + public function __construct(?string $version = null, ?Description $description = null) { Assert::nullOrStringNotEmpty($version); - $this->version = $version; + $this->version = $version; $this->description = $description; } @@ -56,13 +58,13 @@ final class Since extends BaseTag implements Factory\StaticMethod ?string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): ?self { + ) : ?self { if (empty($body)) { return new static(); } $matches = []; - if (! preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return null; } @@ -75,7 +77,7 @@ final class Since extends BaseTag implements Factory\StaticMethod /** * Gets the version section of the tag. */ - public function getVersion(): ?string + public function getVersion() : ?string { return $this->version; } @@ -83,7 +85,7 @@ final class Since extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + 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 d63fb8a..c6286fd 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -17,6 +17,7 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; /** * Reflection class for a {@}source tag in a Docblock. @@ -32,14 +33,18 @@ final class Source extends BaseTag implements Factory\StaticMethod /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */ private $lineCount; + /** + * @param int|string $startingLine should be a to int convertible value + * @param int|string|null $lineCount should be a to int convertible value + */ public function __construct($startingLine, $lineCount = null, ?Description $description = null) { Assert::integerish($startingLine); Assert::nullOrIntegerish($lineCount); $this->startingLine = (int) $startingLine; - $this->lineCount = $lineCount !== null ? (int) $lineCount : null; - $this->description = $description; + $this->lineCount = $lineCount !== null ? (int) $lineCount : null; + $this->description = $description; } /** @@ -49,13 +54,13 @@ final class Source extends BaseTag implements Factory\StaticMethod string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::notNull($descriptionFactory); $startingLine = 1; - $lineCount = null; - $description = null; + $lineCount = null; + $description = null; // Starting line / Number of lines / Description if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) { @@ -76,7 +81,7 @@ final class Source extends BaseTag implements Factory\StaticMethod * @return int The starting line, relative to the structural element's * location. */ - public function getStartingLine(): int + public function getStartingLine() : int { return $this->startingLine; } @@ -87,15 +92,15 @@ final class Source extends BaseTag implements Factory\StaticMethod * @return int|null The number of lines, relative to the starting line. NULL * means "to the end". */ - public function getLineCount(): ?int + public function getLineCount() : ?int { return $this->lineCount; } - public function __toString(): string + public function __toString() : string { return $this->startingLine - . ($this->lineCount !== null ? ' ' . $this->lineCount : '') - . ($this->description ? ' ' . $this->description->render() : ''); + . ($this->lineCount !== null ? ' ' . $this->lineCount : '') + . ($this->description ? ' ' . $this->description->render() : ''); } } diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 3e35708..7ac2b42 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,12 +19,14 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_split; /** * Reflection class for a {@}throws tag in a Docblock. */ final class Throws extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'throws'; /** @var Type */ @@ -32,7 +34,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod public function __construct(Type $type, ?Description $description = null) { - $this->type = $type; + $this->type = $type; $this->description = $description; } @@ -44,12 +46,12 @@ final class Throws extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::allNotNull([$typeResolver, $descriptionFactory]); $parts = preg_split('/\s+/Su', $body, 2); - $type = $typeResolver->resolve($parts[0] ?? '', $context); + $type = $typeResolver->resolve($parts[0] ?? '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context); return new static($type, $description); @@ -58,12 +60,12 @@ final class Throws extends BaseTag implements Factory\StaticMethod /** * Returns the type section of the variable. */ - public function getType(): Type + public function getType() : Type { return $this->type; } - public function __toString(): string + public function __toString() : string { return $this->type . ' ' . $this->description; } diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index 50fb36d..24c74dc 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -19,12 +19,14 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_split; /** * Reflection class for a {@}uses tag in a Docblock. */ final class Uses extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'uses'; /** @var Fqsen */ @@ -35,7 +37,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod */ public function __construct(Fqsen $refers, ?Description $description = null) { - $this->refers = $refers; + $this->refers = $refers; $this->description = $description; } @@ -47,7 +49,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod ?FqsenResolver $resolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::allNotNull([$resolver, $descriptionFactory]); $parts = preg_split('/\s+/Su', $body, 2); @@ -61,7 +63,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod /** * Returns the structural element this tag refers to. */ - public function getReference(): Fqsen + public function getReference() : Fqsen { return $this->refers; } @@ -69,7 +71,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod /** * Returns a string representation of this tag. */ - public function __toString(): string + 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 eb7d41c..e39d4e0 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,6 +19,12 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use const PREG_SPLIT_DELIM_CAPTURE; +use function array_shift; +use function implode; +use function preg_split; +use function strlen; +use function substr; /** * Reflection class for a {@}var tag in a Docblock. @@ -37,8 +43,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; - $this->type = $type; - $this->description = $description; + $this->type = $type; + $this->description = $description; } /** @@ -49,12 +55,12 @@ class Var_ extends BaseTag implements Factory\StaticMethod ?TypeResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): self { + ) : self { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); - $type = null; + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type @@ -81,7 +87,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName(): string + public function getVariableName() : string { return $this->variableName; } @@ -89,7 +95,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod /** * Returns the variable's type or null if unknown. */ - public function getType(): ?Type + public function getType() : ?Type { return $this->type; } @@ -97,7 +103,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + 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 1710adf..5a50283 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -1,14 +1,14 @@ - - * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; @@ -17,12 +17,14 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Types\Context as TypeContext; use Webmozart\Assert\Assert; +use function preg_match; /** * Reflection class for a {@}version tag in a Docblock. */ final class Version extends BaseTag implements Factory\StaticMethod { + /** @var string */ protected $name = 'version'; /** @@ -44,11 +46,11 @@ final class Version extends BaseTag implements Factory\StaticMethod /** @var string The version vector. */ private $version = ''; - public function __construct($version = null, ?Description $description = null) + public function __construct(?string $version = null, ?Description $description = null) { Assert::nullOrStringNotEmpty($version); - $this->version = $version; + $this->version = $version; $this->description = $description; } @@ -56,7 +58,7 @@ final class Version extends BaseTag implements Factory\StaticMethod ?string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null - ): ?self { + ) : ?self { if (empty($body)) { return new static(); } @@ -75,7 +77,7 @@ final class Version extends BaseTag implements Factory\StaticMethod /** * Gets the version section of the tag. */ - public function getVersion(): ?string + public function getVersion() : ?string { return $this->version; } @@ -83,7 +85,7 @@ final class Version extends BaseTag implements Factory\StaticMethod /** * Returns a string representation for this tag. */ - public function __toString(): string + public function __toString() : string { return $this->version . ($this->description ? ' ' . $this->description->render() : ''); } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 4383bc5..d046a65 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection; +use InvalidArgumentException; +use LogicException; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\TagFactory; use Webmozart\Assert\Assert; +use function array_filter; +use function array_shift; +use function count; +use function explode; +use function is_object; +use function method_exists; +use function preg_match; +use function preg_replace; +use function str_replace; +use function strpos; +use function substr; +use function trim; final class DocBlockFactory implements DocBlockFactoryInterface { @@ -33,7 +47,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory) { $this->descriptionFactory = $descriptionFactory; - $this->tagFactory = $tagFactory; + $this->tagFactory = $tagFactory; } /** @@ -41,10 +55,10 @@ final class DocBlockFactory implements DocBlockFactoryInterface * * @param string[] $additionalTags */ - public static function createInstance(array $additionalTags = []): self + public static function createInstance(array $additionalTags = []) : self { - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); $descriptionFactory = new DescriptionFactory($tagFactory); $tagFactory->addService($descriptionFactory); @@ -62,12 +76,12 @@ final class DocBlockFactory implements DocBlockFactoryInterface * @param object|string $docblock A string containing the DocBlock to parse or an object supporting the * getDocComment method (such as a ReflectionClass object). */ - public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock + public function create($docblock, ?Types\Context $context = null, ?Location $location = null) : DocBlock { if (is_object($docblock)) { if (!method_exists($docblock, 'getDocComment')) { $exceptionMessage = 'Invalid object passed; the given object must support the getDocComment method'; - throw new \InvalidArgumentException($exceptionMessage); + throw new InvalidArgumentException($exceptionMessage); } $docblock = $docblock->getDocComment(); @@ -80,14 +94,18 @@ final class DocBlockFactory implements DocBlockFactoryInterface } $parts = $this->splitDocBlock($this->stripDocComment($docblock)); + [$templateMarker, $summary, $description, $tags] = $parts; return new DocBlock( $summary, $description ? $this->descriptionFactory->create($description, $context) : null, - array_filter($this->parseTagBlock($tags, $context), function ($tag) { - return $tag instanceof Tag; - }), + array_filter( + $this->parseTagBlock($tags, $context), + static function ($tag) { + return $tag instanceof Tag; + } + ), $context, $location, $templateMarker === '#@+', @@ -95,7 +113,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface ); } - public function registerTagHandler($tagName, $handler): void + public function registerTagHandler(string $tagName, string $handler) : void { $this->tagFactory->registerTagHandler($tagName, $handler); } @@ -105,9 +123,11 @@ final class DocBlockFactory implements DocBlockFactoryInterface * * @param string $comment String containing the comment text. */ - private function stripDocComment(string $comment): string + private function stripDocComment(string $comment) : string { - $comment = trim(preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment)); + /** @var string $comment */ + $comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment); + $comment = trim($comment); // reg ex above is not able to remove */ from a single line docblock if (substr($comment, -2) === '*/') { @@ -117,17 +137,19 @@ final class DocBlockFactory implements DocBlockFactoryInterface return str_replace(["\r\n", "\r"], "\n", $comment); } + // phpcs:disable SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden /** * Splits the DocBlock into a template marker, summary, description and block of tags. * * @param string $comment Comment to split into the sub-parts. * - * @author Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split. + * @return string[] containing the template marker (if any), summary, description and a string containing the tags. + * * @author Mike van Riel for extending the regex with template marker support. * - * @return string[] containing the template marker (if any), summary, description and a string containing the tags. + * @author Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split. */ - private function splitDocBlock(string $comment): array + 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 @@ -137,6 +159,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface } // clears all extra horizontal whitespace from the line endings to prevent parsing issues + /** @var string $comment */ $comment = preg_replace('/\h*$/Sum', '', $comment); /* @@ -204,15 +227,15 @@ final class DocBlockFactory implements DocBlockFactoryInterface /** * Creates the tag objects. * - * @param string $tags Tag block to parse. + * @param string $tags Tag block to parse. * @param Types\Context $context Context of the parsed Tag * * @return DocBlock\Tag[]|string[]|null[] */ - private function parseTagBlock(string $tags, Types\Context $context): array + private function parseTagBlock(string $tags, Types\Context $context) : array { $tags = $this->filterTagBlock($tags); - if (!$tags) { + if ($tags === null) { return []; } @@ -227,7 +250,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface /** * @return string[] */ - private function splitTagBlockIntoTagLines(string $tags): array + private function splitTagBlockIntoTagLines(string $tags) : array { $result = []; foreach (explode("\n", $tags) as $tag_line) { @@ -241,18 +264,18 @@ final class DocBlockFactory implements DocBlockFactoryInterface return $result; } - private function filterTagBlock($tags): ?string + private function filterTagBlock(string $tags) : ?string { $tags = trim($tags); if (!$tags) { return null; } - if ('@' !== $tags[0]) { + if ($tags[0] !== '@') { // @codeCoverageIgnoreStart // Can't simulate this; this only happens if there is an error with the parsing of the DocBlock that // we didn't foresee. - throw new \LogicException('A tag block started with text instead of an at-sign(@): ' . $tags); + throw new LogicException('A tag block started with text instead of an at-sign(@): ' . $tags); // @codeCoverageIgnoreEnd } diff --git a/src/DocBlockFactoryInterface.php b/src/DocBlockFactoryInterface.php index 4f665dd..c161956 100644 --- a/src/DocBlockFactoryInterface.php +++ b/src/DocBlockFactoryInterface.php @@ -1,7 +1,10 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index ffec7ad..7ef37ba 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ diff --git a/tests/integration/ReconstitutingADocBlockTest.php b/tests/integration/ReconstitutingADocBlockTest.php index c8eda66..02da4de 100644 --- a/tests/integration/ReconstitutingADocBlockTest.php +++ b/tests/integration/ReconstitutingADocBlockTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ diff --git a/tests/integration/UsingTagsTest.php b/tests/integration/UsingTagsTest.php index eb5d429..eb463d8 100644 --- a/tests/integration/UsingTagsTest.php +++ b/tests/integration/UsingTagsTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ diff --git a/tests/unit/DocBlock/DescriptionFactoryTest.php b/tests/unit/DocBlock/DescriptionFactoryTest.php index 0f8376f..e10978e 100644 --- a/tests/unit/DocBlock/DescriptionFactoryTest.php +++ b/tests/unit/DocBlock/DescriptionFactoryTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; use Mockery as m; -use phpDocumentor\Reflection\DocBlock\Tags\Link; +use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag; use phpDocumentor\Reflection\Types\Context; use PHPUnit\Framework\TestCase; @@ -27,103 +27,108 @@ class DescriptionFactoryTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description * @dataProvider provideSimpleExampleDescriptions */ - public function testDescriptionCanParseASimpleString($contents): void + public function testDescriptionCanParseASimpleString(string $contents) : void { $tagFactory = m::mock(TagFactory::class); $tagFactory->shouldReceive('create')->never(); - $factory = new DescriptionFactory($tagFactory); + $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, new Context('')); $this->assertSame($contents, $description->render()); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description * @dataProvider provideEscapeSequences */ - public function testEscapeSequences($contents, $expected): void + public function testEscapeSequences(string $contents, string $expected) : void { $tagFactory = m::mock(TagFactory::class); $tagFactory->shouldReceive('create')->never(); - $factory = new DescriptionFactory($tagFactory); + $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, new Context('')); $this->assertSame($expected, $description->render()); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\Types\Context + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Link - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\Types\Context */ - public function testDescriptionCanParseAStringWithInlineTag(): void + public function testDescriptionCanParseAStringWithInlineTag() : void { - $contents = 'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.'; - $context = new Context(''); + $contents = 'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.'; + $context = new Context(''); $tagFactory = m::mock(TagFactory::class); $tagFactory->shouldReceive('create') ->once() ->with('@link http://phpdoc.org/ description', $context) - ->andReturn(new Link('http://phpdoc.org/', new Description('description'))); + ->andReturn(new LinkTag('http://phpdoc.org/', new Description('description'))); - $factory = new DescriptionFactory($tagFactory); + $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, $context); $this->assertSame($contents, $description->render()); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\Types\Context + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Link - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\Types\Context */ - public function testDescriptionCanParseAStringStartingWithInlineTag(): void + public function testDescriptionCanParseAStringStartingWithInlineTag() : void { - $contents = '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.'; - $context = new Context(''); + $contents = '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.'; + $context = new Context(''); $tagFactory = m::mock(TagFactory::class); $tagFactory->shouldReceive('create') ->once() ->with('@link http://phpdoc.org/ This', $context) - ->andReturn(new Link('http://phpdoc.org/', new Description('This'))); + ->andReturn(new LinkTag('http://phpdoc.org/', new Description('This'))); - $factory = new DescriptionFactory($tagFactory); + $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, $context); $this->assertSame($contents, $description->render()); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testIfSuperfluousStartingSpacesAreRemoved(): void + public function testIfSuperfluousStartingSpacesAreRemoved() : void { - $factory = new DescriptionFactory(m::mock(TagFactory::class)); + $factory = new DescriptionFactory(m::mock(TagFactory::class)); $descriptionText = << - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -26,23 +26,24 @@ class DescriptionTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** - * @covers ::__construct - * @covers ::render * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers ::__construct + * @covers ::render */ - public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags(): void + public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() : void { - $body = 'This is a %1$s body.'; + $body = 'This is a %1$s body.'; $expected = 'This is a {@internal significant} body.'; - $tags = [new Generic('internal', new Description('significant '))]; + $tags = [new Generic('internal', new Description('significant '))]; $fixture = new Description($body, $tags); @@ -56,18 +57,19 @@ class DescriptionTest extends TestCase } /** - * @covers ::__construct - * @covers ::render - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers ::__construct + * @covers ::render + * @covers ::__toString */ - public function testDescriptionCanBeCastToString(): void + public function testDescriptionCanBeCastToString() : void { - $body = 'This is a %1$s body.'; + $body = 'This is a %1$s body.'; $expected = 'This is a {@internal significant} body.'; - $tags = [new Generic('internal', new Description('significant '))]; + $tags = [new Generic('internal', new Description('significant '))]; $fixture = new Description($body, $tags); @@ -75,11 +77,12 @@ class DescriptionTest extends TestCase } /** - * @covers ::getTags * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * + * @covers ::getTags */ - public function testDescriptionTagsGetter(): void + public function testDescriptionTagsGetter() : void { $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; @@ -102,14 +105,15 @@ class DescriptionTest extends TestCase } /** - * @covers ::__construct - * @covers ::render - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers ::__construct + * @covers ::render + * @covers ::__toString */ - public function testDescriptionMultipleTagsCanBeCastToString(): void + public function testDescriptionMultipleTagsCanBeCastToString() : void { $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; @@ -121,8 +125,9 @@ class DescriptionTest extends TestCase $tag2, ]; - $fixture = new Description($body, $tags); - $expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; + $fixture = new Description($body, $tags); + $expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, ' + . 'inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; $this->assertSame($expected, (string) $fixture); } } diff --git a/tests/unit/DocBlock/ExampleFinderTest.php b/tests/unit/DocBlock/ExampleFinderTest.php index 01a8a8c..19a32f1 100644 --- a/tests/unit/DocBlock/ExampleFinderTest.php +++ b/tests/unit/DocBlock/ExampleFinderTest.php @@ -1,4 +1,6 @@ - */ class ExampleFinderTest extends TestCase @@ -18,23 +20,24 @@ class ExampleFinderTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } - public function setUp(): void + public function setUp() : void { $this->fixture = new ExampleFinder(); } /** - * @covers ::find - * @covers ::getSourceDirectory * @uses \phpDocumentor\Reflection\DocBlock\Tags\Example * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::find + * @covers ::getSourceDirectory */ - public function testFileNotFound(): void + public function testFileNotFound() : void { $example = new Example('./example.php', false, 1, 0, new Description('Test')); $this->assertSame('** File not found : ./example.php **', $this->fixture->find($example)); diff --git a/tests/unit/DocBlock/SerializerTest.php b/tests/unit/DocBlock/SerializerTest.php index adfd8f9..967dace 100644 --- a/tests/unit/DocBlock/SerializerTest.php +++ b/tests/unit/DocBlock/SerializerTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -26,21 +26,22 @@ class SerializerTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * * @covers ::__construct * @covers ::getDocComment - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\DocBlock - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic */ - public function testReconstructsADocCommentFromADocBlock(): void + public function testReconstructsADocCommentFromADocBlock() : void { $expected = <<<'DOCCOMMENT' /** @@ -66,15 +67,16 @@ DOCCOMMENT; } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * * @covers ::__construct * @covers ::getDocComment - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\DocBlock - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic */ - public function testAddPrefixToDocBlock(): void + public function testAddPrefixToDocBlock() : void { $expected = <<<'DOCCOMMENT' aa/** @@ -100,15 +102,16 @@ DOCCOMMENT; } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * * @covers ::__construct * @covers ::getDocComment - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\DocBlock - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic */ - public function testAddPrefixToDocBlockExceptFirstLine(): void + public function testAddPrefixToDocBlockExceptFirstLine() : void { $expected = <<<'DOCCOMMENT' /** @@ -134,15 +137,16 @@ DOCCOMMENT; } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * * @covers ::__construct * @covers ::getDocComment - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * @uses phpDocumentor\Reflection\DocBlock - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic */ - public function testWordwrapsAroundTheGivenAmountOfCharacters(): void + public function testWordwrapsAroundTheGivenAmountOfCharacters() : void { $expected = <<<'DOCCOMMENT' /** @@ -177,7 +181,7 @@ DOCCOMMENT; * @covers ::__construct * @covers ::getDocComment */ - public function testNoExtraSpacesAfterTagRemoval() + public function testNoExtraSpacesAfterTagRemoval() : void { $expected = <<<'DOCCOMMENT' /** @@ -190,7 +194,7 @@ DOCCOMMENT; */ DOCCOMMENT_AFTER_REMOVE; - $fixture = new Serializer(0, '', true, 15); + $fixture = new Serializer(0, '', true, 15); $genericTag = new DocBlock\Tags\Generic('unknown-tag'); $docBlock = new DocBlock('', null, [$genericTag]); diff --git a/tests/unit/DocBlock/StandardTagFactoryTest.php b/tests/unit/DocBlock/StandardTagFactoryTest.php index e6647c7..5e4ee4c 100644 --- a/tests/unit/DocBlock/StandardTagFactoryTest.php +++ b/tests/unit/DocBlock/StandardTagFactoryTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; @@ -27,7 +27,7 @@ use phpDocumentor\Reflection\Types\Context; use PHPUnit\Framework\TestCase; /** - * @coversDefaultClass phpDocumentor\Reflection\DocBlock\StandardTagFactory + * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\StandardTagFactory * @covers :: */ class StandardTagFactoryTest extends TestCase @@ -35,25 +35,26 @@ class StandardTagFactoryTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService - * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testCreatingAGenericTag(): void + public function testCreatingAGenericTag() : void { - $expectedTagName = 'unknown-tag'; + $expectedTagName = 'unknown-tag'; $expectedDescriptionText = 'This is a description'; - $expectedDescription = new Description($expectedDescriptionText); - $context = new Context(''); + $expectedDescription = new Description($expectedDescriptionText); + $context = new Context(''); $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory @@ -74,15 +75,16 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService - * @uses phpDocumentor\Reflection\DocBlock\Tags\Author - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testCreatingASpecificTag(): void + public function testCreatingASpecificTag() : void { - $context = new Context(''); + $context = new Context(''); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class)); /** @var Author $tag */ @@ -93,18 +95,19 @@ class StandardTagFactoryTest extends TestCase } /** - * @covers ::__construct - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService * @uses \phpDocumentor\Reflection\DocBlock\Tags\See * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen + * + * @covers ::__construct + * @covers ::create */ - public function testAnEmptyContextIsCreatedIfNoneIsProvided(): void + public function testAnEmptyContextIsCreatedIfNoneIsProvided() : void { - $fqsen = '\Tag'; - $resolver = m::mock(FqsenResolver::class) + $fqsen = '\Tag'; + $resolver = m::mock(FqsenResolver::class) ->shouldReceive('resolve') ->with('Tag', m::type(Context::class)) ->andReturn(new Fqsen($fqsen)) @@ -123,15 +126,16 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService - * @uses phpDocumentor\Reflection\DocBlock\Tags\Author - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testPassingYourOwnSetOfTagHandlers(): void + public function testPassingYourOwnSetOfTagHandlers() : void { - $context = new Context(''); + $context = new Context(''); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class), ['user' => Author::class]); /** @var Author $tag */ @@ -142,26 +146,30 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testExceptionIsThrownIfProvidedTagIsNotWellformed(): void + public function testExceptionIsThrownIfProvidedTagIsNotWellformed() : void { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage('The tag "@user[myuser" does not seem to be wellformed, please check it for errors'); + $this->expectExceptionMessage( + 'The tag "@user[myuser" does not seem to be wellformed, please check it for errors' + ); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class)); $tagFactory->create('@user[myuser'); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::__construct * @covers ::addParameter - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testAddParameterToServiceLocator(): void + public function testAddParameterToServiceLocator() : void { - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->addParameter('myParam', 'myValue'); @@ -173,14 +181,15 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * * @covers ::addService - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct */ - public function testAddServiceToServiceLocator(): void + public function testAddServiceToServiceLocator() : void { $service = new PassthroughFormatter(); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->addService($service); @@ -192,15 +201,16 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * * @covers ::addService - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct */ - public function testInjectConcreteServiceForInterfaceToServiceLocator(): void + public function testInjectConcreteServiceForInterfaceToServiceLocator() : void { $interfaceName = Formatter::class; - $service = new PassthroughFormatter(); + $service = new PassthroughFormatter(); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->addService($service, $interfaceName); @@ -212,15 +222,16 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::create + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author + * * @covers ::registerTagHandler - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::create - * @uses phpDocumentor\Reflection\DocBlock\Tags\Author */ - public function testRegisteringAHandlerForANewTag(): void + public function testRegisteringAHandlerForANewTag() : void { - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->registerTagHandler('my-tag', Author::class); @@ -231,66 +242,72 @@ class StandardTagFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::registerTagHandler - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testHandlerRegistrationFailsIfProvidedTagNameIsNamespaceButNotFullyQualified(): void + public function testHandlerRegistrationFailsIfProvidedTagNameIsNamespaceButNotFullyQualified() : void { $this->expectException('InvalidArgumentException'); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); + // phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName $tagFactory->registerTagHandler(\Name\Spaced\Tag::class, Author::class); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::registerTagHandler - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testHandlerRegistrationFailsIfProvidedHandlerIsEmpty(): void + public function testHandlerRegistrationFailsIfProvidedHandlerIsEmpty() : void { $this->expectException('InvalidArgumentException'); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->registerTagHandler('my-tag', ''); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::registerTagHandler - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testHandlerRegistrationFailsIfProvidedHandlerIsNotAnExistingClassName(): void + public function testHandlerRegistrationFailsIfProvidedHandlerIsNotAnExistingClassName() : void { $this->expectException('InvalidArgumentException'); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->registerTagHandler('my-tag', 'IDoNotExist'); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * * @covers ::registerTagHandler - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService */ - public function testHandlerRegistrationFailsIfProvidedHandlerDoesNotImplementTheTagInterface(): void + public function testHandlerRegistrationFailsIfProvidedHandlerDoesNotImplementTheTagInterface() : void { $this->expectException('InvalidArgumentException'); - $resolver = m::mock(FqsenResolver::class); + $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->registerTagHandler('my-tag', 'stdClass'); } /** + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct + * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService + * @uses \phpDocumentor\Reflection\Docblock\Description + * @uses \phpDocumentor\Reflection\Docblock\Tags\Return_ + * @uses \phpDocumentor\Reflection\Docblock\Tags\BaseTag + * * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct - * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService - * @uses phpDocumentor\Reflection\Docblock\Description - * @uses phpDocumentor\Reflection\Docblock\Tags\Return_ - * @uses phpDocumentor\Reflection\Docblock\Tags\BaseTag */ - public function testReturntagIsMappedCorrectly(): void + public function testReturnTagIsMappedCorrectly() : void { $context = new Context(''); diff --git a/tests/unit/DocBlock/Tags/AuthorTest.php b/tests/unit/DocBlock/Tags/AuthorTest.php index 088c236..59e4cda 100644 --- a/tests/unit/DocBlock/Tags/AuthorTest.php +++ b/tests/unit/DocBlock/Tags/AuthorTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -25,16 +25,17 @@ class AuthorTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Author('Mike van Riel', 'mike@phpdoc.org'); @@ -45,10 +46,11 @@ class AuthorTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::__construct * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Author('Mike van Riel', 'mike@phpdoc.org'); @@ -57,9 +59,10 @@ class AuthorTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Author('Mike van Riel', 'mike@phpdoc.org'); @@ -73,7 +76,7 @@ class AuthorTest extends TestCase * @covers ::__construct * @covers ::getAuthorName */ - public function testHasTheAuthorName(): void + public function testHasTheAuthorName() : void { $expected = 'Mike van Riel'; @@ -86,7 +89,7 @@ class AuthorTest extends TestCase * @covers ::__construct * @covers ::getEmail */ - public function testHasTheAuthorMailAddress(): void + public function testHasTheAuthorMailAddress() : void { $expected = 'mike@phpdoc.org'; @@ -98,7 +101,7 @@ class AuthorTest extends TestCase /** * @covers ::__construct */ - public function testInitializationFailsIfEmailIsNotValid(): void + public function testInitializationFailsIfEmailIsNotValid() : void { $this->expectException('InvalidArgumentException'); new Author('Mike van Riel', 'mike'); @@ -108,7 +111,7 @@ class AuthorTest extends TestCase * @covers ::__construct * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Author('Mike van Riel', 'mike@phpdoc.org'); @@ -119,7 +122,7 @@ class AuthorTest extends TestCase * @covers ::__construct * @covers ::__toString */ - public function testStringRepresentationWithEmtpyEmail(): void + public function testStringRepresentationWithEmtpyEmail() : void { $fixture = new Author('Mike van Riel', ''); @@ -127,10 +130,11 @@ class AuthorTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author:: + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $fixture = Author::create('Mike van Riel '); @@ -140,10 +144,11 @@ class AuthorTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Author:: + * + * @covers ::create */ - public function testFactoryMethodReturnsNullIfItCouldNotReadBody(): void + public function testFactoryMethodReturnsNullIfItCouldNotReadBody() : void { $this->assertNull(Author::create('dfgr<')); } diff --git a/tests/unit/DocBlock/Tags/CoversTest.php b/tests/unit/DocBlock/Tags/CoversTest.php index 56c2657..f4319a9 100644 --- a/tests/unit/DocBlock/Tags/CoversTest.php +++ b/tests/unit/DocBlock/Tags/CoversTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class CoversTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class CoversTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Covers::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description')); @@ -52,10 +53,11 @@ class CoversTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Covers::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description')); @@ -65,9 +67,10 @@ class CoversTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Covers::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description')); @@ -81,7 +84,7 @@ class CoversTest extends TestCase * @covers ::__construct * @covers ::getReference */ - public function testHasReferenceToFqsen(): void + public function testHasReferenceToFqsen() : void { $expected = new Fqsen('\DateTime'); @@ -91,11 +94,12 @@ class CoversTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -105,11 +109,12 @@ class CoversTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description')); @@ -117,21 +122,22 @@ class CoversTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Covers:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\FqsenResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = m::mock(FqsenResolver::class); - $context = new Context(''); + $resolver = m::mock(FqsenResolver::class); + $context = new Context(''); - $fqsen = new Fqsen('\DateTime'); + $fqsen = new Fqsen('\DateTime'); $description = new Description('My Description'); $descriptionFactory @@ -148,7 +154,7 @@ class CoversTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void + public function testFactoryMethodFailsIfBodyIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(Covers::create('')); diff --git a/tests/unit/DocBlock/Tags/DeprecatedTest.php b/tests/unit/DocBlock/Tags/DeprecatedTest.php index 95607c9..9df9a7f 100644 --- a/tests/unit/DocBlock/Tags/DeprecatedTest.php +++ b/tests/unit/DocBlock/Tags/DeprecatedTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -28,7 +28,7 @@ class DeprecatedTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class DeprecatedTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Deprecated('1.0', new Description('Description')); @@ -50,10 +51,11 @@ class DeprecatedTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Deprecated('1.0', new Description('Description')); @@ -63,9 +65,10 @@ class DeprecatedTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Deprecated('1.0', new Description('Description')); @@ -79,7 +82,7 @@ class DeprecatedTest extends TestCase * @covers ::__construct * @covers ::getVersion */ - public function testHasVersionNumber(): void + public function testHasVersionNumber() : void { $expected = '1.0'; @@ -89,11 +92,12 @@ class DeprecatedTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -103,11 +107,12 @@ class DeprecatedTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Deprecated('1.0', new Description('Description')); @@ -115,18 +120,19 @@ class DeprecatedTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); - $version = '1.0'; + $version = '1.0'; $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -139,13 +145,14 @@ class DeprecatedTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethodCreatesEmptyDeprecatedTag(): void + public function testFactoryMethodCreatesEmptyDeprecatedTag() : void { $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->never(); @@ -158,10 +165,11 @@ class DeprecatedTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated::__construct + * + * @covers ::create */ - public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex(): void + public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex() : void { $this->assertEquals(new Deprecated(), Deprecated::create('dkhf<')); } diff --git a/tests/unit/DocBlock/Tags/ExampleTest.php b/tests/unit/DocBlock/Tags/ExampleTest.php index ab9a333..77809d4 100644 --- a/tests/unit/DocBlock/Tags/ExampleTest.php +++ b/tests/unit/DocBlock/Tags/ExampleTest.php @@ -1,4 +1,6 @@ -assertEquals('"example1.php"', $tag->getContent()); @@ -34,13 +37,14 @@ class ExampleTest extends TestCase } /** + * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::create * @covers ::__construct * @covers ::getFilePath * @covers ::getDescription - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testWithDescription(): void + public function testWithDescription() : void { $tag = Example::create('"example1.php" some text'); $this->assertEquals('example1.php', $tag->getFilePath()); @@ -48,13 +52,14 @@ class ExampleTest extends TestCase } /** + * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::create * @covers ::__construct * @covers ::getFilePath * @covers ::getStartingLine - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testStartlineIsParsed(): void + public function testStartlineIsParsed() : void { $tag = Example::create('"example1.php" 10'); $this->assertEquals('example1.php', $tag->getFilePath()); @@ -62,14 +67,15 @@ class ExampleTest extends TestCase } /** + * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::create * @covers ::__construct * @covers ::getFilePath * @covers ::getStartingLine * @covers ::getDescription - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testAllowOmitingLineCount(): void + public function testAllowOmitingLineCount() : void { $tag = Example::create('"example1.php" 10 some text'); $this->assertEquals('example1.php', $tag->getFilePath()); @@ -78,14 +84,15 @@ class ExampleTest extends TestCase } /** + * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::create * @covers ::__construct * @covers ::getFilePath * @covers ::getStartingLine * @covers ::getLineCount - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testLengthIsParsed(): void + public function testLengthIsParsed() : void { $tag = Example::create('"example1.php" 10 5'); $this->assertEquals('example1.php', $tag->getFilePath()); @@ -94,15 +101,16 @@ class ExampleTest extends TestCase } /** + * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * * @covers ::create * @covers ::__construct * @covers ::getFilePath * @covers ::getStartingLine * @covers ::getLineCount * @covers ::getDescription - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag */ - public function testFullExample(): void + public function testFullExample() : void { $tag = Example::create('"example1.php" 10 5 test text'); $this->assertEquals('example1.php', $tag->getFilePath()); diff --git a/tests/unit/DocBlock/Tags/Formatter/AlignFormatterTest.php b/tests/unit/DocBlock/Tags/Formatter/AlignFormatterTest.php index 481e799..ce0c286 100644 --- a/tests/unit/DocBlock/Tags/Formatter/AlignFormatterTest.php +++ b/tests/unit/DocBlock/Tags/Formatter/AlignFormatterTest.php @@ -1,4 +1,6 @@ - - * @copyright 2018 Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\Tags\Link; +use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag; use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\DocBlock\Tags\Version; use phpDocumentor\Reflection\Types\String_; @@ -30,27 +29,28 @@ class AlignFormatterTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version + * @uses \phpDocumentor\Reflection\Types\String_ + * * @covers ::format * @covers \phpDocumentor\Reflection\DocBlock\Tags\Formatter\AlignFormatter::__construct - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version - * @uses \phpDocumentor\Reflection\Types\String_ */ - public function testFormatterCallsToStringAndReturnsAStandardRepresentation(): void + public function testFormatterCallsToStringAndReturnsAStandardRepresentation() : void { - $tags = [ + $tags = [ new Param('foobar', new String_()), new Version('1.2.0'), - new Link('http://www.example.com', new Description('Examples')), + new LinkTag('http://www.example.com', new Description('Examples')), ]; $fixture = new AlignFormatter($tags); diff --git a/tests/unit/DocBlock/Tags/Formatter/PassthroughFormatterTest.php b/tests/unit/DocBlock/Tags/Formatter/PassthroughFormatterTest.php index 6c4a281..8f0f021 100644 --- a/tests/unit/DocBlock/Tags/Formatter/PassthroughFormatterTest.php +++ b/tests/unit/DocBlock/Tags/Formatter/PassthroughFormatterTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; @@ -26,18 +26,19 @@ class PassthroughFormatterTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** - * @covers ::format * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * + * @covers ::format */ - public function testFormatterCallsToStringAndReturnsAStandardRepresentation(): void + public function testFormatterCallsToStringAndReturnsAStandardRepresentation() : void { $expected = '@unknown-tag This is a description'; @@ -50,15 +51,16 @@ class PassthroughFormatterTest extends TestCase } /** - * @covers ::format * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * + * @covers ::format */ - public function testFormatterToStringWitoutDescription(): void + public function testFormatterToStringWitoutDescription() : void { $expected = '@unknown-tag'; - $fixture = new PassthroughFormatter(); + $fixture = new PassthroughFormatter(); $this->assertSame( $expected, diff --git a/tests/unit/DocBlock/Tags/GenericTest.php b/tests/unit/DocBlock/Tags/GenericTest.php index 3605bc4..a3c8248 100644 --- a/tests/unit/DocBlock/Tags/GenericTest.php +++ b/tests/unit/DocBlock/Tags/GenericTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @generic http://phpdoc.org */ @@ -28,7 +28,7 @@ class GenericTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class GenericTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Generic('generic', new Description('Description')); @@ -51,9 +52,10 @@ class GenericTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Generic('generic', new Description('Description')); @@ -63,9 +65,10 @@ class GenericTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Generic('generic', new Description('Description')); @@ -76,11 +79,12 @@ class GenericTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -90,12 +94,13 @@ class GenericTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Generic('generic', new Description('Description')); @@ -103,18 +108,19 @@ class GenericTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); - $generics = 'generic'; + $generics = 'generic'; $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -129,7 +135,7 @@ class GenericTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfNameIsNotEmpty(): void + public function testFactoryMethodFailsIfNameIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); Generic::create('', ''); @@ -139,7 +145,7 @@ class GenericTest extends TestCase * @covers ::create * @covers ::__construct */ - public function testFactoryMethodFailsIfNameContainsIllegalCharacters(): void + public function testFactoryMethodFailsIfNameContainsIllegalCharacters() : void { $this->expectException('InvalidArgumentException'); Generic::create('', 'name/myname'); diff --git a/tests/unit/DocBlock/Tags/LinkTest.php b/tests/unit/DocBlock/Tags/LinkTest.php index 47097d7..00c8fe5 100644 --- a/tests/unit/DocBlock/Tags/LinkTest.php +++ b/tests/unit/DocBlock/Tags/LinkTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -28,7 +28,7 @@ class LinkTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class LinkTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Link('http://this.is.my/link', new Description('Description')); @@ -50,10 +51,11 @@ class LinkTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Link('http://this.is.my/link', new Description('Description')); @@ -63,9 +65,10 @@ class LinkTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Link('http://this.is.my/link', new Description('Description')); @@ -79,7 +82,7 @@ class LinkTest extends TestCase * @covers ::__construct * @covers ::getLink */ - public function testHasLinkUrl(): void + public function testHasLinkUrl() : void { $expected = 'http://this.is.my/link'; @@ -89,11 +92,12 @@ class LinkTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -103,11 +107,12 @@ class LinkTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Link('http://this.is.my/link', new Description('Description')); @@ -115,18 +120,19 @@ class LinkTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); - $links = 'http://this.is.my/link'; + $links = 'http://this.is.my/link'; $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -139,13 +145,14 @@ class LinkTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethodCreatesEmptyLinkTag(): void + public function testFactoryMethodCreatesEmptyLinkTag() : void { $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->never(); diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 880a3cf..f0ef1ff 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -37,16 +37,17 @@ class MethodTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Method('myMethod'); @@ -59,16 +60,24 @@ class MethodTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $arguments = [ ['name' => 'argument1', 'type' => new String_()], ['name' => 'argument2', 'type' => new Object_()], ]; - $fixture = new Method('myMethod', $arguments, new Void_(), true, new Description('My Description')); + + $fixture = new Method( + 'myMethod', + $arguments, + new Void_(), + true, + new Description('My Description') + ); $this->assertSame( '@method static void myMethod(string $argument1, object $argument2) My Description', @@ -79,9 +88,10 @@ class MethodTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Method('myMethod'); @@ -95,7 +105,7 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getMethodName */ - public function testHasMethodName(): void + public function testHasMethodName() : void { $expected = 'myMethod'; @@ -108,7 +118,7 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getArguments */ - public function testHasArguments(): void + public function testHasArguments() : void { $arguments = [ ['name' => 'argument1', 'type' => new String_()], @@ -123,10 +133,10 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getArguments */ - public function testArgumentsMayBePassedAsString(): void + public function testArgumentsMayBePassedAsString() : void { $arguments = ['argument1']; - $expected = [ + $expected = [ ['name' => $arguments[0], 'type' => new Void_()], ]; @@ -139,10 +149,10 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getArguments */ - public function testArgumentTypeCanBeInferredAsVoid(): void + public function testArgumentTypeCanBeInferredAsVoid() : void { $arguments = [['name' => 'argument1']]; - $expected = [ + $expected = [ ['name' => $arguments[0]['name'], 'type' => new Void_()], ]; @@ -152,12 +162,13 @@ class MethodTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::__construct * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::getArguments * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::create */ - public function testRestArgumentIsParsedAsRegularArg(): void + public function testRestArgumentIsParsedAsRegularArg() : void { $expected = [ ['name' => 'arg1', 'type' => new Void_()], @@ -166,9 +177,9 @@ class MethodTest extends TestCase ]; $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); - $description = new Description(''); + $resolver = new TypeResolver(); + $context = new Context(''); + $description = new Description(''); $descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description); $fixture = Method::create( @@ -185,7 +196,7 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getReturnType */ - public function testHasReturnType(): void + public function testHasReturnType() : void { $expected = new String_(); @@ -198,7 +209,7 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::getReturnType */ - public function testReturnTypeCanBeInferredAsVoid(): void + public function testReturnTypeCanBeInferredAsVoid() : void { $fixture = new Method('myMethod', []); @@ -209,23 +220,24 @@ class MethodTest extends TestCase * @covers ::__construct * @covers ::isStatic */ - public function testMethodCanBeStatic(): void + public function testMethodCanBeStatic() : void { $expected = false; - $fixture = new Method('myMethod', [], null, $expected); + $fixture = new Method('myMethod', [], null, $expected); $this->assertSame($expected, $fixture->isStatic()); $expected = true; - $fixture = new Method('myMethod', [], null, $expected); + $fixture = new Method('myMethod', [], null, $expected); $this->assertSame($expected, $fixture->isStatic()); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -235,18 +247,19 @@ class MethodTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::isStatic + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $arguments = [ ['name' => 'argument1', 'type' => new String_()], ['name' => 'argument2', 'type' => new Object_()], ]; - $fixture = new Method('myMethod', $arguments, new Void_(), true, new Description('My Description')); + $fixture = new Method('myMethod', $arguments, new Void_(), true, new Description('My Description')); $this->assertSame( 'static void myMethod(string $argument1, object $argument2) My Description', @@ -255,21 +268,22 @@ class MethodTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); - $description = new Description('My Description'); + $description = new Description('My Description'); $expectedArguments = [ ['name' => 'argument1', 'type' => new String_()], ['name' => 'argument2', 'type' => new Void_()], @@ -292,17 +306,18 @@ class MethodTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testReturnTypeThis(): void + public function testReturnTypeThis() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); $description = new Description(''); @@ -321,52 +336,58 @@ class MethodTest extends TestCase $this->assertInstanceOf(This::class, $fixture->getReturnType()); } - public function collectionReturnTypesProvider() + /** + * @return string[][] + */ + public function collectionReturnTypesProvider() : array { return [ - ['int[]', Array_::class, Integer::class, Compound::class], - ['int[][]', Array_::class, Array_::class, Compound::class], + ['int[]', Array_::class, Integer::class, Compound::class], + ['int[][]', Array_::class, Array_::class, Compound::class], ['Object[]', Array_::class, Object_::class, Compound::class], - ['array[]', Array_::class, Array_::class, Compound::class], + ['array[]', Array_::class, Array_::class, Compound::class], ]; } /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\TypeResolver + * @uses \phpDocumentor\Reflection\Types\Array_ + * @uses \phpDocumentor\Reflection\Types\Compound + * @uses \phpDocumentor\Reflection\Types\Integer + * @uses \phpDocumentor\Reflection\Types\Object_ + * * @dataProvider collectionReturnTypesProvider * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Tags\Method:: - * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses phpDocumentor\Reflection\TypeResolver - * @uses phpDocumentor\Reflection\Types\Array_ - * @uses phpDocumentor\Reflection\Types\Compound - * @uses phpDocumentor\Reflection\Types\Integer - * @uses phpDocumentor\Reflection\Types\Object_ */ public function testCollectionReturnTypes( string $returnType, string $expectedType, ?string $expectedValueType = null, ?string $expectedKeyType = null - ): void { - $resolver = new TypeResolver(); + ) : void { + $resolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->with('', null)->andReturn(new Description('')); - $fixture = Method::create("${returnType} myMethod(\$arg)", $resolver, $descriptionFactory); + $fixture = Method::create("${returnType} myMethod(\$arg)", $resolver, $descriptionFactory); $returnType = $fixture->getReturnType(); $this->assertInstanceOf($expectedType, $returnType); - if ($returnType instanceof Array_) { - $this->assertInstanceOf($expectedValueType, $returnType->getValueType()); - $this->assertInstanceOf($expectedKeyType, $returnType->getKeyType()); + if (!($returnType instanceof Array_)) { + return; } + + $this->assertInstanceOf($expectedValueType, $returnType->getValueType()); + $this->assertInstanceOf($expectedKeyType, $returnType->getKeyType()); } /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsEmpty(): void + public function testFactoryMethodFailsIfBodyIsEmpty() : void { $this->expectException('InvalidArgumentException'); Method::create(''); @@ -375,7 +396,7 @@ class MethodTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodReturnsNullIfBodyIsIncorrect(): void + public function testFactoryMethodReturnsNullIfBodyIsIncorrect() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(Method::create('body(')); @@ -384,7 +405,7 @@ class MethodTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Method::create('body'); @@ -393,7 +414,7 @@ class MethodTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Method::create('body', new TypeResolver()); @@ -402,16 +423,7 @@ class MethodTest extends TestCase /** * @covers ::__construct */ - public function testCreationFailsIfBodyIsNotString(): void - { - $this->expectException('InvalidArgumentException'); - new Method([]); - } - - /** - * @covers ::__construct - */ - public function testCreationFailsIfBodyIsEmpty(): void + public function testCreationFailsIfBodyIsEmpty() : void { $this->expectException('InvalidArgumentException'); new Method(''); @@ -420,35 +432,27 @@ class MethodTest extends TestCase /** * @covers ::__construct */ - public function testCreationFailsIfStaticIsNotBoolean(): void - { - $this->expectException('InvalidArgumentException'); - new Method('body', [], null, []); - } - - /** - * @covers ::__construct - */ - public function testCreationFailsIfArgumentRecordContainsInvalidEntry(): void + public function testCreationFailsIfArgumentRecordContainsInvalidEntry() : void { $this->expectException('InvalidArgumentException'); new Method('body', [['name' => 'myName', 'unknown' => 'nah']]); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testCreateMethodParenthesisMissing(): void + public function testCreateMethodParenthesisMissing() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); $description = new Description('My Description'); @@ -469,7 +473,6 @@ class MethodTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver @@ -477,12 +480,14 @@ class MethodTest extends TestCase * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context * @uses \phpDocumentor\Reflection\Types\Void_ + * + * @covers ::create */ - public function testCreateWithoutReturnType(): void + public function testCreateWithoutReturnType() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); $description = new Description(''); @@ -503,7 +508,6 @@ class MethodTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver @@ -514,12 +518,14 @@ class MethodTest extends TestCase * @uses \phpDocumentor\Reflection\Types\Compound * @uses \phpDocumentor\Reflection\Types\Integer * @uses \phpDocumentor\Reflection\Types\Object_ + * + * @covers ::create */ - public function testCreateWithMixedReturnTypes(): void + public function testCreateWithMixedReturnTypes() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); $descriptionFactory->shouldReceive('create')->andReturn(new Description('')); diff --git a/tests/unit/DocBlock/Tags/ParamTest.php b/tests/unit/DocBlock/Tags/ParamTest.php index 45615c9..9e4513a 100644 --- a/tests/unit/DocBlock/Tags/ParamTest.php +++ b/tests/unit/DocBlock/Tags/ParamTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class ParamTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class ParamTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Param('myParameter', null, false, new Description('Description')); @@ -53,10 +54,11 @@ class ParamTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Param('myParameter', new String_(), true, new Description('Description')); $this->assertSame('@param string ...$myParameter Description', $fixture->render()); @@ -73,9 +75,10 @@ class ParamTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Param('myParameter'); @@ -89,7 +92,7 @@ class ParamTest extends TestCase * @covers ::__construct * @covers ::getVariableName */ - public function testHasVariableName(): void + public function testHasVariableName() : void { $expected = 'myParameter'; @@ -102,7 +105,7 @@ class ParamTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -115,7 +118,7 @@ class ParamTest extends TestCase * @covers ::__construct * @covers ::isVariadic */ - public function testIfParameterIsVariadic(): void + public function testIfParameterIsVariadic() : void { $fixture = new Param('myParameter', new String_(), false); $this->assertFalse($fixture->isVariadic()); @@ -125,11 +128,12 @@ class ParamTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -139,13 +143,14 @@ class ParamTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\String_ + * * @covers ::__construct * @covers ::isVariadic * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\String_ */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Param('myParameter', new String_(), true, new Description('Description')); @@ -153,17 +158,18 @@ class ParamTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { - $typeResolver = new TypeResolver(); + $typeResolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -178,12 +184,13 @@ class ParamTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -193,17 +200,18 @@ class ParamTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Param::create('body'); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Param::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/PropertyReadTest.php b/tests/unit/DocBlock/Tags/PropertyReadTest.php index c69508c..901b090 100644 --- a/tests/unit/DocBlock/Tags/PropertyReadTest.php +++ b/tests/unit/DocBlock/Tags/PropertyReadTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class PropertyReadTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class PropertyReadTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new PropertyRead('myProperty', null, new Description('Description')); @@ -52,10 +53,11 @@ class PropertyReadTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new PropertyRead('myProperty', new String_(), new Description('Description')); $this->assertSame('@property-read string $myProperty Description', $fixture->render()); @@ -69,9 +71,10 @@ class PropertyReadTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new PropertyRead('myProperty'); @@ -85,7 +88,7 @@ class PropertyReadTest extends TestCase * @covers ::__construct * @covers ::getVariableName */ - public function testHasVariableName(): void + public function testHasVariableName() : void { $expected = 'myProperty'; @@ -98,7 +101,7 @@ class PropertyReadTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -108,11 +111,12 @@ class PropertyReadTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -122,12 +126,13 @@ class PropertyReadTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new PropertyRead('myProperty', new String_(), new Description('Description')); @@ -135,17 +140,18 @@ class PropertyReadTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { - $typeResolver = new TypeResolver(); + $typeResolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -164,12 +170,13 @@ class PropertyReadTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -179,17 +186,18 @@ class PropertyReadTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); PropertyRead::create('body'); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); PropertyRead::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/PropertyTest.php b/tests/unit/DocBlock/Tags/PropertyTest.php index f9e34b2..ec0e7fc 100644 --- a/tests/unit/DocBlock/Tags/PropertyTest.php +++ b/tests/unit/DocBlock/Tags/PropertyTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class PropertyTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class PropertyTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Property('myProperty', null, new Description('Description')); @@ -52,10 +53,11 @@ class PropertyTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Property('myProperty', new String_(), new Description('Description')); $this->assertSame('@property string $myProperty Description', $fixture->render()); @@ -69,9 +71,10 @@ class PropertyTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Property('myProperty'); @@ -85,7 +88,7 @@ class PropertyTest extends TestCase * @covers ::__construct * @covers ::getVariableName */ - public function testHasVariableName(): void + public function testHasVariableName() : void { $expected = 'myProperty'; @@ -98,7 +101,7 @@ class PropertyTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -108,11 +111,12 @@ class PropertyTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -122,12 +126,13 @@ class PropertyTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Property('myProperty', new String_(), new Description('Description')); @@ -135,17 +140,18 @@ class PropertyTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { - $typeResolver = new TypeResolver(); + $typeResolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -159,12 +165,13 @@ class PropertyTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -174,17 +181,18 @@ class PropertyTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Property::create('body'); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Property::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/PropertyWriteTest.php b/tests/unit/DocBlock/Tags/PropertyWriteTest.php index 65be7f9..1c6124c 100644 --- a/tests/unit/DocBlock/Tags/PropertyWriteTest.php +++ b/tests/unit/DocBlock/Tags/PropertyWriteTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class PropertyWriteTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class PropertyWriteTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new PropertyWrite('myProperty', null, new Description('Description')); @@ -52,10 +53,11 @@ class PropertyWriteTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new PropertyWrite('myProperty', new String_(), new Description('Description')); $this->assertSame('@property-write string $myProperty Description', $fixture->render()); @@ -69,9 +71,10 @@ class PropertyWriteTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new PropertyWrite('myProperty'); @@ -85,7 +88,7 @@ class PropertyWriteTest extends TestCase * @covers ::__construct * @covers ::getVariableName */ - public function testHasVariableName(): void + public function testHasVariableName() : void { $expected = 'myProperty'; @@ -98,7 +101,7 @@ class PropertyWriteTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -108,11 +111,12 @@ class PropertyWriteTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -122,12 +126,13 @@ class PropertyWriteTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new PropertyWrite('myProperty', new String_(), new Description('Description')); @@ -135,17 +140,18 @@ class PropertyWriteTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { - $typeResolver = new TypeResolver(); + $typeResolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -164,12 +170,13 @@ class PropertyWriteTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -179,17 +186,18 @@ class PropertyWriteTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); PropertyWrite::create('body'); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); PropertyWrite::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/ReturnTest.php b/tests/unit/DocBlock/Tags/ReturnTest.php index dd6c4b9..63ace03 100644 --- a/tests/unit/DocBlock/Tags/ReturnTest.php +++ b/tests/unit/DocBlock/Tags/ReturnTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class ReturnTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class ReturnTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Return_(new String_(), new Description('Description')); @@ -52,10 +53,11 @@ class ReturnTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Return_(new String_(), new Description('Description')); @@ -65,9 +67,10 @@ class ReturnTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Return_(new String_(), new Description('Description')); @@ -81,7 +84,7 @@ class ReturnTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -91,11 +94,12 @@ class ReturnTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -105,11 +109,12 @@ class ReturnTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Return_(new String_(), new Description('Description')); @@ -117,21 +122,22 @@ class ReturnTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); - $type = new String_(); + $type = new String_(); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -145,7 +151,7 @@ class ReturnTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void + public function testFactoryMethodFailsIfBodyIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(Return_::create('')); @@ -154,7 +160,7 @@ class ReturnTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Return_::create('body'); @@ -163,7 +169,7 @@ class ReturnTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Return_::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/SeeTest.php b/tests/unit/DocBlock/Tags/SeeTest.php index b876f69..f9ed04c 100644 --- a/tests/unit/DocBlock/Tags/SeeTest.php +++ b/tests/unit/DocBlock/Tags/SeeTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -32,7 +32,7 @@ class SeeTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -42,9 +42,10 @@ class SeeTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); @@ -57,10 +58,11 @@ class SeeTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); @@ -72,9 +74,10 @@ class SeeTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); @@ -87,10 +90,11 @@ class SeeTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen + * * @covers ::__construct * @covers ::getReference */ - public function testHasReferenceToFqsen(): void + public function testHasReferenceToFqsen() : void { $expected = new FqsenRef(new Fqsen('\DateTime')); @@ -100,13 +104,14 @@ class SeeTest extends TestCase } /** - * @covers ::__construct - * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen + * + * @covers ::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -116,13 +121,14 @@ class SeeTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new See(new FqsenRef(new Fqsen('\DateTime::format()')), new Description('Description')); @@ -130,7 +136,6 @@ class SeeTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\See:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\FqsenResolver @@ -138,14 +143,16 @@ class SeeTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = m::mock(FqsenResolver::class); - $context = new Context(''); + $resolver = m::mock(FqsenResolver::class); + $context = new Context(''); - $fqsen = new Fqsen('\DateTime'); + $fqsen = new Fqsen('\DateTime'); $description = new Description('My Description'); $descriptionFactory @@ -161,19 +168,20 @@ class SeeTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\See:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\FqsenResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethodWithUrl(): void + public function testFactoryMethodWithUrl() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = m::mock(FqsenResolver::class); - $context = new Context(''); + $resolver = m::mock(FqsenResolver::class); + $context = new Context(''); $description = new Description('My Description'); @@ -193,7 +201,7 @@ class SeeTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void + public function testFactoryMethodFailsIfBodyIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(See::create('')); @@ -202,7 +210,7 @@ class SeeTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); See::create('body'); @@ -211,7 +219,7 @@ class SeeTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); See::create('body', new FqsenResolver()); diff --git a/tests/unit/DocBlock/Tags/SinceTest.php b/tests/unit/DocBlock/Tags/SinceTest.php index f55364a..ff926d2 100644 --- a/tests/unit/DocBlock/Tags/SinceTest.php +++ b/tests/unit/DocBlock/Tags/SinceTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -28,7 +28,7 @@ class SinceTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class SinceTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Since('1.0', new Description('Description')); @@ -50,10 +51,11 @@ class SinceTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Since('1.0', new Description('Description')); @@ -63,9 +65,10 @@ class SinceTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Since('1.0', new Description('Description')); @@ -79,7 +82,7 @@ class SinceTest extends TestCase * @covers ::__construct * @covers ::getVersion */ - public function testHasVersionNumber(): void + public function testHasVersionNumber() : void { $expected = '1.0'; @@ -89,11 +92,12 @@ class SinceTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -103,11 +107,12 @@ class SinceTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Since('1.0', new Description('Description')); @@ -115,18 +120,19 @@ class SinceTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); - $version = '1.0'; + $version = '1.0'; $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -139,13 +145,14 @@ class SinceTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethodCreatesEmptySinceTag(): void + public function testFactoryMethodCreatesEmptySinceTag() : void { $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->never(); @@ -160,7 +167,7 @@ class SinceTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex(): void + public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex() : void { $this->assertNull(Since::create('dkhf<')); } diff --git a/tests/unit/DocBlock/Tags/SourceTest.php b/tests/unit/DocBlock/Tags/SourceTest.php index e1742ed..178d16e 100644 --- a/tests/unit/DocBlock/Tags/SourceTest.php +++ b/tests/unit/DocBlock/Tags/SourceTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -28,7 +28,7 @@ class SourceTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class SourceTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Source(1, null, new Description('Description')); @@ -50,10 +51,11 @@ class SourceTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Source(1, 10, new Description('Description')); $this->assertSame('@source 1 10 Description', $fixture->render()); @@ -67,9 +69,10 @@ class SourceTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Source(1); @@ -83,7 +86,7 @@ class SourceTest extends TestCase * @covers ::__construct * @covers ::getStartingLine */ - public function testHasStartingLine(): void + public function testHasStartingLine() : void { $expected = 1; @@ -96,7 +99,7 @@ class SourceTest extends TestCase * @covers ::__construct * @covers ::getLineCount */ - public function testHasLineCount(): void + public function testHasLineCount() : void { $expected = 2; @@ -106,11 +109,12 @@ class SourceTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -120,12 +124,13 @@ class SourceTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Source(1, 10, new Description('Description')); @@ -133,16 +138,17 @@ class SourceTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -156,12 +162,13 @@ class SourceTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -169,10 +176,11 @@ class SourceTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Source::create('1'); @@ -181,7 +189,7 @@ class SourceTest extends TestCase /** * @covers ::__construct */ - public function testExceptionIsThrownIfStartingLineIsNotInteger(): void + public function testExceptionIsThrownIfStartingLineIsNotInteger() : void { $this->expectException('InvalidArgumentException'); new Source('blabla'); @@ -190,7 +198,7 @@ class SourceTest extends TestCase /** * @covers ::__construct */ - public function testExceptionIsThrownIfLineCountIsNotIntegerOrNull(): void + public function testExceptionIsThrownIfLineCountIsNotIntegerOrNull() : void { $this->expectException('InvalidArgumentException'); new Source('1', []); diff --git a/tests/unit/DocBlock/Tags/ThrowsTest.php b/tests/unit/DocBlock/Tags/ThrowsTest.php index 3338127..b4dec5e 100644 --- a/tests/unit/DocBlock/Tags/ThrowsTest.php +++ b/tests/unit/DocBlock/Tags/ThrowsTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class ThrowsTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class ThrowsTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Throws(new String_(), new Description('Description')); @@ -52,10 +53,11 @@ class ThrowsTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Throws(new String_(), new Description('Description')); @@ -65,9 +67,10 @@ class ThrowsTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Throws(new String_(), new Description('Description')); @@ -81,7 +84,7 @@ class ThrowsTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -91,11 +94,12 @@ class ThrowsTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -105,11 +109,12 @@ class ThrowsTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Throws(new String_(), new Description('Description')); @@ -117,21 +122,22 @@ class ThrowsTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); + $resolver = new TypeResolver(); + $context = new Context(''); - $type = new String_(); + $type = new String_(); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -145,7 +151,7 @@ class ThrowsTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void + public function testFactoryMethodFailsIfBodyIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(Throws::create('')); @@ -154,7 +160,7 @@ class ThrowsTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Throws::create('body'); @@ -163,7 +169,7 @@ class ThrowsTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Throws::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/UsesTest.php b/tests/unit/DocBlock/Tags/UsesTest.php index ee06863..979a675 100644 --- a/tests/unit/DocBlock/Tags/UsesTest.php +++ b/tests/unit/DocBlock/Tags/UsesTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class UsesTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class UsesTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Uses::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Uses(new Fqsen('\DateTime'), new Description('Description')); @@ -52,10 +53,11 @@ class UsesTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Uses::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Uses(new Fqsen('\DateTime'), new Description('Description')); @@ -65,9 +67,10 @@ class UsesTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Uses::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Uses(new Fqsen('\DateTime'), new Description('Description')); @@ -81,7 +84,7 @@ class UsesTest extends TestCase * @covers ::__construct * @covers ::getReference */ - public function testHasReferenceToFqsen(): void + public function testHasReferenceToFqsen() : void { $expected = new Fqsen('\DateTime'); @@ -91,11 +94,12 @@ class UsesTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -105,11 +109,12 @@ class UsesTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Uses(new Fqsen('\DateTime'), new Description('Description')); @@ -117,21 +122,22 @@ class UsesTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Uses:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\FqsenResolver * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Fqsen * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = m::mock(FqsenResolver::class); - $context = new Context(''); + $resolver = m::mock(FqsenResolver::class); + $context = new Context(''); - $fqsen = new Fqsen('\DateTime'); + $fqsen = new Fqsen('\DateTime'); $description = new Description('My Description'); $descriptionFactory @@ -148,7 +154,7 @@ class UsesTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void + public function testFactoryMethodFailsIfBodyIsNotEmpty() : void { $this->expectException('InvalidArgumentException'); $this->assertNull(Uses::create('')); @@ -157,7 +163,7 @@ class UsesTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Uses::create('body'); @@ -166,7 +172,7 @@ class UsesTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Uses::create('body', new FqsenResolver()); diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 627b533..409263e 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -30,7 +30,7 @@ class VarTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -38,9 +38,10 @@ class VarTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Var_('myVariable', null, new Description('Description')); @@ -49,9 +50,10 @@ class VarTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfVariableNameIsOmmitedIfEmpty(): void + public function testIfVariableNameIsOmmitedIfEmpty() : void { $fixture = new Var_('', null, null); @@ -63,10 +65,11 @@ class VarTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Var_('myVariable', new String_(), new Description('Description')); $this->assertSame('@var string $myVariable Description', $fixture->render()); @@ -80,9 +83,10 @@ class VarTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__construct + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Var_('myVariable'); @@ -96,7 +100,7 @@ class VarTest extends TestCase * @covers ::__construct * @covers ::getVariableName */ - public function testHasVariableName(): void + public function testHasVariableName() : void { $expected = 'myVariable'; @@ -109,7 +113,7 @@ class VarTest extends TestCase * @covers ::__construct * @covers ::getType */ - public function testHasType(): void + public function testHasType() : void { $expected = new String_(); @@ -119,11 +123,12 @@ class VarTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -133,12 +138,13 @@ class VarTest extends TestCase } /** - * @covers ::__construct - * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Var_('myVariable', new String_(), new Description('Description')); @@ -146,17 +152,18 @@ class VarTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { - $typeResolver = new TypeResolver(); + $typeResolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -170,12 +177,13 @@ class VarTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: * @uses \phpDocumentor\Reflection\TypeResolver * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::create */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void + public function testFactoryMethodFailsIfEmptyBodyIsGiven() : void { $this->expectException('InvalidArgumentException'); $descriptionFactory = m::mock(DescriptionFactory::class); @@ -185,17 +193,18 @@ class VarTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodFailsIfResolverIsNull(): void + public function testFactoryMethodFailsIfResolverIsNull() : void { $this->expectException('InvalidArgumentException'); Var_::create('body'); } /** - * @covers ::create * @uses \phpDocumentor\Reflection\TypeResolver + * + * @covers ::create */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void + public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void { $this->expectException('InvalidArgumentException'); Var_::create('body', new TypeResolver()); diff --git a/tests/unit/DocBlock/Tags/VersionTest.php b/tests/unit/DocBlock/Tags/VersionTest.php index 1eff1a6..04ce027 100644 --- a/tests/unit/DocBlock/Tags/VersionTest.php +++ b/tests/unit/DocBlock/Tags/VersionTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -28,7 +28,7 @@ class VersionTest extends TestCase /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } @@ -36,9 +36,10 @@ class VersionTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfCorrectTagNameIsReturned(): void + public function testIfCorrectTagNameIsReturned() : void { $fixture = new Version('1.0', new Description('Description')); @@ -50,10 +51,11 @@ class VersionTest extends TestCase * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName */ - public function testIfTagCanBeRenderedUsingDefaultFormatter(): void + public function testIfTagCanBeRenderedUsingDefaultFormatter() : void { $fixture = new Version('1.0', new Description('Description')); @@ -63,9 +65,10 @@ class VersionTest extends TestCase /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version::__construct * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render */ - public function testIfTagCanBeRenderedUsingSpecificFormatter(): void + public function testIfTagCanBeRenderedUsingSpecificFormatter() : void { $fixture = new Version('1.0', new Description('Description')); @@ -79,7 +82,7 @@ class VersionTest extends TestCase * @covers ::__construct * @covers ::getVersion */ - public function testHasVersionNumber(): void + public function testHasVersionNumber() : void { $expected = '1.0'; @@ -89,11 +92,12 @@ class VersionTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testHasDescription(): void + public function testHasDescription() : void { $expected = new Description('Description'); @@ -103,11 +107,12 @@ class VersionTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testStringRepresentationIsReturned(): void + public function testStringRepresentationIsReturned() : void { $fixture = new Version('1.0', new Description('Description')); @@ -115,18 +120,19 @@ class VersionTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethod(): void + public function testFactoryMethod() : void { $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); + $context = new Context(''); - $version = '1.0'; + $version = '1.0'; $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); @@ -139,13 +145,14 @@ class VersionTest extends TestCase } /** - * @covers ::create * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create */ - public function testFactoryMethodCreatesEmptyVersionTag(): void + public function testFactoryMethodCreatesEmptyVersionTag() : void { $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->never(); @@ -160,7 +167,7 @@ class VersionTest extends TestCase /** * @covers ::create */ - public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex(): void + public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex() : void { $this->assertNull(Version::create('dkhf<')); } diff --git a/tests/unit/DocBlockFactoryTest.php b/tests/unit/DocBlockFactoryTest.php index c9662fb..91f06be 100644 --- a/tests/unit/DocBlockFactoryTest.php +++ b/tests/unit/DocBlockFactoryTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -21,30 +21,33 @@ use phpDocumentor\Reflection\DocBlock\TagFactory; use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\Types\Context; use PHPUnit\Framework\TestCase; +use ReflectionClass; /** - * @coversDefaultClass phpDocumentor\Reflection\DocBlockFactory - * @covers :: * @uses \Webmozart\Assert\Assert - * @uses phpDocumentor\Reflection\DocBlock + * @uses \phpDocumentor\Reflection\DocBlock + * + * @coversDefaultClass \phpDocumentor\Reflection\DocBlockFactory + * @covers :: */ class DocBlockFactoryTest extends TestCase { /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** - * @covers ::__construct - * @covers ::createInstance * @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * + * @covers ::__construct + * @covers ::createInstance */ - public function testCreateFactoryUsingFactoryMethod(): void + public function testCreateFactoryUsingFactoryMethod() : void { $fixture = DocBlockFactory::createInstance(); @@ -52,16 +55,17 @@ class DocBlockFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testCreateDocBlockFromReflection(): void + public function testCreateDocBlockFromReflection() : void { $fixture = new DocBlockFactory(m::mock(DescriptionFactory::class), m::mock(TagFactory::class)); - $docBlock = '/** This is a DocBlock */'; - $classReflector = m::mock(\ReflectionClass::class); + $docBlock = '/** This is a DocBlock */'; + $classReflector = m::mock(ReflectionClass::class); $classReflector->shouldReceive('getDocComment')->andReturn($docBlock); $docblock = $fixture->create($classReflector); @@ -74,11 +78,12 @@ class DocBlockFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testCreateDocBlockFromStringWithDocComment(): void + public function testCreateDocBlockFromStringWithDocComment() : void { $fixture = new DocBlockFactory(m::mock(DescriptionFactory::class), m::mock(TagFactory::class)); @@ -93,11 +98,12 @@ class DocBlockFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::create * @covers ::__construct - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testCreateDocBlockFromStringWithoutDocComment(): void + public function testCreateDocBlockFromStringWithoutDocComment() : void { $fixture = new DocBlockFactory(m::mock(DescriptionFactory::class), m::mock(TagFactory::class)); @@ -112,16 +118,18 @@ class DocBlockFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses phpDocumentor\Reflection\DocBlock\Description + * * @dataProvider provideSummaryAndDescriptions */ - public function testSummaryAndDescriptionAreSeparated($given, $summary, $description): void + public function testSummaryAndDescriptionAreSeparated(string $given, string $summary, string $description) : void { $tagFactory = m::mock(TagFactory::class); - $fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory); + $fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory); $docblock = $fixture->create($given); @@ -130,15 +138,16 @@ class DocBlockFactoryTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testDescriptionsRetainFormatting(): void + public function testDescriptionsRetainFormatting() : void { $tagFactory = m::mock(TagFactory::class); - $fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory); + $fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory); $given = << This is with multiline description. TAG; - $tag = m::mock(Tag::class); + $tag = m::mock(Tag::class); $tagFactory = m::mock(TagFactory::class); $tagFactory->shouldReceive('create')->with($tagString, m::type(Context::class))->andReturn($tag); @@ -195,7 +205,10 @@ DOCBLOCK; $this->assertEquals([$tag], $docblock->getTags()); } - public function provideSummaryAndDescriptions() + /** + * @return string[] + */ + public function provideSummaryAndDescriptions() : array { return [ ['This is a DocBlock', 'This is a DocBlock', ''], @@ -208,8 +221,7 @@ DOCBLOCK; <<shouldReceive('create')->with(m::any(), $context)->andReturn(new Param('param')); $docblock = $fixture->create('/** @param MyType $param */', $context); @@ -268,13 +277,13 @@ DOCBLOCK } /** + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::create - * - * @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses phpDocumentor\Reflection\DocBlock\Description */ - public function testTagsAreFilteredForNullValues(): void + public function testTagsAreFilteredForNullValues() : void { $tagString = << This is with diff --git a/tests/unit/DocBlockTest.php b/tests/unit/DocBlockTest.php index d03fb0d..e6cbfe3 100644 --- a/tests/unit/DocBlockTest.php +++ b/tests/unit/DocBlockTest.php @@ -1,4 +1,6 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ @@ -19,27 +19,28 @@ use phpDocumentor\Reflection\Types\Context; use PHPUnit\Framework\TestCase; /** + * @uses \Webmozart\Assert\Assert + * * @coversDefaultClass phpDocumentor\Reflection\DocBlock * @covers :: - * @uses \Webmozart\Assert\Assert */ class DocBlockTest extends TestCase { /** * Call Mockery::close after each test. */ - public function tearDown(): void + public function tearDown() : void { m::close(); } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::getSummary - * - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testDocBlockCanHaveASummary(): void + public function testDocBlockCanHaveASummary() : void { $summary = 'This is a summary'; @@ -49,12 +50,12 @@ class DocBlockTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::getSummary - * - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testDocBlockCanHaveEllipsisInSummary(): void + public function testDocBlockCanHaveEllipsisInSummary() : void { $summary = 'This is a short (...) description.'; @@ -64,12 +65,12 @@ class DocBlockTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::getDescription - * - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testDocBlockCanHaveADescription(): void + public function testDocBlockCanHaveADescription() : void { $description = new DocBlock\Description(''); @@ -79,13 +80,13 @@ class DocBlockTest extends TestCase } /** - * @covers ::__construct - * @covers ::getTags - * * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tag + * + * @covers ::__construct + * @covers ::getTags */ - public function testDocBlockCanHaveTags(): void + public function testDocBlockCanHaveTags() : void { $tags = [ m::mock(DocBlock\Tag::class), @@ -97,29 +98,28 @@ class DocBlockTest extends TestCase } /** - * @covers ::__construct - * @covers ::getTags * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tag + * + * @covers ::__construct + * @covers ::getTags */ - public function testDocBlockAllowsOnlyTags(): void + public function testDocBlockAllowsOnlyTags() : void { $this->expectException('InvalidArgumentException'); - $tags = [ - null, - ]; + $tags = [null]; $fixture = new DocBlock('', null, $tags); } /** - * @covers ::__construct - * @covers ::getTagsByName - * * @uses \phpDocumentor\Reflection\DocBlock::getTags * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tag + * + * @covers ::__construct + * @covers ::getTagsByName */ - public function testFindTagsInDocBlockByName(): void + public function testFindTagsInDocBlockByName() : void { $tag1 = m::mock(DocBlock\Tag::class); $tag2 = m::mock(DocBlock\Tag::class); @@ -137,14 +137,14 @@ class DocBlockTest extends TestCase } /** - * @covers ::__construct - * @covers ::hasTag - * * @uses \phpDocumentor\Reflection\DocBlock::getTags * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\DocBlock\Tag + * + * @covers ::__construct + * @covers ::hasTag */ - public function testCheckIfThereAreTagsWithAGivenName(): void + public function testCheckIfThereAreTagsWithAGivenName() : void { $tag1 = m::mock(DocBlock\Tag::class); $tag2 = m::mock(DocBlock\Tag::class); @@ -162,13 +162,13 @@ class DocBlockTest extends TestCase } /** - * @covers ::__construct - * @covers ::getContext - * * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::__construct + * @covers ::getContext */ - public function testDocBlockKnowsInWhichNamespaceItIsAndWhichAliasesThereAre(): void + public function testDocBlockKnowsInWhichNamespaceItIsAndWhichAliasesThereAre() : void { $context = new Context(''); @@ -178,13 +178,13 @@ class DocBlockTest extends TestCase } /** - * @covers ::__construct - * @covers ::getLocation - * * @uses \phpDocumentor\Reflection\DocBlock\Description * @uses \phpDocumentor\Reflection\Location + * + * @covers ::__construct + * @covers ::getLocation */ - public function testDocBlockKnowsAtWhichLineItIs(): void + public function testDocBlockKnowsAtWhichLineItIs() : void { $location = new Location(10); @@ -194,12 +194,12 @@ class DocBlockTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::isTemplateStart - * - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testDocBlockKnowsIfItIsTheStartOfADocBlockTemplate(): void + public function testDocBlockKnowsIfItIsTheStartOfADocBlockTemplate() : void { $fixture = new DocBlock('', null, [], null, null, true); @@ -207,12 +207,12 @@ class DocBlockTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * * @covers ::__construct * @covers ::isTemplateEnd - * - * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate(): void + public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate() : void { $fixture = new DocBlock('', null, [], null, null, false, true); @@ -220,14 +220,14 @@ class DocBlockTest extends TestCase } /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated + * * @covers ::__construct * @covers ::removeTag - * - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated */ - public function testRemoveTag(): void + public function testRemoveTag() : void { - $someTag = new Deprecated(); + $someTag = new Deprecated(); $anotherTag = new Deprecated(); $fixture = new DocBlock('', null, [$someTag]); From 19a1f3a91fc2895a7540efd3537545bac16800df Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2019 16:52:17 +0200 Subject: [PATCH 02/10] Phpstan to max level --- phpstan.neon | 12 +++--- src/DocBlock/DescriptionFactory.php | 57 ++++++++++++---------------- src/DocBlock/ExampleFinder.php | 7 +++- src/DocBlock/StandardTagFactory.php | 59 +++++++++++++++++++---------- src/DocBlock/Tags/Covers.php | 3 ++ src/DocBlock/Tags/Deprecated.php | 3 +- src/DocBlock/Tags/Generic.php | 2 +- src/DocBlock/Tags/Link.php | 1 + src/DocBlock/Tags/Method.php | 9 +++-- src/DocBlock/Tags/Param.php | 12 +++--- src/DocBlock/Tags/Property.php | 14 ++++--- src/DocBlock/Tags/PropertyRead.php | 10 +++-- src/DocBlock/Tags/PropertyWrite.php | 9 +++-- src/DocBlock/Tags/Return_.php | 4 +- src/DocBlock/Tags/See.php | 8 ++-- src/DocBlock/Tags/Since.php | 3 +- src/DocBlock/Tags/Throws.php | 4 +- src/DocBlock/Tags/Uses.php | 5 ++- src/DocBlock/Tags/Var_.php | 15 +++++--- src/DocBlock/Tags/Version.php | 9 ++++- src/DocBlockFactory.php | 12 ++++-- 21 files changed, 156 insertions(+), 102 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 2beb983..4ebb808 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,10 @@ +includes: + - /composer/vendor/phpstan/phpstan-mockery/extension.neon + - /composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon + parameters: ignoreErrors: # false positive - - '#Call to an undefined method object::getDocComment\(\)#' + - '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array but returns array#' + - "~Parameter #1 $function of function call_user_func_array expects callable(): mixed, array(string, 'create') given.~" - '#Cannot call method render\(\) on phpDocumentor\\Reflection\\DocBlock\\Description\|string#' - - '#Calling method create\(\) on possibly null value of type phpDocumentor\\Reflection\\DocBlock\\DescriptionFactory\|null#' - - '#Calling method resolve\(\) on possibly null value of type phpDocumentor\\Reflection\\(TypeResolver|FqsenResolver)\|null#' - - # nested parents - - '#Calling method render\(\) on possibly null value of type phpDocumentor\\Reflection\\DocBlock\\Description\|string\|null#' diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 458fac7..746a2c2 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; use const PREG_SPLIT_DELIM_CAPTURE; use function count; use function explode; @@ -62,9 +63,28 @@ class DescriptionFactory */ public function create(string $contents, ?TypeContext $context = null) : Description { - [$text, $tags] = $this->parse($this->lex($contents), $context); + $tokens = $this->lex($contents); + $count = count($tokens); + $tagCount = 0; + $tags = []; - return new Description($text, $tags); + for ($i = 1; $i < $count; $i += 2) { + $tag = $this->tagFactory->create($tokens[$i], $context); + if ($tag !== null) { + $tags[] = $tag; + } + $tokens[$i] = '%' . ++$tagCount . '$s'; + } + + //In order to allow "literal" inline tags, the otherwise invalid + //sequence "{@}" is changed to "@", and "{}" is changed to "}". + //"%" is escaped to "%%" because of vsprintf. + //See unit tests for examples. + for ($i = 0; $i < $count; $i += 2) { + $tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]); + } + + return new Description(implode('', $tokens), $tags); } /** @@ -81,7 +101,7 @@ class DescriptionFactory return [$contents]; } - return preg_split( + $parts = preg_split( '/\{ # "{@}" is not a valid inline tag. This ensures that we do not treat it as one, but treat it literally. (?!@\}) @@ -110,35 +130,8 @@ class DescriptionFactory 0, PREG_SPLIT_DELIM_CAPTURE ); - } - - /** - * Parses the stream of tokens in to a new set of tokens containing Tags. - * - * @param string[] $tokens - * - * @return string[]|Tag[] - */ - private function parse(array $tokens, ?TypeContext $context = null) : array - { - $count = count($tokens); - $tagCount = 0; - $tags = []; - - for ($i = 1; $i < $count; $i += 2) { - $tags[] = $this->tagFactory->create($tokens[$i], $context); - $tokens[$i] = '%' . ++$tagCount . '$s'; - } - - //In order to allow "literal" inline tags, the otherwise invalid - //sequence "{@}" is changed to "@", and "{}" is changed to "}". - //"%" is escaped to "%%" because of vsprintf. - //See unit tests for examples. - for ($i = 0; $i < $count; $i += 2) { - $tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]); - } - - return [implode('', $tokens), $tags]; + Assert::isArray($parts); + return $parts; } /** diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index 227894c..919c2b4 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -96,8 +96,10 @@ class ExampleFinder * 2. Checks the source folder for the given filename * 3. Checks the 'examples' folder in the current working directory for examples * 4. Checks the path relative to the current working directory for the given filename + * + * @return string[] all lines of the example file */ - private function getExampleFileContents(string $filename) : ?string + private function getExampleFileContents(string $filename) : ?array { $normalizedPath = null; @@ -119,7 +121,8 @@ class ExampleFinder } } - return $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : null; + $lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false; + return $lines !== false ? $lines : null; } /** diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index b26f761..7cf911a 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -28,6 +28,23 @@ use function count; use function get_class; use function preg_match; use function strpos; +use phpDocumentor\Reflection\DocBlock\Tags\Author; +use phpDocumentor\Reflection\DocBlock\Tags\Covers; +use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; +use phpDocumentor\Reflection\DocBlock\Tags\Link; +use phpDocumentor\Reflection\DocBlock\Tags\Method; +use phpDocumentor\Reflection\DocBlock\Tags\Param; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead; +use phpDocumentor\Reflection\DocBlock\Tags\Property; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite; +use phpDocumentor\Reflection\DocBlock\Tags\Return_; +use phpDocumentor\Reflection\DocBlock\Tags\See; +use phpDocumentor\Reflection\DocBlock\Tags\Since; +use phpDocumentor\Reflection\DocBlock\Tags\Source; +use phpDocumentor\Reflection\DocBlock\Tags\Throws; +use phpDocumentor\Reflection\DocBlock\Tags\Uses; +use phpDocumentor\Reflection\DocBlock\Tags\Var_; +use phpDocumentor\Reflection\DocBlock\Tags\Version; /** * Creates a Tag object given the contents of a tag. @@ -56,25 +73,25 @@ final class StandardTagFactory implements TagFactory * FQCN to a class that handles it as an array value. */ private $tagHandlerMappings = [ - 'author' => '\phpDocumentor\Reflection\DocBlock\Tags\Author', - 'covers' => '\phpDocumentor\Reflection\DocBlock\Tags\Covers', - 'deprecated' => '\phpDocumentor\Reflection\DocBlock\Tags\Deprecated', + 'author' => Author::class, + 'covers' => Covers::class, + 'deprecated' => Deprecated::class, // 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example', - 'link' => '\phpDocumentor\Reflection\DocBlock\Tags\Link', - 'method' => '\phpDocumentor\Reflection\DocBlock\Tags\Method', - 'param' => '\phpDocumentor\Reflection\DocBlock\Tags\Param', - 'property-read' => '\phpDocumentor\Reflection\DocBlock\Tags\PropertyRead', - 'property' => '\phpDocumentor\Reflection\DocBlock\Tags\Property', - 'property-write' => '\phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite', - 'return' => '\phpDocumentor\Reflection\DocBlock\Tags\Return_', - 'see' => '\phpDocumentor\Reflection\DocBlock\Tags\See', - 'since' => '\phpDocumentor\Reflection\DocBlock\Tags\Since', - 'source' => '\phpDocumentor\Reflection\DocBlock\Tags\Source', - 'throw' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws', - 'throws' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws', - 'uses' => '\phpDocumentor\Reflection\DocBlock\Tags\Uses', - 'var' => '\phpDocumentor\Reflection\DocBlock\Tags\Var_', - 'version' => '\phpDocumentor\Reflection\DocBlock\Tags\Version', + 'link' => Link::class, + 'method' => Method::class, + 'param' => Param::class, + 'property-read' => PropertyRead::class, + 'property' => Property::class, + 'property-write' => PropertyWrite::class, + 'return' => Return_::class, + 'see' => See::class, + 'since' => Since::class, + 'source' => Source::class, + 'throw' => Throws::class, + 'throws' => Throws::class, + 'uses' => Uses::class, + 'var' => Var_::class, + 'version' => Version::class, ]; /** @@ -149,7 +166,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function addService($service, $alias = null) : void + public function addService(object $service, $alias = null) : void { $this->serviceLocator[$alias ?: get_class($service)] = $service; } @@ -215,6 +232,8 @@ final class StandardTagFactory implements TagFactory /** * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). + * + * @return */ private function findHandlerClassName(string $tagName, TypeContext $context) : string { @@ -245,7 +264,7 @@ final class StandardTagFactory implements TagFactory { $arguments = []; foreach ($parameters as $parameter) { - $typeHint = $parameter->getClass() ? $parameter->getClass()->getName() : null; + $typeHint = $parameter->getClass() !== null ? $parameter->getClass()->getName() : null; if (isset($locator[$typeHint])) { $arguments[] = $locator[$typeHint]; continue; diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 2a1ebf1..5d165f8 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -51,8 +51,11 @@ final class Covers extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::notEmpty($body); + Assert::notNull($descriptionFactory); + Assert::notNull($resolver); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); return new static( $resolver->resolve($parts[0], $context), diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index 9883414..824ec73 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -43,7 +43,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod [^\s\:]+\:\s*\$[^\$]+\$ )'; - /** @var string The version vector. */ + /** @var string|null The version vector. */ private $version = ''; public function __construct(?string $version = null, ?Description $description = null) @@ -74,6 +74,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod ); } + Assert::notNull($descriptionFactory); return new static( $matches[1], $descriptionFactory->create($matches[2] ?? '', $context) diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index 713a10c..ffb4a5b 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -54,7 +54,7 @@ class Generic extends BaseTag implements Factory\StaticMethod Assert::stringNotEmpty($name); Assert::notNull($descriptionFactory); - $description = $descriptionFactory && $body !== '' ? $descriptionFactory->create($body, $context) : null; + $description = $body !== '' ? $descriptionFactory->create($body, $context) : null; return new static($name, $description); } diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index 475357f..2f9db50 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -50,6 +50,7 @@ final class Link extends BaseTag implements Factory\StaticMethod Assert::notNull($descriptionFactory); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; return new static($parts[0], $description); diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 251cf03..0ab19e9 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -44,7 +44,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** @var string */ private $methodName = ''; - /** @var string[] */ + /** @var string[][] */ private $arguments = []; /** @var bool */ @@ -87,7 +87,8 @@ final class Method extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : ?self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); // 1. none or more whitespace // 2. optionally the keyword "static" followed by whitespace @@ -184,7 +185,7 @@ final class Method extends BaseTag implements Factory\StaticMethod } /** - * @return string[] + * @return string[][] */ public function getArguments() : array { @@ -221,7 +222,7 @@ final class Method extends BaseTag implements Factory\StaticMethod } /** - * @param mixed[][] $arguments + * @param array $arguments * * @return mixed[][] */ diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 5d02cb6..430c3d7 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -66,32 +66,34 @@ final class Param extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + Assert::isArray($parts); $type = null; $variableName = ''; $isVariadic = false; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) && (strlen($parts[0]) > 0) && + if (isset($parts[0]) && ($parts[0] !== '') && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0) ) { $variableName = array_shift($parts); array_shift($parts); - if (substr($variableName, 0, 3) === '...') { + if ($variableName !== null && strpos($variableName, '...') === 0) { $isVariadic = true; $variableName = substr($variableName, 3); } - if (substr($variableName, 0, 1) === '$') { + if ($variableName !== null && strpos($variableName, '$') === 0) { $variableName = substr($variableName, 1); } } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index a81b3f0..55f40b7 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -23,7 +23,7 @@ use const PREG_SPLIT_DELIM_CAPTURE; use function array_shift; use function implode; use function preg_split; -use function strlen; +use function strpos; use function substr; /** @@ -57,24 +57,26 @@ class Property extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + Assert::isArray($parts); $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && (strpos($parts[0], '$') === 0)) { $variableName = array_shift($parts); array_shift($parts); - if (substr($variableName, 0, 1) === '$') { + if ($variableName !== null && strpos($variableName, '$') === 0) { $variableName = substr($variableName, 1); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index f98e332..5810ea8 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -57,24 +57,26 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + Assert::isArray($parts); $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && (strpos($parts[0], '$') === 0)) { $variableName = array_shift($parts); array_shift($parts); - if (substr($variableName, 0, 1) === '$') { + if ($variableName !== null && strpos($variableName, '$') === 0) { $variableName = substr($variableName, 1); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 8e45ab8..ff7367b 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -24,6 +24,7 @@ use function array_shift; use function implode; use function preg_split; use function strlen; +use function strpos; use function substr; /** @@ -57,14 +58,16 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + Assert::isArray($parts); $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } @@ -74,7 +77,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod $variableName = array_shift($parts); array_shift($parts); - if (substr($variableName, 0, 1) === '$') { + if ($variableName !== null && strpos($variableName, '$') === 0) { $variableName = substr($variableName, 1); } } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index dac5036..1efdfbb 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -47,9 +47,11 @@ final class Return_ extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ) : self { - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); $type = $typeResolver->resolve($parts[0] ?? '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context); diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 218309e..5db5a65 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -49,13 +49,15 @@ class See extends BaseTag implements Factory\StaticMethod */ public static function create( string $body, - ?FqsenResolver $resolver = null, + ?FqsenResolver $typeResolver = null, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ) : self { - Assert::allNotNull([$resolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; // https://tools.ietf.org/html/rfc2396#section-3 @@ -63,7 +65,7 @@ class See extends BaseTag implements Factory\StaticMethod return new static(new Url($parts[0]), $description); } - return new static(new FqsenRef($resolver->resolve($parts[0], $context)), $description); + return new static(new FqsenRef($typeResolver->resolve($parts[0], $context)), $description); } /** diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 4b96796..8e714a8 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -43,7 +43,7 @@ final class Since extends BaseTag implements Factory\StaticMethod [^\s\:]+\:\s*\$[^\$]+\$ )'; - /** @var string The version vector. */ + /** @var string|null The version vector. */ private $version = ''; public function __construct(?string $version = null, ?Description $description = null) @@ -68,6 +68,7 @@ final class Since extends BaseTag implements Factory\StaticMethod return null; } + Assert::notNull($descriptionFactory); return new static( $matches[1], $descriptionFactory->create($matches[2] ?? '', $context) diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 7ac2b42..3e9047e 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -47,9 +47,11 @@ final class Throws extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ) : self { - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); $type = $typeResolver->resolve($parts[0] ?? '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context); diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index 24c74dc..529c2b7 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -50,9 +50,12 @@ final class Uses extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ) : self { - Assert::allNotNull([$resolver, $descriptionFactory]); + Assert::notNull($resolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/\s+/Su', $body, 2); + Assert::isArray($parts); + Assert::allString($parts); return new static( $resolver->resolve($parts[0], $context), diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index e39d4e0..1039ffd 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -57,24 +57,29 @@ class Var_ extends BaseTag implements Factory\StaticMethod ?TypeContext $context = null ) : self { Assert::stringNotEmpty($body); - Assert::allNotNull([$typeResolver, $descriptionFactory]); + Assert::notNull($typeResolver); + Assert::notNull($descriptionFactory); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + Assert::isArray($parts); + Assert::allString($parts); $type = null; $variableName = ''; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { - $type = $typeResolver->resolve(array_shift($parts), $context); + if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { + if ($typeResolver !== null) { + $type = $typeResolver->resolve(array_shift($parts), $context); + } array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) { + if (isset($parts[0]) && ($parts[0] !== '') && (strpos($parts[0], '$') === 0)) { $variableName = array_shift($parts); array_shift($parts); - if (substr($variableName, 0, 1) === '$') { + if ($variableName !== null && strpos($variableName, '$') === 0) { $variableName = substr($variableName, 1); } } diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index 5a50283..28cc326 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -43,7 +43,7 @@ final class Version extends BaseTag implements Factory\StaticMethod [^\s\:]+\:\s*\$[^\$]+\$ )'; - /** @var string The version vector. */ + /** @var string|null The version vector. */ private $version = ''; public function __construct(?string $version = null, ?Description $description = null) @@ -68,9 +68,14 @@ final class Version extends BaseTag implements Factory\StaticMethod return null; } + $description = null; + if ($descriptionFactory !== null) { + $description = $descriptionFactory->create($matches[2] ?? '', $context); + } + return new static( $matches[1], - $descriptionFactory->create($matches[2] ?? '', $context) + $description ); } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index d046a65..1ea28eb 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -230,7 +230,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface * @param string $tags Tag block to parse. * @param Types\Context $context Context of the parsed Tag * - * @return DocBlock\Tag[]|string[]|null[] + * @return DocBlock\Tag[] */ private function parseTagBlock(string $tags, Types\Context $context) : array { @@ -239,9 +239,13 @@ final class DocBlockFactory implements DocBlockFactoryInterface return []; } - $result = $this->splitTagBlockIntoTagLines($tags); - foreach ($result as $key => $tagLine) { - $result[$key] = $this->tagFactory->create(trim($tagLine), $context); + $result = []; + $lines = $this->splitTagBlockIntoTagLines($tags); + foreach ($lines as $key => $tagLine) { + $tag = $this->tagFactory->create(trim($tagLine), $context); + if ($tag instanceof Tag) { + $result[$key] = $tag; + } } return $result; From 50ec1362de7f758a61dac08d031bd565db1d7049 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 26 Sep 2019 21:09:37 +0200 Subject: [PATCH 03/10] Psalm fixes --- composer-require-config.json | 15 +++ composer.json | 13 ++- composer.lock | 165 ++++++++++++++++++++-------- src/DocBlock/ExampleFinder.php | 2 +- src/DocBlock/StandardTagFactory.php | 51 +++++---- src/DocBlock/Tags/Link.php | 2 +- src/DocBlock/Tags/Method.php | 2 +- src/DocBlock/Tags/Param.php | 3 +- src/DocBlock/Tags/PropertyRead.php | 4 +- src/DocBlock/Tags/PropertyWrite.php | 2 +- src/DocBlock/Tags/See.php | 2 +- src/DocBlock/Tags/Var_.php | 6 +- src/DocBlock/Tags/Version.php | 3 +- src/DocBlockFactory.php | 16 +-- 14 files changed, 187 insertions(+), 99 deletions(-) create mode 100644 composer-require-config.json diff --git a/composer-require-config.json b/composer-require-config.json new file mode 100644 index 0000000..19eee4f --- /dev/null +++ b/composer-require-config.json @@ -0,0 +1,15 @@ +{ + "symbol-whitelist" : [ + "null", "true", "false", + "static", "self", "parent", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor" + ], + "php-core-extensions" : [ + "Core", + "pcre", + "Reflection", + "tokenizer", + "SPL", + "standard" + ] +} diff --git a/composer.json b/composer.json index 788ed98..a072f63 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,18 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], - "minimum-stability": "alpha", "require": { - "php": ">=7.1", - "phpdocumentor/type-resolver": "^0", - "webmozart/assert": "^1" + "php": "^7.1", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1", + "phpdocumentor/reflection-common": "^2.0", + "ext-filter": "^7.1" }, "require-dev": { "mockery/mockery": "^1", diff --git a/composer.lock b/composer.lock index 29b1328..cc854ec 100644 --- a/composer.lock +++ b/composer.lock @@ -1,30 +1,30 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cb7ecdcb52e627755275cf273bcdd249", + "content-hash": "93c5a8174b30802326730535c6b1479f", "packages": [ { "name": "phpdocumentor/reflection-common", - "version": "2.0.0-alpha3", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "eedd98e8bc9cfd924f056b4b5847066d4a250d2f" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/eedd98e8bc9cfd924f056b4b5847066d4a250d2f", - "reference": "eedd98e8bc9cfd924f056b4b5847066d4a250d2f", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { @@ -34,9 +34,7 @@ }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -58,34 +56,35 @@ "reflection", "static analysis" ], - "time": "2018-06-13T21:44:20+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.6.2", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e81ce9e82df06b49b2d0e0a2393a08955aeda05b" + "reference": "4dfca962ce4d6c11ae17efcc65621cc4b22004c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e81ce9e82df06b49b2d0e0a2393a08955aeda05b", - "reference": "e81ce9e82df06b49b2d0e0a2393a08955aeda05b", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/4dfca962ce4d6c11ae17efcc65621cc4b22004c7", + "reference": "4dfca962ce4d6c11ae17efcc65621cc4b22004c7", "shasum": "" }, "require": { - "php": ">=7.1", - "phpdocumentor/reflection-common": "^2" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.5" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { @@ -93,7 +92,11 @@ "phpDocumentor\\Reflection\\": "src" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "phpDocumentor\\Reflection\\": "tests/unit" + } + }, "license": [ "MIT" ], @@ -103,24 +106,88 @@ "email": "me@mikevanriel.com" } ], - "time": "2018-06-14T12:29:58+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.0.0", + "issues": "https://github.com/phpDocumentor/TypeResolver/issues" + }, + "time": "2019-07-08T19:35:58+00:00" }, { - "name": "webmozart/assert", - "version": "1.3.0", + "name": "symfony/polyfill-ctype", + "version": "v1.11.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "82ebae02209c21113908c229e9883c419720738a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.11-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-02-06T07:57:58+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -153,33 +220,35 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2018-12-25T11:19:39+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + "reference": "a2c590166b2133a4633738648b6b064edae0814a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^6.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "^6.2.3", - "squizlabs/php_codesniffer": "^3.0.2" + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { @@ -204,12 +273,12 @@ } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2017-07-22T11:58:36+00:00" + "time": "2019-03-17T17:37:11+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -261,16 +330,16 @@ }, { "name": "mockery/mockery", - "version": "1.1.0", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "99e29d3596b16dabe4982548527d5ddf90232e99" + "reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/99e29d3596b16dabe4982548527d5ddf90232e99", - "reference": "99e29d3596b16dabe4982548527d5ddf90232e99", + "url": "https://api.github.com/repos/mockery/mockery/zipball/0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2", + "reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2", "shasum": "" }, "require": { @@ -279,8 +348,7 @@ "php": ">=5.6.0" }, "require-dev": { - "phpdocumentor/phpdocumentor": "^2.9", - "phpunit/phpunit": "~5.7.10|~6.5" + "phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0" }, "type": "library", "extra": { @@ -323,16 +391,17 @@ "test double", "testing" ], - "time": "2018-05-08T08:54:48+00:00" + "time": "2019-02-13T09:37:52+00:00" } ], "aliases": [], - "minimum-stability": "alpha", + "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1" + "php": "^7.1", + "ext-filter": "^7.1" }, "platform-dev": [] } diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index 919c2b4..db42be7 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -122,7 +122,7 @@ class ExampleFinder } $lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false; - return $lines !== false ? $lines : null; + return $lines !== false ? $lines : null; } /** diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 7cf911a..02c3651 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -8,14 +8,31 @@ declare(strict_types=1); * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * - * @link http://phpdoc.org + * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock; use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Tags\Author; +use phpDocumentor\Reflection\DocBlock\Tags\Covers; +use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod; use phpDocumentor\Reflection\DocBlock\Tags\Generic; +use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag; +use phpDocumentor\Reflection\DocBlock\Tags\Method; +use phpDocumentor\Reflection\DocBlock\Tags\Param; +use phpDocumentor\Reflection\DocBlock\Tags\Property; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite; +use phpDocumentor\Reflection\DocBlock\Tags\Return_; +use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag; +use phpDocumentor\Reflection\DocBlock\Tags\Since; +use phpDocumentor\Reflection\DocBlock\Tags\Source; +use phpDocumentor\Reflection\DocBlock\Tags\Throws; +use phpDocumentor\Reflection\DocBlock\Tags\Uses; +use phpDocumentor\Reflection\DocBlock\Tags\Var_; +use phpDocumentor\Reflection\DocBlock\Tags\Version; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use ReflectionMethod; @@ -28,23 +45,6 @@ use function count; use function get_class; use function preg_match; use function strpos; -use phpDocumentor\Reflection\DocBlock\Tags\Author; -use phpDocumentor\Reflection\DocBlock\Tags\Covers; -use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; -use phpDocumentor\Reflection\DocBlock\Tags\Link; -use phpDocumentor\Reflection\DocBlock\Tags\Method; -use phpDocumentor\Reflection\DocBlock\Tags\Param; -use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead; -use phpDocumentor\Reflection\DocBlock\Tags\Property; -use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite; -use phpDocumentor\Reflection\DocBlock\Tags\Return_; -use phpDocumentor\Reflection\DocBlock\Tags\See; -use phpDocumentor\Reflection\DocBlock\Tags\Since; -use phpDocumentor\Reflection\DocBlock\Tags\Source; -use phpDocumentor\Reflection\DocBlock\Tags\Throws; -use phpDocumentor\Reflection\DocBlock\Tags\Uses; -use phpDocumentor\Reflection\DocBlock\Tags\Var_; -use phpDocumentor\Reflection\DocBlock\Tags\Version; /** * Creates a Tag object given the contents of a tag. @@ -77,14 +77,14 @@ final class StandardTagFactory implements TagFactory 'covers' => Covers::class, 'deprecated' => Deprecated::class, // 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example', - 'link' => Link::class, + 'link' => LinkTag::class, 'method' => Method::class, 'param' => Param::class, 'property-read' => PropertyRead::class, 'property' => Property::class, 'property-write' => PropertyWrite::class, 'return' => Return_::class, - 'see' => See::class, + 'see' => SeeTag::class, 'since' => Since::class, 'source' => Source::class, 'throw' => Throws::class, @@ -166,7 +166,7 @@ final class StandardTagFactory implements TagFactory /** * {@inheritDoc} */ - public function addService(object $service, $alias = null) : void + public function addService(object $service, ?string $alias = null) : void { $this->serviceLocator[$alias ?: get_class($service)] = $service; } @@ -232,8 +232,6 @@ final class StandardTagFactory implements TagFactory /** * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). - * - * @return */ private function findHandlerClassName(string $tagName, TypeContext $context) : string { @@ -264,7 +262,12 @@ final class StandardTagFactory implements TagFactory { $arguments = []; foreach ($parameters as $parameter) { - $typeHint = $parameter->getClass() !== null ? $parameter->getClass()->getName() : null; + $class = $parameter->getClass(); + $typeHint = null; + if ($class !== null) { + $typeHint = $class->getName(); + } + if (isset($locator[$typeHint])) { $arguments[] = $locator[$typeHint]; continue; diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index 2f9db50..a50c813 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -49,7 +49,7 @@ final class Link extends BaseTag implements Factory\StaticMethod ) : self { Assert::notNull($descriptionFactory); - $parts = preg_split('/\s+/Su', $body, 2); + $parts = preg_split('/\s+/Su', $body, 2); Assert::isArray($parts); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 0ab19e9..8f9ab59 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -222,7 +222,7 @@ final class Method extends BaseTag implements Factory\StaticMethod } /** - * @param array $arguments + * @param mixed[][] $arguments * * @return mixed[][] */ diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 430c3d7..74e984d 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -23,7 +23,6 @@ use const PREG_SPLIT_DELIM_CAPTURE; use function array_shift; use function implode; use function preg_split; -use function strlen; use function strpos; use function substr; @@ -69,7 +68,7 @@ final class Param extends BaseTag implements Factory\StaticMethod Assert::notNull($typeResolver); Assert::notNull($descriptionFactory); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); Assert::isArray($parts); $type = null; $variableName = ''; diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 5810ea8..9cdd4f8 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -23,7 +23,7 @@ use const PREG_SPLIT_DELIM_CAPTURE; use function array_shift; use function implode; use function preg_split; -use function strlen; +use function strpos; use function substr; /** @@ -60,7 +60,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod Assert::notNull($typeResolver); Assert::notNull($descriptionFactory); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); Assert::isArray($parts); $type = null; $variableName = ''; diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index ff7367b..edeed5f 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -61,7 +61,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod Assert::notNull($typeResolver); Assert::notNull($descriptionFactory); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); Assert::isArray($parts); $type = null; $variableName = ''; diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 5db5a65..cb79e48 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -56,7 +56,7 @@ class See extends BaseTag implements Factory\StaticMethod Assert::notNull($typeResolver); Assert::notNull($descriptionFactory); - $parts = preg_split('/\s+/Su', $body, 2); + $parts = preg_split('/\s+/Su', $body, 2); Assert::isArray($parts); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index 1039ffd..cf5b4d9 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -23,7 +23,7 @@ use const PREG_SPLIT_DELIM_CAPTURE; use function array_shift; use function implode; use function preg_split; -use function strlen; +use function strpos; use function substr; /** @@ -60,7 +60,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod Assert::notNull($typeResolver); Assert::notNull($descriptionFactory); - $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); Assert::isArray($parts); Assert::allString($parts); $type = null; @@ -111,7 +111,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . (empty($this->variableName) ? null : ('$' . $this->variableName)) + . (empty($this->variableName) ? '' : ('$' . $this->variableName)) . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index 28cc326..7fdb590 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -92,6 +92,7 @@ final class Version extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->version . ($this->description ? ' ' . $this->description->render() : ''); + return ((string) $this->version) . + ($this->description instanceof Description ? ' ' . $this->description->render() : ''); } } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 1ea28eb..3055968 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -20,7 +20,6 @@ use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\TagFactory; use Webmozart\Assert\Assert; -use function array_filter; use function array_shift; use function count; use function explode; @@ -100,12 +99,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface return new DocBlock( $summary, $description ? $this->descriptionFactory->create($description, $context) : null, - array_filter( - $this->parseTagBlock($tags, $context), - static function ($tag) { - return $tag instanceof Tag; - } - ), + $this->parseTagBlock($tags, $context), $context, $location, $templateMarker === '#@+', @@ -240,12 +234,14 @@ final class DocBlockFactory implements DocBlockFactoryInterface } $result = []; - $lines = $this->splitTagBlockIntoTagLines($tags); + $lines = $this->splitTagBlockIntoTagLines($tags); foreach ($lines as $key => $tagLine) { $tag = $this->tagFactory->create(trim($tagLine), $context); - if ($tag instanceof Tag) { - $result[$key] = $tag; + if (!($tag instanceof Tag)) { + continue; } + + $result[$key] = $tag; } return $result; From 73ea6784b334130ecbaa8909d12d504743ecf082 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 26 Sep 2019 21:11:19 +0200 Subject: [PATCH 04/10] Add workflow to ensure checks --- .github/workflows/push.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..4e53593 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,35 @@ +on: push +name: Qa workflow +jobs: + qa-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: composer + uses: docker://composer + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: install --no-interaction --prefer-dist --optimize-autoloader + - name: Code style check + uses: docker://phpdoc/phpcs-ga:master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: -d memory_limit=1024M -s + - name: composer-require-checker + uses: docker://phpga/composer-require-checker-ga + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: check --config-file ./composer-require-config.json composer.json + - name: Psalm + uses: docker://mickaelandrieu/psalm-ga + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: analyse src --level max --configuration phpstan.neon From 09e086ecf13bde3be24643709cb01fc1394fd315 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 26 Sep 2019 21:19:59 +0200 Subject: [PATCH 05/10] Cleanup build files --- .travis.yml | 9 --------- easy-coding-standard.neon | 26 -------------------------- phive.xml | 5 ----- psalm.xml | 18 ++++++++++++++++++ 4 files changed, 18 insertions(+), 40 deletions(-) delete mode 100644 easy-coding-standard.neon delete mode 100644 phive.xml create mode 100644 psalm.xml diff --git a/.travis.yml b/.travis.yml index 050bab9..f4cc4b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,18 +27,9 @@ jobs: - travis_retry php phive.phar --no-progress install --trust-gpg-keys E82B2FB314E9906E php-coveralls/php-coveralls && ./tools/php-coveralls --verbose - travis_retry wget --no-verbose https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - - stage: lint - php: 7.1 - before_script: - - travis_retry php phive.phar --no-progress install --trust-gpg-keys 8E730BA25823D8B5 phpstan - script: - - ./tools/phpstan analyse src --level max --configuration phpstan.neon - - composer create-project symplify/easy-coding-standard temp/ecs ^3 && temp/ecs/bin/ecs check src tests - cache: directories: - $HOME/.composer/cache/files - - $HOME/.phive notifications: irc: "irc.freenode.org#phpdocumentor" diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon deleted file mode 100644 index 8260402..0000000 --- a/easy-coding-standard.neon +++ /dev/null @@ -1,26 +0,0 @@ -includes: - - temp/ecs/config/clean-code.neon - - temp/ecs/config/psr2.neon - - temp/ecs/config/common.neon - -parameters: - exclude_checkers: - # from temp/ecs/config/common.neon - - PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer - - PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer - - PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer - # from temp/ecs/config/spaces.neon - - PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer - - skip: - SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff: - # WIP code - - src/DocBlock/StandardTagFactory.php - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff: - # WIP code - - src/DocBlock/StandardTagFactory.php - PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff: - - src/DocBlock/Tags/Return_.php - - src/DocBlock/Tags/Var_.php - PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff: - - */tests/** diff --git a/phive.xml b/phive.xml deleted file mode 100644 index 24b708d..0000000 --- a/phive.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..9fedb8a --- /dev/null +++ b/psalm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + From c14c01875aa515194332e6eba966a66dbd035ef8 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 10 Dec 2019 23:46:06 +0100 Subject: [PATCH 06/10] Make static anlisys pass --- Makefile | 32 +++++++++++++++ composer.lock | 21 ++++------ phive.xml | 5 +++ phpstan.neon | 2 - phpunit.xml.dist | 10 +---- src/DocBlock/StandardTagFactory.php | 6 ++- src/DocBlock/Tags/BaseTag.php | 7 +--- src/DocBlock/Tags/Deprecated.php | 2 +- src/DocBlock/Tags/Example.php | 50 +++++++++++++++-------- src/DocBlock/Tags/Generic.php | 2 +- src/DocBlock/Tags/Method.php | 20 +++++---- src/DocBlock/Tags/Param.php | 12 +++--- src/DocBlock/Tags/Property.php | 10 ++--- src/DocBlock/Tags/PropertyRead.php | 10 ++--- src/DocBlock/Tags/PropertyWrite.php | 10 ++--- src/DocBlock/Tags/Return_.php | 2 +- src/DocBlock/Tags/See.php | 2 +- src/DocBlock/Tags/Since.php | 2 +- src/DocBlock/Tags/Source.php | 4 +- src/DocBlock/Tags/Throws.php | 2 +- src/DocBlock/Tags/Uses.php | 2 +- src/DocBlock/Tags/Var_.php | 12 +++--- tests/unit/DocBlock/ExampleFinderTest.php | 2 +- tests/unit/DocBlockFactoryTest.php | 12 ++++-- 24 files changed, 143 insertions(+), 96 deletions(-) create mode 100644 Makefile create mode 100644 phive.xml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..374f1bd --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +.PHONY: install-phive +install-phive: + mkdir tools; \ + wget -O tools/phive.phar https://phar.io/releases/phive.phar; \ + wget -O tools/phive.phar.asc https://phar.io/releases/phive.phar.asc; \ + gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79; \ + gpg --verify tools/phive.phar.asc tools/phive.phar; \ + chmod +x tools/phive.phar + +.PHONY: setup +setup: install-phive + docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phar-ga:latest php tools/phive.phar install --force-accept-unsigned + +.PHONY: phpcs +phpcs: + docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest -d memory_limit=1024M + +.PHONY: phpstan +phpstan: + docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpstan-ga:latest analyse src --debug --no-progress --level max --configuration phpstan.neon + +.PHONY: psaml +psalm: + docker run -it --rm -v${PWD}:/opt/project -w /opt/project mickaelandrieu/psalm-ga + +.PHONY: test +test: + docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/phpunit + +.PHONY: pre-commit-test +pre-commit-test: test phpcs phpstan psalm + diff --git a/composer.lock b/composer.lock index cc854ec..e2ac299 100644 --- a/composer.lock +++ b/composer.lock @@ -173,32 +173,29 @@ }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", + "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", "shasum": "" }, "require": { "php": "^5.3.3 || ^7.0", "symfony/polyfill-ctype": "^1.8" }, + "conflict": { + "vimeo/psalm": "<3.6.0" + }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -220,7 +217,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-11-24T13:36:37+00:00" } ], "packages-dev": [ diff --git a/phive.xml b/phive.xml new file mode 100644 index 0000000..5168775 --- /dev/null +++ b/phive.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/phpstan.neon b/phpstan.neon index 4ebb808..272dd74 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,5 +6,3 @@ parameters: ignoreErrors: # false positive - '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array but returns array#' - - "~Parameter #1 $function of function call_user_func_array expects callable(): mixed, array(string, 'create') given.~" - - '#Cannot call method render\(\) on phpDocumentor\\Reflection\\DocBlock\\Description\|string#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1460f9a..81f914c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,9 @@ ./src/ - - ./vendor/ - diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 02c3651..59caf8c 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -177,8 +177,8 @@ final class StandardTagFactory implements TagFactory public function registerTagHandler(string $tagName, string $handler) : void { Assert::stringNotEmpty($tagName); - Assert::stringNotEmpty($handler); Assert::classExists($handler); + /** @var object $handler stupid hack to make phpstan happy. */ Assert::implementsInterface($handler, StaticMethod::class); if (strpos($tagName, '\\') && $tagName[0] !== '\\') { @@ -224,7 +224,9 @@ final class StandardTagFactory implements TagFactory ); try { - return call_user_func_array([$handlerClassName, 'create'], $arguments); + /** @var callable $callable */ + $callable = [$handlerClassName, 'create']; + return call_user_func_array($callable, $arguments); } catch (InvalidArgumentException $e) { return null; } diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php index 7a1b949..fbcd402 100644 --- a/src/DocBlock/Tags/BaseTag.php +++ b/src/DocBlock/Tags/BaseTag.php @@ -24,7 +24,7 @@ abstract class BaseTag implements DocBlock\Tag /** @var string Name of the tag */ protected $name = ''; - /** @var Description|string|null Description of the tag. */ + /** @var Description|null Description of the tag. */ protected $description; /** @@ -37,10 +37,7 @@ abstract class BaseTag implements DocBlock\Tag return $this->name; } - /** - * @return Description|string|null - */ - public function getDescription() + public function getDescription() : ?Description { return $this->description; } diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index 824ec73..130d844 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -94,6 +94,6 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->version . ($this->description ? ' ' . $this->description->render() : ''); + return ($this->version ?? '') . ($this->description ? ' ' . $this->description->render() : ''); } } diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 122d6d3..020145f 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -13,7 +13,6 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Tag; use Webmozart\Assert\Assert; use function array_key_exists; @@ -26,7 +25,7 @@ use function trim; /** * Reflection class for a {@}example tag in a Docblock. */ -final class Example extends BaseTag +final class Example implements Tag { /** @var string Path to a file to use as an example. May also be an absolute URI. */ private $filePath; @@ -43,10 +42,10 @@ final class Example extends BaseTag /** @var int */ private $lineCount; - /** - * @param string|Description|null $description - */ - public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, $description) + /** @var string|null */ + private $content; + + public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content) { Assert::notEmpty($filePath); Assert::greaterThanEq($startingLine, 0); @@ -55,20 +54,16 @@ final class Example extends BaseTag $this->filePath = $filePath; $this->startingLine = $startingLine; $this->lineCount = $lineCount; - $this->name = 'example'; - if ($description !== null) { - $this->description = trim((string) $description); + if ($content !== null) { + $this->content = trim((string) $content); } $this->isURI = $isURI; } - /** - * {@inheritdoc} - */ - public function getContent() + public function getContent() : string { - if ($this->description === null) { + if ($this->content === null) { $filePath = '"' . $this->filePath . '"'; if ($this->isURI) { $filePath = $this->isUriRelative($this->filePath) @@ -76,10 +71,15 @@ final class Example extends BaseTag : $this->filePath; } - return trim($filePath . ' ' . parent::getDescription()); + return trim($filePath); } - return $this->description; + return $this->content; + } + + public function getDescription() : ?string + { + return $this->content; } /** @@ -121,7 +121,7 @@ final class Example extends BaseTag } return new static( - $filePath ?? $fileUri, + $filePath ?? ($fileUri ?? ''), $fileUri !== null, $startingLine, $lineCount, @@ -145,7 +145,7 @@ final class Example extends BaseTag */ public function __toString() : string { - return $this->filePath . ($this->description ? ' ' . $this->description : ''); + return $this->filePath . ($this->content ? ' ' . $this->content : ''); } /** @@ -165,4 +165,18 @@ final class Example extends BaseTag { return $this->lineCount; } + + public function getName() : string + { + return 'example'; + } + + public function render(?Formatter $formatter = null) : string + { + if ($formatter === null) { + $formatter = new Formatter\PassthroughFormatter(); + } + + return $formatter->format($this); + } } diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index ffb4a5b..7509ff1 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -24,7 +24,7 @@ use function preg_match; /** * Parses a tag definition for a DocBlock. */ -class Generic extends BaseTag implements Factory\StaticMethod +final class Generic extends BaseTag implements Factory\StaticMethod { /** * Parses a tag and populates the member variables. diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 8f9ab59..4d42961 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -27,7 +27,6 @@ use function implode; use function is_string; use function preg_match; use function sort; -use function strlen; use function strpos; use function substr; use function trim; @@ -54,7 +53,9 @@ final class Method extends BaseTag implements Factory\StaticMethod private $returnType; /** - * @param mixed[][] $arguments $arguments + * @param mixed[][] $arguments + * + * @psalm-param array|string> $arguments */ public function __construct( string $methodName, @@ -64,7 +65,6 @@ final class Method extends BaseTag implements Factory\StaticMethod ?Description $description = null ) { Assert::stringNotEmpty($methodName); - Assert::boolean($static); if ($returnType === null) { $returnType = new Void_(); @@ -151,7 +151,7 @@ final class Method extends BaseTag implements Factory\StaticMethod $returnType = $typeResolver->resolve($returnType, $context); $description = $descriptionFactory->create($description, $context); - if (is_string($arguments) && strlen($arguments) > 0) { + if ($arguments !== '') { $arguments = explode(',', $arguments); foreach ($arguments as &$argument) { $argument = explode(' ', self::stripRestArg(trim($argument)), 2); @@ -222,13 +222,17 @@ final class Method extends BaseTag implements Factory\StaticMethod } /** - * @param mixed[][] $arguments + * @param mixed[][]|string[] $arguments * * @return mixed[][] + * + * @psalm-param array|string> $arguments + * @psalm-return array> $arguments */ private function filterArguments(array $arguments = []) : array { - foreach ($arguments as &$argument) { + $result = []; + foreach ($arguments as $argument) { if (is_string($argument)) { $argument = ['name' => $argument]; } @@ -244,9 +248,11 @@ final class Method extends BaseTag implements Factory\StaticMethod 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) ); } + + $result[] = $argument; } - return $arguments; + return $result; } private static function stripRestArg(string $argument) : string diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 74e984d..967ed84 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -37,14 +37,14 @@ final class Param extends BaseTag implements Factory\StaticMethod /** @var Type|null */ private $type; - /** @var string */ - private $variableName = ''; + /** @var string|null */ + private $variableName; /** @var bool determines whether this is a variadic argument */ - private $isVariadic = false; + private $isVariadic; public function __construct( - string $variableName, + ?string $variableName, ?Type $type = null, bool $isVariadic = false, ?Description $description = null @@ -105,7 +105,7 @@ final class Param extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName() : string + public function getVariableName() : ?string { return $this->variableName; } @@ -133,7 +133,7 @@ final class Param extends BaseTag implements Factory\StaticMethod { return ($this->type ? $this->type . ' ' : '') . ($this->isVariadic() ? '...' : '') - . '$' . $this->variableName + . ($this->variableName !== null ? '$' . $this->variableName : '') . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index 55f40b7..290a4fa 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -29,7 +29,7 @@ use function substr; /** * Reflection class for a {@}property tag in a Docblock. */ -class Property extends BaseTag implements Factory\StaticMethod +final class Property extends BaseTag implements Factory\StaticMethod { /** @var string */ protected $name = 'property'; @@ -37,10 +37,10 @@ class Property extends BaseTag implements Factory\StaticMethod /** @var Type|null */ private $type; - /** @var string */ + /** @var string|null */ protected $variableName = ''; - public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; $this->type = $type; @@ -89,7 +89,7 @@ class Property extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName() : string + public function getVariableName() : ?string { return $this->variableName; } @@ -108,7 +108,7 @@ class Property extends BaseTag implements Factory\StaticMethod public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName + . ($this->variableName ? '$' . $this->variableName : '') . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 9cdd4f8..4e0c904 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -29,7 +29,7 @@ use function substr; /** * Reflection class for a {@}property-read tag in a Docblock. */ -class PropertyRead extends BaseTag implements Factory\StaticMethod +final class PropertyRead extends BaseTag implements Factory\StaticMethod { /** @var string */ protected $name = 'property-read'; @@ -37,10 +37,10 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod /** @var Type|null */ private $type; - /** @var string */ + /** @var string|null */ protected $variableName = ''; - public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; $this->type = $type; @@ -89,7 +89,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName() : string + public function getVariableName() : ?string { return $this->variableName; } @@ -108,7 +108,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName + . ($this->variableName ? '$' . $this->variableName : '') . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index edeed5f..014b1ac 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -30,7 +30,7 @@ use function substr; /** * Reflection class for a {@}property-write tag in a Docblock. */ -class PropertyWrite extends BaseTag implements Factory\StaticMethod +final class PropertyWrite extends BaseTag implements Factory\StaticMethod { /** @var string */ protected $name = 'property-write'; @@ -38,10 +38,10 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod /** @var Type|null */ private $type; - /** @var string */ + /** @var string|null */ protected $variableName = ''; - public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; $this->type = $type; @@ -90,7 +90,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName() : string + public function getVariableName() : ?string { return $this->variableName; } @@ -109,7 +109,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName + . ($this->variableName ? '$' . $this->variableName : '') . ($this->description ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index 1efdfbb..2fb8135 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -69,6 +69,6 @@ final class Return_ extends BaseTag implements Factory\StaticMethod public function __toString() : string { - return $this->type . ' ' . $this->description; + return $this->type . ' ' . (string) $this->description; } } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index cb79e48..21d8591 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -27,7 +27,7 @@ use function preg_split; /** * Reflection class for an {@}see tag in a Docblock. */ -class See extends BaseTag implements Factory\StaticMethod +final class See extends BaseTag implements Factory\StaticMethod { /** @var string */ protected $name = 'see'; diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 8e714a8..31ce54c 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -88,6 +88,6 @@ final class Since extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->version . ($this->description ? ' ' . $this->description->render() : ''); + return (string) $this->version . ($this->description ? ' ' . (string) $this->description : ''); } } diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index c6286fd..b678806 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -72,7 +72,7 @@ final class Source extends BaseTag implements Factory\StaticMethod $description = $matches[3]; } - return new static($startingLine, $lineCount, $descriptionFactory->create($description, $context)); + return new static($startingLine, $lineCount, $descriptionFactory->create($description??'', $context)); } /** @@ -101,6 +101,6 @@ final class Source extends BaseTag implements Factory\StaticMethod { return $this->startingLine . ($this->lineCount !== null ? ' ' . $this->lineCount : '') - . ($this->description ? ' ' . $this->description->render() : ''); + . ($this->description ? ' ' . (string) $this->description : ''); } } diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 3e9047e..1a2328d 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -69,6 +69,6 @@ final class Throws extends BaseTag implements Factory\StaticMethod public function __toString() : string { - return $this->type . ' ' . $this->description; + return (string) $this->type . ' ' . (string) $this->description; } } diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index 529c2b7..7a69642 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -76,6 +76,6 @@ final class Uses extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->refers . ' ' . $this->description->render(); + return $this->refers . ' ' . (string) $this->description; } } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index cf5b4d9..1bd5b8a 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -29,7 +29,7 @@ use function substr; /** * Reflection class for a {@}var tag in a Docblock. */ -class Var_ extends BaseTag implements Factory\StaticMethod +final class Var_ extends BaseTag implements Factory\StaticMethod { /** @var string */ protected $name = 'var'; @@ -37,10 +37,10 @@ class Var_ extends BaseTag implements Factory\StaticMethod /** @var Type|null */ private $type; - /** @var string */ + /** @var string|null */ protected $variableName = ''; - public function __construct(string $variableName, ?Type $type = null, ?Description $description = null) + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { $this->variableName = $variableName; $this->type = $type; @@ -68,9 +68,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod // if the first item that is encountered is not a variable; it is a type if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { - if ($typeResolver !== null) { - $type = $typeResolver->resolve(array_shift($parts), $context); - } + $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } @@ -92,7 +90,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod /** * Returns the variable's name. */ - public function getVariableName() : string + public function getVariableName() : ?string { return $this->variableName; } diff --git a/tests/unit/DocBlock/ExampleFinderTest.php b/tests/unit/DocBlock/ExampleFinderTest.php index 19a32f1..d135892 100644 --- a/tests/unit/DocBlock/ExampleFinderTest.php +++ b/tests/unit/DocBlock/ExampleFinderTest.php @@ -39,7 +39,7 @@ class ExampleFinderTest extends TestCase */ public function testFileNotFound() : void { - $example = new Example('./example.php', false, 1, 0, new Description('Test')); + $example = new Example('./example.php', false, 1, 0, 'Test'); $this->assertSame('** File not found : ./example.php **', $this->fixture->find($example)); } } diff --git a/tests/unit/DocBlockFactoryTest.php b/tests/unit/DocBlockFactoryTest.php index 91f06be..1c965ad 100644 --- a/tests/unit/DocBlockFactoryTest.php +++ b/tests/unit/DocBlockFactoryTest.php @@ -221,7 +221,8 @@ DOCBLOCK; << Date: Wed, 11 Dec 2019 09:13:46 +0100 Subject: [PATCH 07/10] Bump minimal required php version --- composer.json | 2 +- composer.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a072f63..008f1d8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "phpdocumentor/type-resolver": "^1.0", "webmozart/assert": "^1", "phpdocumentor/reflection-common": "^2.0", diff --git a/composer.lock b/composer.lock index e2ac299..207ce3e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "93c5a8174b30802326730535c6b1479f", + "content-hash": "2f0301d81fbb8c707a619b4e2bdb3a9c", "packages": [ { "name": "phpdocumentor/reflection-common", @@ -397,7 +397,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.1", + "php": "^7.2", "ext-filter": "^7.1" }, "platform-dev": [] From fc2eb2355ec51142a73ddc784cd09bdd782dc90b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 11 Dec 2019 09:18:05 +0100 Subject: [PATCH 08/10] Add phpdoc workflow --- .github/workflows/push.yml | 238 ++++++++++++++++++++++++++++++++----- 1 file changed, 208 insertions(+), 30 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4e53593..dedadea 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,35 +1,213 @@ on: push name: Qa workflow jobs: - qa-checks: + setup: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: composer - uses: docker://composer - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: install --no-interaction --prefer-dist --optimize-autoloader - - name: Code style check - uses: docker://phpdoc/phpcs-ga:master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: -d memory_limit=1024M -s - - name: composer-require-checker - uses: docker://phpga/composer-require-checker-ga - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: check --config-file ./composer-require-config.json composer.json - - name: Psalm - uses: docker://mickaelandrieu/psalm-ga - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: PHPStan - uses: docker://oskarstark/phpstan-ga - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: analyse src --level max --configuration phpstan.neon + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: composer + uses: docker://composer + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: install --no-interaction --prefer-dist --optimize-autoloader + - name: composer-require-checker + uses: docker://phpga/composer-require-checker-ga + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: check --config-file ./composer-require-config.json composer.json + - name: Install phive + run: make install-phive + - name: Install PHAR dependencies + run: tools/phive.phar --no-progress install --copy --trust-gpg-keys 4AA394086372C20A,D2CCAC42F6295E7D,E82B2FB314E9906E,8E730BA25823D8B5 --force-accept-unsigned + + phpunit-with-coverage: + runs-on: ubuntu-latest + name: Unit tests + needs: setup + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: Setup PHP + uses: shivammathur/setup-php@master + with: + php-version: 7.2 + extension-csv: mbstring, intl, iconv, libxml, dom, json, simplexml, zlib + ini-values-csv: memory_limit=2G, display_errors=On, error_reporting=-1 + coverage: xdebug + pecl: false + - name: Run PHPUnit + run: php tools/phpunit + + phpunit: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: + - ubuntu-latest + - windows-latest + - macOS-latest + php-versions: ['7.2', '7.3', '7.4'] + name: Unit tests for PHP version ${{ matrix.php-versions }} on ${{ matrix.operating-system }} + needs: + - setup + - phpunit-with-coverage + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: Setup PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php-versions }} + extension-csv: mbstring, intl, iconv, libxml, dom, json, simplexml, zlib + ini-values-csv: memory_limit=2G, display_errors=On, error_reporting=-1 + pecl: false + - name: Run PHPUnit + continue-on-error: true + run: php tools/phpunit + + codestyle: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: Code style check + uses: docker://phpdoc/phpcs-ga:latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: -d memory_limit=1024M + + phpstan: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: PHPStan + uses: docker://phpdoc/phpstan-ga:latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: analyse src --level max --configuration phpstan.neon + + psalm: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + - name: Psalm + uses: docker://mickaelandrieu/psalm-ga + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + bc_check: + name: BC Check + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@master + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga From 0bbc74b119d2b616eb9a1dfe1540f7d8f3e7506b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 11 Dec 2019 09:32:27 +0100 Subject: [PATCH 09/10] Remove ci configs to switch to github actions --- .travis.yml | 40 -------------------------------------- appveyor.yml | 54 ---------------------------------------------------- 2 files changed, 94 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f4cc4b3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: php -php: [ 7.1, 7.2, 7.3, nightly ] -sudo: false - -env: - -matrix: - fast_finish: true - allow_failures: - - php: nightly - -install: - - travis_retry composer install --no-interaction --prefer-dist --optimize-autoloader - - travis_retry composer global require phpunit/phpunit ^6 # cannot use phpunit.phar or require-dev, because this package is a phpunit dep - - travis_retry wget --no-verbose https://phar.io/releases/phive.phar - -script: - - /home/travis/.composer/vendor/bin/phpunit --no-coverage - -jobs: - include: - - stage: coverage - php: 7.1 - script: - - /home/travis/.composer/vendor/bin/phpunit - after_script: - - travis_retry php phive.phar --no-progress install --trust-gpg-keys E82B2FB314E9906E php-coveralls/php-coveralls && ./tools/php-coveralls --verbose - - travis_retry wget --no-verbose https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - -cache: - directories: - - $HOME/.composer/cache/files - -notifications: - irc: "irc.freenode.org#phpdocumentor" - slack: - secure: "fjumM0h+4w3EYM4dpgqvpiCug7m4sSIC5+HATgwga/Nrc6IjlbWvGOv3JPgD3kQUhi18VmZfUYPmCv916SIbMnv8JWcrSaJXnPCgmxidvYkuzQDIw1HDJbVppGnkmwQA/qjIrM3sIEMfnu/arLRJQLI363aStZzGPxwIa4PDKcg=" - email: - - me@mikevanriel.com - - ashnazg@php.net diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 2a650d9..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,54 +0,0 @@ -build: false -clone_folder: c:\reflectiondocblock -max_jobs: 3 -platform: x86 -pull_requests: - do_not_increment_build_number: true -version: '{build}.{branch}' -skip_tags: true -branches: - only: - - master - -environment: - matrix: - - php_ver_target: 7.1 - - php_ver_target: 7.2 -matrix: - fast_finish: false - -cache: - - c:\php -> appveyor.yml - - '%LOCALAPPDATA%\Composer\files' - -init: - - SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH% - - SET COMPOSER_NO_INTERACTION=1 - - SET PHP=1 - - SET ANSICON=121x90 (121x90) - - -install: - - IF EXIST c:\tools\php (SET PHP=0) - - ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','') - - cd c:\tools\php - - IF %PHP%==1 copy /Y php.ini-development php.ini - - IF %PHP%==1 echo max_execution_time=1200 >> php.ini - - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - - IF %PHP%==1 echo extension_dir=ext >> php.ini - - IF %PHP%==1 echo extension=php_curl.dll >> php.ini - - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini - - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini - - IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini - - IF %PHP%==1 echo zend.assertions=1 >> php.ini - - IF %PHP%==1 echo assert.exception=On >> php.ini - - IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat - - appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar - - cd c:\reflectiondocblock - - composer install --no-interaction --prefer-dist --no-progress - - composer global require phpunit/phpunit ^6 - - composer global config bin-dir --absolute - -test_script: - - cd c:\reflectiondocblock - - c:\Users\appveyor\AppData\Roaming\Composer\vendor\bin\phpunit --no-coverage From 043df2c565a2d355c49ba559ebadd8c548e2a8f9 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 13 Dec 2019 15:31:58 +0100 Subject: [PATCH 10/10] remove bc check for now --- .github/workflows/push.yml | 17 ----------------- Makefile | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index dedadea..d3ead8a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -194,20 +194,3 @@ jobs: uses: docker://mickaelandrieu/psalm-ga env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - bc_check: - name: BC Check - runs-on: ubuntu-latest - needs: [setup, phpunit] - steps: - - uses: actions/checkout@master - - name: Restore/cache vendor folder - uses: actions/cache@v1 - with: - path: vendor - key: all-build-${{ hashFiles('**/composer.lock') }} - restore-keys: | - all-build-${{ hashFiles('**/composer.lock') }} - all-build- - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga diff --git a/Makefile b/Makefile index 374f1bd..b83dd98 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ phpcs: .PHONY: phpstan phpstan: - docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpstan-ga:latest analyse src --debug --no-progress --level max --configuration phpstan.neon + docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --level max --configuration phpstan.neon .PHONY: psaml psalm: