Apply new code style

This commit is contained in:
Jaapio
2019-09-20 10:54:12 +02:00
parent 8fcadfe5f8
commit aee984014b
71 changed files with 1661 additions and 1286 deletions
+8 -7
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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();
}
+22 -11
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,14 +8,24 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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);
+22 -13
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,14 +8,21 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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',
+54 -32
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,14 +8,19 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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;
+69 -52
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,18 +8,26 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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
+6 -6
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+31 -32
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,13 +8,12 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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;
}
+18 -11
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,13 +8,18 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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);
}
+9 -6
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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();
+10 -8
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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() : '');
}
+11 -9
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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() : '');
}
+33 -29
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,24 +8,27 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+3 -3
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
-19
View File
@@ -1,19 +0,0 @@
<?php declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+4 -4
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+13 -8
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Jan Schneider <[email protected]>
* @copyright 2018 Mike van Riel<[email protected]>
* @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;
}
}
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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);
}
}
+13 -12
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,18 +8,18 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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.'
);
+19 -14
View File
@@ -1,14 +1,14 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* phpDocumentor
* This file is part of phpDocumentor.
*
* PHP Version 5.3
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Ben Selby <[email protected]>
* @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() : '');
}
+43 -22
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,13 +8,12 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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));
+34 -21
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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 : '');
}
}
+19 -13
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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 : '');
}
}
+19 -13
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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 : '');
}
}
+19 -13
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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 : '');
}
}
+7 -12
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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;
}
+6 -6
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,17 +8,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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;
}
+7 -12
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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;
}
+10 -8
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+12 -9
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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() : '');
}
+11 -9
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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() : '');
}
+18 -13
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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() : '');
}
}
+10 -8
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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;
}
+10 -8
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,9 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
* @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();
}
+17 -11
View File
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
@@ -6,8 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2018 Mike van Riel<[email protected]>
* @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))
+14 -12
View File
@@ -1,14 +1,14 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* phpDocumentor
* This file is part of phpDocumentor.
*
* PHP Version 5.3
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Vasil Rangelov <[email protected]>
* @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() : '');
}