add strict_types and typehints

This commit is contained in:
TomasVotruba
2017-11-30 10:27:01 +01:00
committed by Jaap van Otterdijk
parent 94fd000123
commit d874c4d14a
38 changed files with 230 additions and 215 deletions
+13 -15
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -40,7 +41,6 @@ final class DocBlock
/** /**
* @param string $summary * @param string $summary
* @param DocBlock\Description $description
* @param DocBlock\Tag[] $tags * @param DocBlock\Tag[] $tags
* @param Types\Context $context The context in which the DocBlock occurs. * @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 Location $location The location within the file that this DocBlock occurs in.
@@ -48,13 +48,13 @@ final class DocBlock
* @param bool $isTemplateEnd * @param bool $isTemplateEnd
*/ */
public function __construct( public function __construct(
$summary = '', string $summary = '',
DocBlock\Description $description = null, DocBlock\Description $description = null,
array $tags = [], array $tags = [],
Types\Context $context = null, Types\Context $context = null,
Location $location = null, Location $location = null,
$isTemplateStart = false, bool $isTemplateStart = false,
$isTemplateEnd = false bool $isTemplateEnd = false
) { ) {
Assert::string($summary); Assert::string($summary);
Assert::boolean($isTemplateStart); Assert::boolean($isTemplateStart);
@@ -77,7 +77,7 @@ final class DocBlock
/** /**
* @return string * @return string
*/ */
public function getSummary() public function getSummary(): string
{ {
return $this->summary; return $this->summary;
} }
@@ -85,7 +85,7 @@ final class DocBlock
/** /**
* @return DocBlock\Description * @return DocBlock\Description
*/ */
public function getDescription() public function getDescription(): DocBlock\Description
{ {
return $this->description; return $this->description;
} }
@@ -95,7 +95,7 @@ final class DocBlock
* *
* @return Types\Context * @return Types\Context
*/ */
public function getContext() public function getContext(): Types\Context
{ {
return $this->context; return $this->context;
} }
@@ -105,7 +105,7 @@ final class DocBlock
* *
* @return Location * @return Location
*/ */
public function getLocation() public function getLocation(): Location
{ {
return $this->location; return $this->location;
} }
@@ -131,7 +131,7 @@ final class DocBlock
* *
* @return boolean * @return boolean
*/ */
public function isTemplateStart() public function isTemplateStart(): bool
{ {
return $this->isTemplateStart; return $this->isTemplateStart;
} }
@@ -143,7 +143,7 @@ final class DocBlock
* *
* @return boolean * @return boolean
*/ */
public function isTemplateEnd() public function isTemplateEnd(): bool
{ {
return $this->isTemplateEnd; return $this->isTemplateEnd;
} }
@@ -166,7 +166,7 @@ final class DocBlock
* *
* @return Tag[] * @return Tag[]
*/ */
public function getTagsByName($name) public function getTagsByName(string $name)
{ {
Assert::string($name); Assert::string($name);
@@ -191,7 +191,7 @@ final class DocBlock
* *
* @return bool * @return bool
*/ */
public function hasTag($name) public function hasTag(string $name): bool
{ {
Assert::string($name); Assert::string($name);
@@ -210,7 +210,6 @@ final class DocBlock
* *
* @param Tag $tag The tag to remove. * @param Tag $tag The tag to remove.
* *
* @return void
*/ */
public function removeTag(Tag $tagToRemove) public function removeTag(Tag $tagToRemove)
{ {
@@ -227,7 +226,6 @@ final class DocBlock
* *
* @param Tag $tag The tag to add. * @param Tag $tag The tag to add.
* *
* @return void
*/ */
private function addTag(Tag $tag) private function addTag(Tag $tag)
{ {
+5 -7
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -62,10 +63,8 @@ class Description
* @param string $bodyTemplate * @param string $bodyTemplate
* @param Tag[] $tags * @param Tag[] $tags
*/ */
public function __construct($bodyTemplate, array $tags = []) public function __construct(string $bodyTemplate, array $tags = [])
{ {
Assert::string($bodyTemplate);
$this->bodyTemplate = $bodyTemplate; $this->bodyTemplate = $bodyTemplate;
$this->tags = $tags; $this->tags = $tags;
} }
@@ -84,11 +83,10 @@ class Description
* Renders this description as a string where the provided formatter will format the tags in the expected string * Renders this description as a string where the provided formatter will format the tags in the expected string
* format. * format.
* *
* @param Formatter|null $formatter
* *
* @return string * @return string
*/ */
public function render(Formatter $formatter = null) public function render(Formatter $formatter = null): string
{ {
if ($formatter === null) { if ($formatter === null) {
$formatter = new PassthroughFormatter(); $formatter = new PassthroughFormatter();
@@ -107,7 +105,7 @@ class Description
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->render(); return $this->render();
} }
+6 -8
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -39,7 +40,6 @@ class DescriptionFactory
/** /**
* Initializes this factory with the means to construct (inline) tags. * Initializes this factory with the means to construct (inline) tags.
* *
* @param TagFactory $tagFactory
*/ */
public function __construct(TagFactory $tagFactory) public function __construct(TagFactory $tagFactory)
{ {
@@ -50,11 +50,10 @@ class DescriptionFactory
* Returns the parsed text of this description. * Returns the parsed text of this description.
* *
* @param string $contents * @param string $contents
* @param TypeContext $context
* *
* @return Description * @return Description
*/ */
public function create($contents, TypeContext $context = null) public function create(string $contents, TypeContext $context = null): Description
{ {
list($text, $tags) = $this->parse($this->lex($contents), $context); list($text, $tags) = $this->parse($this->lex($contents), $context);
@@ -68,7 +67,7 @@ class DescriptionFactory
* *
* @return string[] A series of tokens of which the description text is composed. * @return string[] A series of tokens of which the description text is composed.
*/ */
private function lex($contents) private function lex(string $contents)
{ {
$contents = $this->removeSuperfluousStartingWhitespace($contents); $contents = $this->removeSuperfluousStartingWhitespace($contents);
@@ -103,7 +102,7 @@ class DescriptionFactory
) )
\}/Sux', \}/Sux',
$contents, $contents,
null, 0,
PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_DELIM_CAPTURE
); );
} }
@@ -112,7 +111,6 @@ class DescriptionFactory
* Parses the stream of tokens in to a new set of tokens containing Tags. * Parses the stream of tokens in to a new set of tokens containing Tags.
* *
* @param string[] $tokens * @param string[] $tokens
* @param TypeContext $context
* *
* @return string[]|Tag[] * @return string[]|Tag[]
*/ */
@@ -156,7 +154,7 @@ class DescriptionFactory
* *
* @return string * @return string
*/ */
private function removeSuperfluousStartingWhitespace($contents) private function removeSuperfluousStartingWhitespace(string $contents): string
{ {
$lines = explode("\n", $contents); $lines = explode("\n", $contents);
+9 -10
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -28,11 +29,10 @@ class ExampleFinder
/** /**
* Attempts to find the example contents for the given descriptor. * Attempts to find the example contents for the given descriptor.
* *
* @param Example $example
* *
* @return string * @return string
*/ */
public function find(Example $example) public function find(Example $example): string
{ {
$filename = $example->getFilePath(); $filename = $example->getFilePath();
@@ -49,9 +49,8 @@ class ExampleFinder
* *
* @param string $directory * @param string $directory
* *
* @return void
*/ */
public function setSourceDirectory($directory = '') public function setSourceDirectory(string $directory = '')
{ {
$this->sourceDirectory = $directory; $this->sourceDirectory = $directory;
} }
@@ -61,7 +60,7 @@ class ExampleFinder
* *
* @return string * @return string
*/ */
public function getSourceDirectory() public function getSourceDirectory(): string
{ {
return $this->sourceDirectory; return $this->sourceDirectory;
} }
@@ -101,7 +100,7 @@ class ExampleFinder
* *
* @return string|null * @return string|null
*/ */
private function getExampleFileContents($filename) private function getExampleFileContents(string $filename)
{ {
$normalizedPath = null; $normalizedPath = null;
@@ -133,7 +132,7 @@ class ExampleFinder
* *
* @return string * @return string
*/ */
private function getExamplePathFromExampleDirectory($file) private function getExamplePathFromExampleDirectory(string $file): string
{ {
return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file;
} }
@@ -146,7 +145,7 @@ class ExampleFinder
* *
* @return string * @return string
*/ */
private function constructExamplePath($directory, $file) private function constructExamplePath(string $directory, string $file): string
{ {
return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file;
} }
@@ -158,7 +157,7 @@ class ExampleFinder
* *
* @return string * @return string
*/ */
private function getExamplePathFromSource($file) private function getExamplePathFromSource(string $file): string
{ {
return sprintf( return sprintf(
'%s%s%s', '%s%s%s',
+6 -7
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -44,7 +45,7 @@ class Serializer
* @param int|null $lineLength The max length of a line or NULL to disable line wrapping. * @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 DocBlock\Tags\Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter.
*/ */
public function __construct($indent = 0, $indentString = ' ', $indentFirstLine = true, $lineLength = null, $tagFormatter = null) public function __construct(int $indent = 0, string $indentString = ' ', bool $indentFirstLine = true, int $lineLength = null, DocBlock\Tags\Formatter $tagFormatter = null)
{ {
Assert::integer($indent); Assert::integer($indent);
Assert::string($indentString); Assert::string($indentString);
@@ -66,7 +67,7 @@ class Serializer
* *
* @return string The serialized doc block. * @return string The serialized doc block.
*/ */
public function getDocComment(DocBlock $docblock) public function getDocComment(DocBlock $docblock): string
{ {
$indent = str_repeat($this->indentString, $this->indent); $indent = str_repeat($this->indentString, $this->indent);
$firstIndent = $this->isFirstLineIndented ? $indent : ''; $firstIndent = $this->isFirstLineIndented ? $indent : '';
@@ -114,11 +115,10 @@ class Serializer
} }
/** /**
* @param DocBlock $docblock
* @param $wrapLength * @param $wrapLength
* @return string * @return string
*/ */
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength) private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength): string
{ {
$text = $docblock->getSummary() . ((string)$docblock->getDescription() ? "\n\n" . $docblock->getDescription() $text = $docblock->getSummary() . ((string)$docblock->getDescription() ? "\n\n" . $docblock->getDescription()
: ''); : '');
@@ -131,13 +131,12 @@ class Serializer
} }
/** /**
* @param DocBlock $docblock
* @param $wrapLength * @param $wrapLength
* @param $indent * @param $indent
* @param $comment * @param $comment
* @return string * @return string
*/ */
private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment) private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment): string
{ {
foreach ($docblock->getTags() as $tag) { foreach ($docblock->getTags() as $tag) {
$tagText = $this->tagFormatter->format($tag); $tagText = $this->tagFormatter->format($tag);
+11 -13
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -87,7 +88,6 @@ final class StandardTagFactory implements TagFactory
* If no tag handlers are provided than the default list in the {@see self::$tagHandlerMappings} property * If no tag handlers are provided than the default list in the {@see self::$tagHandlerMappings} property
* is used. * is used.
* *
* @param FqsenResolver $fqsenResolver
* @param string[] $tagHandlers * @param string[] $tagHandlers
* *
* @see self::registerTagHandler() to add a new tag handler to the existing default list. * @see self::registerTagHandler() to add a new tag handler to the existing default list.
@@ -105,7 +105,7 @@ final class StandardTagFactory implements TagFactory
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function create($tagLine, TypeContext $context = null) public function create(string $tagLine, TypeContext $context = null): Tag
{ {
if (! $context) { if (! $context) {
$context = new TypeContext(''); $context = new TypeContext('');
@@ -125,7 +125,7 @@ final class StandardTagFactory implements TagFactory
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function addParameter($name, $value) public function addParameter(string $name, $value)
{ {
$this->serviceLocator[$name] = $value; $this->serviceLocator[$name] = $value;
} }
@@ -141,7 +141,7 @@ final class StandardTagFactory implements TagFactory
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function registerTagHandler($tagName, $handler) public function registerTagHandler(string $tagName, string $handler)
{ {
Assert::stringNotEmpty($tagName); Assert::stringNotEmpty($tagName);
Assert::stringNotEmpty($handler); Assert::stringNotEmpty($handler);
@@ -164,7 +164,7 @@ final class StandardTagFactory implements TagFactory
* *
* @return string[] * @return string[]
*/ */
private function extractTagParts($tagLine) private function extractTagParts(string $tagLine)
{ {
$matches = []; $matches = [];
if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) {
@@ -186,11 +186,10 @@ final class StandardTagFactory implements TagFactory
* *
* @param string $body * @param string $body
* @param string $name * @param string $name
* @param TypeContext $context
* *
* @return Tag|null * @return Tag|null
*/ */
private function createTag($body, $name, TypeContext $context) private function createTag(string $body, string $name, TypeContext $context)
{ {
$handlerClassName = $this->findHandlerClassName($name, $context); $handlerClassName = $this->findHandlerClassName($name, $context);
$arguments = $this->getArgumentsForParametersFromWiring( $arguments = $this->getArgumentsForParametersFromWiring(
@@ -205,11 +204,10 @@ final class StandardTagFactory implements TagFactory
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
* *
* @param string $tagName * @param string $tagName
* @param TypeContext $context
* *
* @return string * @return string
*/ */
private function findHandlerClassName($tagName, TypeContext $context) private function findHandlerClassName(string $tagName, TypeContext $context): string
{ {
$handlerClassName = Generic::class; $handlerClassName = Generic::class;
if (isset($this->tagHandlerMappings[$tagName])) { if (isset($this->tagHandlerMappings[$tagName])) {
@@ -264,7 +262,7 @@ final class StandardTagFactory implements TagFactory
* *
* @return \ReflectionParameter[] * @return \ReflectionParameter[]
*/ */
private function fetchParametersForHandlerFactoryMethod($handlerClassName) private function fetchParametersForHandlerFactoryMethod(string $handlerClassName)
{ {
if (! isset($this->tagHandlerParameterCache[$handlerClassName])) { if (! isset($this->tagHandlerParameterCache[$handlerClassName])) {
$methodReflection = new \ReflectionMethod($handlerClassName, 'create'); $methodReflection = new \ReflectionMethod($handlerClassName, 'create');
@@ -284,7 +282,7 @@ final class StandardTagFactory implements TagFactory
* *
* @return mixed[] * @return mixed[]
*/ */
private function getServiceLocatorWithDynamicParameters(TypeContext $context, $tagName, $tagBody) private function getServiceLocatorWithDynamicParameters(TypeContext $context, string $tagName, string $tagBody)
{ {
$locator = array_merge( $locator = array_merge(
$this->serviceLocator, $this->serviceLocator,
@@ -307,7 +305,7 @@ final class StandardTagFactory implements TagFactory
* *
* @return bool * @return bool
*/ */
private function isAnnotation($tagContent) private function isAnnotation(string $tagContent): bool
{ {
// 1. Contains a namespace separator // 1. Contains a namespace separator
// 2. Contains parenthesis // 2. Contains parenthesis
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -18,7 +19,7 @@ interface Tag
{ {
public function getName(); public function getName();
public static function create($body); public static function create(string $body);
public function render(Formatter $formatter = null); public function render(Formatter $formatter = null);
+5 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -39,7 +40,7 @@ interface TagFactory
* *
* @return void * @return void
*/ */
public function addParameter($name, $value); public function addParameter(string $name, $value);
/** /**
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided. * Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
@@ -61,13 +62,12 @@ interface TagFactory
* Factory method responsible for instantiating the correct sub type. * Factory method responsible for instantiating the correct sub type.
* *
* @param string $tagLine The text for this tag, including description. * @param string $tagLine The text for this tag, including description.
* @param TypeContext $context
* *
* @throws \InvalidArgumentException if an invalid tag line was presented. * @throws \InvalidArgumentException if an invalid tag line was presented.
* *
* @return Tag A new tag object. * @return Tag A new tag object.
*/ */
public function create($tagLine, TypeContext $context = null); public function create(string $tagLine, TypeContext $context = null): Tag;
/** /**
* Registers a handler for tags. * Registers a handler for tags.
@@ -89,5 +89,5 @@ interface TagFactory
* *
* @return void * @return void
*/ */
public function registerTagHandler($tagName, $handler); public function registerTagHandler(string $tagName, string $handler);
} }
+7 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -34,7 +35,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
* @param string $authorName * @param string $authorName
* @param string $authorEmail * @param string $authorEmail
*/ */
public function __construct($authorName, $authorEmail) public function __construct(string $authorName, string $authorEmail)
{ {
Assert::string($authorName); Assert::string($authorName);
Assert::string($authorEmail); Assert::string($authorEmail);
@@ -51,7 +52,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
* *
* @return string The author's name. * @return string The author's name.
*/ */
public function getAuthorName() public function getAuthorName(): string
{ {
return $this->authorName; return $this->authorName;
} }
@@ -61,7 +62,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
* *
* @return string The author's email. * @return string The author's email.
*/ */
public function getEmail() public function getEmail(): string
{ {
return $this->authorEmail; return $this->authorEmail;
} }
@@ -71,7 +72,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : ''); return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : '');
} }
@@ -83,7 +84,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
* *
* @return static * @return static
*/ */
public static function create($body) public static function create(string $body)
{ {
Assert::string($body); Assert::string($body);
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -31,7 +32,7 @@ abstract class BaseTag implements DocBlock\Tag
* *
* @return string The name of this tag. * @return string The name of this tag.
*/ */
public function getName() public function getName(): string
{ {
return $this->name; return $this->name;
} }
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -32,7 +33,6 @@ final class Covers extends BaseTag implements Factory\StaticMethod
/** /**
* Initializes this tag. * Initializes this tag.
* *
* @param Fqsen $refers
* @param Description $description * @param Description $description
*/ */
public function __construct(Fqsen $refers, Description $description = null) public function __construct(Fqsen $refers, Description $description = null)
@@ -45,7 +45,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
FqsenResolver $resolver = null, FqsenResolver $resolver = null,
TypeContext $context = null TypeContext $context = null
@@ -57,7 +57,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
return new static( return new static(
$resolver->resolve($parts[0], $context), $resolver->resolve($parts[0], $context),
$descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) $descriptionFactory->create($parts[1] ?? '', $context)
); );
} }
@@ -66,7 +66,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
* *
* @return Fqsen * @return Fqsen
*/ */
public function getReference() public function getReference(): Fqsen
{ {
return $this->refers; return $this->refers;
} }
@@ -76,7 +76,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
} }
+10 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -54,8 +55,11 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
/** /**
* @return static * @return static
*/ */
public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) public static function create(
{ string $body,
DescriptionFactory $descriptionFactory = null,
TypeContext $context = null
) {
Assert::nullOrString($body); Assert::nullOrString($body);
if (empty($body)) { if (empty($body)) {
return new static(); return new static();
@@ -71,7 +75,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
return new static( return new static(
$matches[1], $matches[1],
$descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context) $descriptionFactory->create($matches[2] ?? '', $context)
); );
} }
@@ -80,7 +84,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVersion() public function getVersion(): string
{ {
return $this->version; return $this->version;
} }
@@ -90,7 +94,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->version . ($this->description ? ' ' . $this->description->render() : ''); return $this->version . ($this->description ? ' ' . $this->description->render() : '');
} }
+10 -10
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -42,10 +43,9 @@ final class Example extends BaseTag
*/ */
private $lineCount; private $lineCount;
public function __construct($filePath, $isURI, $startingLine, $lineCount, $description) public function __construct(string $filePath, bool $isURI, int $startingLine, $lineCount, $description)
{ {
Assert::notEmpty($filePath); Assert::notEmpty($filePath);
Assert::integer($startingLine);
Assert::greaterThanEq($startingLine, 0); Assert::greaterThanEq($startingLine, 0);
$this->filePath = $filePath; $this->filePath = $filePath;
@@ -53,7 +53,7 @@ final class Example extends BaseTag
$this->lineCount = $lineCount; $this->lineCount = $lineCount;
$this->name = 'example'; $this->name = 'example';
if ($description !== null) { if ($description !== null) {
$this->description = trim($description); $this->description = trim((string) $description);
} }
$this->isURI = $isURI; $this->isURI = $isURI;
@@ -81,7 +81,7 @@ final class Example extends BaseTag
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create($body) public static function create(string $body)
{ {
// File component: File path in quotes or File URI / Source information // 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)) {
@@ -131,7 +131,7 @@ final class Example extends BaseTag
* @return string Path to a file to use as an example. * @return string Path to a file to use as an example.
* May also be an absolute URI. * May also be an absolute URI.
*/ */
public function getFilePath() public function getFilePath(): string
{ {
return $this->filePath; return $this->filePath;
} }
@@ -141,7 +141,7 @@ final class Example extends BaseTag
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->filePath . ($this->description ? ' ' . $this->description : ''); return $this->filePath . ($this->description ? ' ' . $this->description : '');
} }
@@ -153,7 +153,7 @@ final class Example extends BaseTag
* *
* @return bool * @return bool
*/ */
private function isUriRelative($uri) private function isUriRelative(string $uri): bool
{ {
return false === strpos($uri, ':'); return false === strpos($uri, ':');
} }
@@ -161,7 +161,7 @@ final class Example extends BaseTag
/** /**
* @return int * @return int
*/ */
public function getStartingLine() public function getStartingLine(): int
{ {
return $this->startingLine; return $this->startingLine;
} }
@@ -169,7 +169,7 @@ final class Example extends BaseTag
/** /**
* @return int * @return int
*/ */
public function getLineCount() public function getLineCount(): int
{ {
return $this->lineCount; return $this->lineCount;
} }
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -14,5 +15,5 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
interface StaticMethod interface StaticMethod
{ {
public static function create($body); public static function create(string $body);
} }
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
+3 -3
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -19,9 +20,8 @@ interface Formatter
/** /**
* Formats a tag into a string representation according to a specific format, such as Markdown. * Formats a tag into a string representation according to a specific format, such as Markdown.
* *
* @param Tag $tag
* *
* @return string * @return string
*/ */
public function format(Tag $tag); public function format(Tag $tag): string;
} }
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -36,11 +37,10 @@ class AlignFormatter implements Formatter
/** /**
* Formats the given tag to return a simple plain text version. * Formats the given tag to return a simple plain text version.
* *
* @param Tag $tag
* *
* @return string * @return string
*/ */
public function format(Tag $tag) 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) . (string)$tag;
} }
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -20,11 +21,10 @@ class PassthroughFormatter implements Formatter
/** /**
* Formats the given tag to return a simple plain text version. * Formats the given tag to return a simple plain text version.
* *
* @param Tag $tag
* *
* @return string * @return string
*/ */
public function format(Tag $tag) public function format(Tag $tag): string
{ {
return trim('@' . $tag->getName() . ' ' . (string)$tag); return trim('@' . $tag->getName() . ' ' . (string)$tag);
} }
+7 -8
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -29,7 +30,7 @@ class Generic extends BaseTag implements Factory\StaticMethod
* @param string $name Name of the tag. * @param string $name Name of the tag.
* @param Description $description The contents of the given tag. * @param Description $description The contents of the given tag.
*/ */
public function __construct($name, Description $description = null) public function __construct(string $name, Description $description = null)
{ {
$this->validateTagName($name); $this->validateTagName($name);
@@ -42,14 +43,13 @@ class Generic extends BaseTag implements Factory\StaticMethod
* *
* @param string $body * @param string $body
* @param string $name * @param string $name
* @param DescriptionFactory $descriptionFactory
* @param TypeContext $context * @param TypeContext $context
* *
* @return static * @return static
*/ */
public static function create( public static function create(
$body, string $body,
$name = '', string $name = '',
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
) { ) {
@@ -67,7 +67,7 @@ class Generic extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->description ? $this->description->render() : ''); return ($this->description ? $this->description->render() : '');
} }
@@ -77,9 +77,8 @@ class Generic extends BaseTag implements Factory\StaticMethod
* *
* @param string $name * @param string $name
* *
* @return void
*/ */
private function validateTagName($name) private function validateTagName(string $name)
{ {
if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
@@ -31,9 +32,8 @@ final class Link extends BaseTag implements Factory\StaticMethod
* Initializes a link to a URL. * Initializes a link to a URL.
* *
* @param string $link * @param string $link
* @param Description $description
*/ */
public function __construct($link, Description $description = null) public function __construct(string $link, Description $description = null)
{ {
Assert::string($link); Assert::string($link);
@@ -44,7 +44,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) public static function create(string $body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
{ {
Assert::string($body); Assert::string($body);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
@@ -60,7 +60,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getLink() public function getLink(): string
{ {
return $this->link; return $this->link;
} }
@@ -70,7 +70,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->link . ($this->description ? ' ' . $this->description->render() : ''); return $this->link . ($this->description ? ' ' . $this->description->render() : '');
} }
+6 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -64,7 +65,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -163,7 +164,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getMethodName() public function getMethodName(): string
{ {
return $this->methodName; return $this->methodName;
} }
@@ -181,7 +182,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
* *
* @return bool TRUE if the method declaration is for a static method, FALSE otherwise. * @return bool TRUE if the method declaration is for a static method, FALSE otherwise.
*/ */
public function isStatic() public function isStatic(): bool
{ {
return $this->isStatic; return $this->isStatic;
} }
@@ -189,7 +190,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
/** /**
* @return Type * @return Type
*/ */
public function getReturnType() public function getReturnType(): Type
{ {
return $this->returnType; return $this->returnType;
} }
+7 -7
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -38,11 +39,10 @@ final class Param extends BaseTag implements Factory\StaticMethod
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type
* @param bool $isVariadic * @param bool $isVariadic
* @param Description $description * @param Description $description
*/ */
public function __construct($variableName, Type $type = null, $isVariadic = false, Description $description = null) public function __construct(string $variableName, Type $type = null, bool $isVariadic = false, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
Assert::boolean($isVariadic); Assert::boolean($isVariadic);
@@ -57,7 +57,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -101,7 +101,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVariableName() public function getVariableName(): string
{ {
return $this->variableName; return $this->variableName;
} }
@@ -121,7 +121,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
* *
* @return boolean * @return boolean
*/ */
public function isVariadic() public function isVariadic(): bool
{ {
return $this->isVariadic; return $this->isVariadic;
} }
@@ -131,7 +131,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. ($this->isVariadic() ? '...' : '') . ($this->isVariadic() ? '...' : '')
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -36,9 +37,8 @@ class Property extends BaseTag implements Factory\StaticMethod
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct(string $variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
@@ -51,7 +51,7 @@ class Property extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -89,7 +89,7 @@ class Property extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVariableName() public function getVariableName(): string
{ {
return $this->variableName; return $this->variableName;
} }
@@ -109,7 +109,7 @@ class Property extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -36,9 +37,8 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct(string $variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
@@ -51,7 +51,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -89,7 +89,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVariableName() public function getVariableName(): string
{ {
return $this->variableName; return $this->variableName;
} }
@@ -109,7 +109,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -36,9 +37,8 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct(string $variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
@@ -51,7 +51,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -89,7 +89,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVariableName() public function getVariableName(): string
{ {
return $this->variableName; return $this->variableName;
} }
@@ -109,7 +109,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -35,7 +36,7 @@ final class Fqsen implements Reference
/** /**
* @return string string representation of the referenced fqsen * @return string string representation of the referenced fqsen
*/ */
public function __toString() public function __toString(): string
{ {
return (string)$this->fqsen; return (string)$this->fqsen;
} }
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
+6 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -39,7 +40,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -49,8 +50,8 @@ final class Return_ extends BaseTag implements Factory\StaticMethod
$parts = preg_split('/\s+/Su', $body, 2); $parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context); $type = $typeResolver->resolve($parts[0] ?? '', $context);
$description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context);
return new static($type, $description); return new static($type, $description);
} }
@@ -60,7 +61,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod
* *
* @return Type * @return Type
*/ */
public function getType() public function getType(): Type
{ {
return $this->type; return $this->type;
} }
+5 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -34,7 +35,6 @@ class See extends BaseTag implements Factory\StaticMethod
/** /**
* Initializes this tag. * Initializes this tag.
* *
* @param Reference $refers
* @param Description $description * @param Description $description
*/ */
public function __construct(Reference $refers, Description $description = null) public function __construct(Reference $refers, Description $description = null)
@@ -47,7 +47,7 @@ class See extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
FqsenResolver $resolver = null, FqsenResolver $resolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -71,7 +71,7 @@ class See extends BaseTag implements Factory\StaticMethod
* *
* @return Reference * @return Reference
*/ */
public function getReference() public function getReference(): Reference
{ {
return $this->refers; return $this->refers;
} }
@@ -81,7 +81,7 @@ class See extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
} }
+10 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -54,8 +55,11 @@ final class Since extends BaseTag implements Factory\StaticMethod
/** /**
* @return static * @return static
*/ */
public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) public static function create(
{ string $body,
DescriptionFactory $descriptionFactory = null,
TypeContext $context = null
) {
Assert::nullOrString($body); Assert::nullOrString($body);
if (empty($body)) { if (empty($body)) {
return new static(); return new static();
@@ -68,7 +72,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
return new static( return new static(
$matches[1], $matches[1],
$descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context) $descriptionFactory->create($matches[2] ?? '', $context)
); );
} }
@@ -77,7 +81,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVersion() public function getVersion(): string
{ {
return $this->version; return $this->version;
} }
@@ -87,7 +91,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->version . ($this->description ? ' ' . $this->description->render() : ''); return $this->version . ($this->description ? ' ' . $this->description->render() : '');
} }
+8 -4
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -44,8 +45,11 @@ final class Source extends BaseTag implements Factory\StaticMethod
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) public static function create(
{ string $body,
DescriptionFactory $descriptionFactory = null,
TypeContext $context = null
) {
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
@@ -72,7 +76,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
* @return int The starting line, relative to the structural element's * @return int The starting line, relative to the structural element's
* location. * location.
*/ */
public function getStartingLine() public function getStartingLine(): int
{ {
return $this->startingLine; return $this->startingLine;
} }
+6 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -39,7 +40,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -49,8 +50,8 @@ final class Throws extends BaseTag implements Factory\StaticMethod
$parts = preg_split('/\s+/Su', $body, 2); $parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context); $type = $typeResolver->resolve($parts[0] ?? '', $context);
$description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context); $description = $descriptionFactory->create($parts[1] ?? '', $context);
return new static($type, $description); return new static($type, $description);
} }
@@ -60,7 +61,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod
* *
* @return Type * @return Type
*/ */
public function getType() public function getType(): Type
{ {
return $this->type; return $this->type;
} }
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -33,7 +34,6 @@ final class Uses extends BaseTag implements Factory\StaticMethod
* Initializes this tag. * Initializes this tag.
* *
* @param Fqsen $refers * @param Fqsen $refers
* @param Description $description
*/ */
public function __construct(Fqsen $refers, Description $description = null) public function __construct(Fqsen $refers, Description $description = null)
{ {
@@ -45,7 +45,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
FqsenResolver $resolver = null, FqsenResolver $resolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -57,7 +57,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
return new static( return new static(
$resolver->resolve($parts[0], $context), $resolver->resolve($parts[0], $context),
$descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) $descriptionFactory->create($parts[1] ?? '', $context)
); );
} }
@@ -66,7 +66,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
* *
* @return Fqsen * @return Fqsen
*/ */
public function getReference() public function getReference(): Fqsen
{ {
return $this->refers; return $this->refers;
} }
@@ -76,7 +76,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->refers . ' ' . $this->description->render(); return $this->refers . ' ' . $this->description->render();
} }
+6 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -36,9 +37,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct(string $variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
@@ -51,7 +51,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create( public static function create(
$body, string $body,
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
@@ -89,7 +89,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVariableName() public function getVariableName(): string
{ {
return $this->variableName; return $this->variableName;
} }
@@ -109,7 +109,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. (empty($this->variableName) ? null : ('$' . $this->variableName)) . (empty($this->variableName) ? null : ('$' . $this->variableName))
+10 -6
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
@@ -54,8 +55,11 @@ final class Version extends BaseTag implements Factory\StaticMethod
/** /**
* @return static * @return static
*/ */
public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) public static function create(
{ string $body,
DescriptionFactory $descriptionFactory = null,
TypeContext $context = null
) {
Assert::nullOrString($body); Assert::nullOrString($body);
if (empty($body)) { if (empty($body)) {
return new static(); return new static();
@@ -68,7 +72,7 @@ final class Version extends BaseTag implements Factory\StaticMethod
return new static( return new static(
$matches[1], $matches[1],
$descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context) $descriptionFactory->create($matches[2] ?? '', $context)
); );
} }
@@ -77,7 +81,7 @@ final class Version extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function getVersion() public function getVersion(): string
{ {
return $this->version; return $this->version;
} }
@@ -87,7 +91,7 @@ final class Version extends BaseTag implements Factory\StaticMethod
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->version . ($this->description ? ' ' . $this->description->render() : ''); return $this->version . ($this->description ? ' ' . $this->description->render() : '');
} }
+9 -10
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
@@ -29,7 +30,6 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/** /**
* Initializes this factory with the required subcontractors. * Initializes this factory with the required subcontractors.
* *
* @param DescriptionFactory $descriptionFactory
* @param TagFactory $tagFactory * @param TagFactory $tagFactory
*/ */
public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory) public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory)
@@ -45,7 +45,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* *
* @return DocBlockFactory * @return DocBlockFactory
*/ */
public static function createInstance(array $additionalTags = []) public static function createInstance(array $additionalTags = []): DocBlockFactory
{ {
$fqsenResolver = new FqsenResolver(); $fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver); $tagFactory = new StandardTagFactory($fqsenResolver);
@@ -65,12 +65,11 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/** /**
* @param object|string $docblock A string containing the DocBlock to parse or an object supporting the * @param object|string $docblock A string containing the DocBlock to parse or an object supporting the
* getDocComment method (such as a ReflectionClass object). * getDocComment method (such as a ReflectionClass object).
* @param Types\Context $context
* @param Location $location * @param Location $location
* *
* @return DocBlock * @return DocBlock
*/ */
public function create($docblock, Types\Context $context = null, Location $location = null) public function create($docblock, Types\Context $context = null, Location $location = null): DocBlock
{ {
if (is_object($docblock)) { if (is_object($docblock)) {
if (!method_exists($docblock, 'getDocComment')) { if (!method_exists($docblock, 'getDocComment')) {
@@ -115,7 +114,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* *
* @return string * @return string
*/ */
private function stripDocComment($comment) private function stripDocComment(string $comment): string
{ {
$comment = trim(preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment)); $comment = trim(preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment));
@@ -137,7 +136,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* *
* @return string[] containing the template marker (if any), summary, description and a string containing the tags. * @return string[] containing the template marker (if any), summary, description and a string containing the tags.
*/ */
private function splitDocBlock($comment) private function splitDocBlock(string $comment)
{ {
// Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This // 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 // method does not split tags so we return this verbatim as the fourth result (tags). This saves us the
@@ -219,7 +218,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* *
* @return DocBlock\Tag[] * @return DocBlock\Tag[]
*/ */
private function parseTagBlock($tags, Types\Context $context) private function parseTagBlock(string $tags, Types\Context $context)
{ {
$tags = $this->filterTagBlock($tags); $tags = $this->filterTagBlock($tags);
if (!$tags) { if (!$tags) {
@@ -239,7 +238,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* *
* @return string[] * @return string[]
*/ */
private function splitTagBlockIntoTagLines($tags) private function splitTagBlockIntoTagLines(string $tags)
{ {
$result = []; $result = [];
foreach (explode("\n", $tags) as $tag_line) { foreach (explode("\n", $tags) as $tag_line) {
@@ -257,7 +256,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* @param $tags * @param $tags
* @return string * @return string
*/ */
private function filterTagBlock($tags) private function filterTagBlock($tags): string
{ {
$tags = trim($tags); $tags = trim($tags);
if (!$tags) { if (!$tags) {
+5 -5
View File
@@ -1,4 +1,5 @@
<?php <?php declare(strict_types=1);
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
interface DocBlockFactoryInterface interface DocBlockFactoryInterface
@@ -10,14 +11,13 @@ interface DocBlockFactoryInterface
* *
* @return DocBlockFactory * @return DocBlockFactory
*/ */
public static function createInstance(array $additionalTags = []); public static function createInstance(array $additionalTags = []): DocBlockFactory;
/** /**
* @param string $docblock * @param string|object $docblock
* @param Types\Context $context
* @param Location $location * @param Location $location
* *
* @return DocBlock * @return DocBlock
*/ */
public function create($docblock, Types\Context $context = null, Location $location = null); public function create($docblock, Types\Context $context = null, Location $location = null): DocBlock;
} }