dep: package update

This commit is contained in:
2021-11-08 16:10:01 +09:00
parent 38208750e7
commit 2c533d2ab3
783 changed files with 4581 additions and 20980 deletions
+3 -2
View File
@@ -21,7 +21,8 @@
"ext-filter": "*"
},
"require-dev": {
"mockery/mockery": "~1.3.2"
"mockery/mockery": "~1.3.2",
"psalm/phar": "^4.8"
},
"autoload": {
"psr-4": {
@@ -30,7 +31,7 @@
},
"autoload-dev": {
"psr-4": {
"phpDocumentor\\Reflection\\": "tests/unit"
"phpDocumentor\\Reflection\\": ["tests/unit", "tests/integration"]
}
},
"extra": {
+35 -11
View File
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
use Webmozart\Assert\Assert;
final class DocBlock
@@ -68,12 +69,12 @@ final class DocBlock
$this->isTemplateStart = $isTemplateStart;
}
public function getSummary() : string
public function getSummary(): string
{
return $this->summary;
}
public function getDescription() : DocBlock\Description
public function getDescription(): DocBlock\Description
{
return $this->description;
}
@@ -81,7 +82,7 @@ final class DocBlock
/**
* Returns the current context.
*/
public function getContext() : ?Types\Context
public function getContext(): ?Types\Context
{
return $this->context;
}
@@ -89,7 +90,7 @@ final class DocBlock
/**
* Returns the current location.
*/
public function getLocation() : ?Location
public function getLocation(): ?Location
{
return $this->location;
}
@@ -113,7 +114,7 @@ final class DocBlock
*
* @see self::isTemplateEnd() for the check whether a closing marker was provided.
*/
public function isTemplateStart() : bool
public function isTemplateStart(): bool
{
return $this->isTemplateStart;
}
@@ -123,7 +124,7 @@ final class DocBlock
*
* @see self::isTemplateStart() for a more complete description of the Docblock Template functionality.
*/
public function isTemplateEnd() : bool
public function isTemplateEnd(): bool
{
return $this->isTemplateEnd;
}
@@ -133,7 +134,7 @@ final class DocBlock
*
* @return Tag[]
*/
public function getTags() : array
public function getTags(): array
{
return $this->tags;
}
@@ -146,7 +147,7 @@ final class DocBlock
*
* @return Tag[]
*/
public function getTagsByName(string $name) : array
public function getTagsByName(string $name): array
{
$result = [];
@@ -161,12 +162,35 @@ final class DocBlock
return $result;
}
/**
* Returns an array of tags with type matching the given name. If no tags are found
* an empty array is returned.
*
* @param string $name String to search by.
*
* @return TagWithType[]
*/
public function getTagsWithTypeByName(string $name): array
{
$result = [];
foreach ($this->getTagsByName($name) as $tag) {
if (!$tag instanceof TagWithType) {
continue;
}
$result[] = $tag;
}
return $result;
}
/**
* Checks if a tag of a certain type is present in this DocBlock.
*
* @param string $name Tag name to check for.
*/
public function hasTag(string $name) : bool
public function hasTag(string $name): bool
{
foreach ($this->getTags() as $tag) {
if ($tag->getName() === $name) {
@@ -182,7 +206,7 @@ final class DocBlock
*
* @param Tag $tagToRemove The tag to remove.
*/
public function removeTag(Tag $tagToRemove) : void
public function removeTag(Tag $tagToRemove): void
{
foreach ($this->tags as $key => $tag) {
if ($tag === $tagToRemove) {
@@ -197,7 +221,7 @@ final class DocBlock
*
* @param Tag $tag The tag to add.
*/
private function addTag(Tag $tag) : void
private function addTag(Tag $tag): void
{
$this->tags[] = $tag;
}
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
use function vsprintf;
/**
@@ -71,7 +72,7 @@ class Description
/**
* Returns the body template.
*/
public function getBodyTemplate() : string
public function getBodyTemplate(): string
{
return $this->bodyTemplate;
}
@@ -81,7 +82,7 @@ class Description
*
* @return Tag[]
*/
public function getTags() : array
public function getTags(): array
{
return $this->tags;
}
@@ -90,7 +91,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();
@@ -107,7 +108,7 @@ class Description
/**
* Returns a plain string representation of this description.
*/
public function __toString() : string
public function __toString(): string
{
return $this->render();
}
@@ -15,8 +15,8 @@ namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use function count;
use function explode;
use function implode;
use function ltrim;
use function min;
@@ -25,6 +25,7 @@ use function strlen;
use function strpos;
use function substr;
use function trim;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -60,7 +61,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
{
$tokens = $this->lex($contents);
$count = count($tokens);
@@ -88,7 +89,7 @@ class DescriptionFactory
*
* @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);
@@ -142,9 +143,9 @@ 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);
$lines = Utils::pregSplit("/\r\n?|\n/", $contents);
// if there is only one line then we don't have lines with superfluous whitespace and
// can use the contents as-is
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tags\Example;
use function array_slice;
use function file;
use function getcwd;
@@ -22,6 +23,7 @@ use function is_readable;
use function rtrim;
use function sprintf;
use function trim;
use const DIRECTORY_SEPARATOR;
/**
@@ -38,7 +40,7 @@ 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();
@@ -53,7 +55,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;
}
@@ -61,7 +63,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;
}
@@ -71,7 +73,7 @@ class ExampleFinder
*
* @param string[] $directories
*/
public function setExampleDirectories(array $directories) : void
public function setExampleDirectories(array $directories): void
{
$this->exampleDirectories = $directories;
}
@@ -81,7 +83,7 @@ class ExampleFinder
*
* @return string[]
*/
public function getExampleDirectories() : array
public function getExampleDirectories(): array
{
return $this->exampleDirectories;
}
@@ -99,7 +101,7 @@ class ExampleFinder
*
* @return string[] all lines of the example file
*/
private function getExampleFileContents(string $filename) : ?array
private function getExampleFileContents(string $filename): ?array
{
$normalizedPath = null;
@@ -129,7 +131,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;
}
@@ -137,7 +139,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;
}
@@ -145,7 +147,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',
@@ -16,6 +16,7 @@ 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;
@@ -41,6 +42,8 @@ class Serializer
/** @var Formatter A custom tag formatter. */
protected $tagFormatter;
/** @var string */
private $lineEnding;
/**
* Create a Serializer instance.
@@ -50,19 +53,22 @@ class Serializer
* @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.
* @param string $lineEnding Line ending used in the output, by default \n is used.
*/
public function __construct(
int $indent = 0,
string $indentString = ' ',
bool $indentFirstLine = true,
?int $lineLength = null,
?Formatter $tagFormatter = null
?Formatter $tagFormatter = null,
string $lineEnding = "\n"
) {
$this->indent = $indent;
$this->indentString = $indentString;
$this->isFirstLineIndented = $indentFirstLine;
$this->lineLength = $lineLength;
$this->tagFormatter = $tagFormatter ?: new PassthroughFormatter();
$this->lineEnding = $lineEnding;
}
/**
@@ -72,7 +78,7 @@ 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);
$firstIndent = $this->isFirstLineIndented ? $indent : '';
@@ -95,10 +101,10 @@ class Serializer
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
return $comment . $indent . ' */';
return str_replace("\n", $this->lineEnding, $comment . $indent . ' */');
}
private function removeTrailingSpaces(string $indent, string $text) : string
private function removeTrailingSpaces(string $indent, string $text): string
{
return str_replace(
sprintf("\n%s * \n", $indent),
@@ -107,7 +113,7 @@ class Serializer
);
}
private function addAsterisksForEachLine(string $indent, string $text) : string
private function addAsterisksForEachLine(string $indent, string $text): string
{
return str_replace(
"\n",
@@ -116,7 +122,7 @@ class Serializer
);
}
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wrapLength) : string
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wrapLength): string
{
$text = $docblock->getSummary() . ((string) $docblock->getDescription() ? "\n\n" . $docblock->getDescription()
: '');
@@ -129,7 +135,7 @@ class Serializer
return $text;
}
private function addTagBlock(DocBlock $docblock, ?int $wrapLength, string $indent, string $comment) : string
private function addTagBlock(DocBlock $docblock, ?int $wrapLength, string $indent, string $comment): string
{
foreach ($docblock->getTags() as $tag) {
$tagText = $this->tagFormatter->format($tag);
@@ -39,6 +39,7 @@ use ReflectionMethod;
use ReflectionNamedType;
use ReflectionParameter;
use Webmozart\Assert\Assert;
use function array_merge;
use function array_slice;
use function call_user_func_array;
@@ -137,7 +138,7 @@ final class StandardTagFactory implements TagFactory
$this->addService($fqsenResolver, FqsenResolver::class);
}
public function create(string $tagLine, ?TypeContext $context = null) : Tag
public function create(string $tagLine, ?TypeContext $context = null): Tag
{
if (!$context) {
$context = new TypeContext('');
@@ -151,17 +152,17 @@ final class StandardTagFactory implements TagFactory
/**
* @param mixed $value
*/
public function addParameter(string $name, $value) : void
public function addParameter(string $name, $value): void
{
$this->serviceLocator[$name] = $value;
}
public function addService(object $service, ?string $alias = null) : void
public function addService(object $service, ?string $alias = null): void
{
$this->serviceLocator[$alias ?: get_class($service)] = $service;
}
public function registerTagHandler(string $tagName, string $handler) : void
public function registerTagHandler(string $tagName, string $handler): void
{
Assert::stringNotEmpty($tagName);
Assert::classExists($handler);
@@ -181,7 +182,7 @@ final class StandardTagFactory implements TagFactory
*
* @return string[]
*/
private function extractTagParts(string $tagLine) : array
private function extractTagParts(string $tagLine): array
{
$matches = [];
if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')((?:[\s\(\{])\s*([^\s].*)|$)/us', $tagLine, $matches)) {
@@ -201,7 +202,7 @@ 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(
@@ -226,7 +227,7 @@ final class StandardTagFactory implements TagFactory
*
* @return class-string<Tag>
*/
private function findHandlerClassName(string $tagName, TypeContext $context) : string
private function findHandlerClassName(string $tagName, TypeContext $context): string
{
$handlerClassName = Generic::class;
if (isset($this->tagHandlerMappings[$tagName])) {
@@ -251,7 +252,7 @@ final class StandardTagFactory implements TagFactory
* @return mixed[] A series of values that can be passed to the Factory Method of the tag whose parameters
* is provided with this method.
*/
private function getArgumentsForParametersFromWiring(array $parameters, array $locator) : array
private function getArgumentsForParametersFromWiring(array $parameters, array $locator): array
{
$arguments = [];
foreach ($parameters as $parameter) {
@@ -292,7 +293,7 @@ final class StandardTagFactory implements TagFactory
*
* @return ReflectionParameter[]
*/
private function fetchParametersForHandlerFactoryMethod(string $handlerClassName) : array
private function fetchParametersForHandlerFactoryMethod(string $handlerClassName): array
{
if (!isset($this->tagHandlerParameterCache[$handlerClassName])) {
$methodReflection = new ReflectionMethod($handlerClassName, 'create');
@@ -319,7 +320,7 @@ final class StandardTagFactory implements TagFactory
TypeContext $context,
string $tagName,
string $tagBody
) : array {
): array {
return array_merge(
$this->serviceLocator,
[
@@ -335,7 +336,7 @@ final class StandardTagFactory implements TagFactory
*
* @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
@@ -17,16 +17,15 @@ use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
interface Tag
{
public function getName() : string;
public function getName(): string;
/**
* @return Tag|mixed Class that implements Tag
*
* @phpstan-return ?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;
}
@@ -38,7 +38,7 @@ interface TagFactory
*
* @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.
@@ -49,7 +49,7 @@ interface TagFactory
*
* @throws InvalidArgumentException If an invalid tag line was presented.
*/
public function create(string $tagLine, ?TypeContext $context = null) : Tag;
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.
@@ -60,7 +60,7 @@ 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.
*/
public function addService(object $service) : void;
public function addService(object $service): void;
/**
* Registers a handler for tags.
@@ -80,5 +80,5 @@ interface TagFactory
* @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;
}
@@ -14,9 +14,11 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException;
use function filter_var;
use function preg_match;
use function trim;
use const FILTER_VALIDATE_EMAIL;
/**
@@ -51,7 +53,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;
}
@@ -61,7 +63,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;
}
@@ -69,7 +71,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
/**
* Returns this tag in string form.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->authorEmail) {
$authorEmail = '<' . $this->authorEmail . '>';
@@ -77,15 +79,15 @@ final class Author extends BaseTag implements Factory\StaticMethod
$authorEmail = '';
}
$authorName = (string) $this->authorName;
$authorName = $this->authorName;
return $authorName . ($authorEmail !== '' ? ($authorName !== '' ? ' ' : '') . $authorEmail : '');
}
/**
* Attempts to create a new Author object based on he tag body.
* Attempts to create a new Author object based on the tag body.
*/
public static function create(string $body) : ?self
public static function create(string $body): ?self
{
$splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches);
if (!$splitTagContent) {
@@ -32,17 +32,17 @@ abstract class BaseTag implements DocBlock\Tag
*
* @return string The name of this tag.
*/
public function getName() : string
public function getName(): string
{
return $this->name;
}
public function getDescription() : ?Description
public function getDescription(): ?Description
{
return $this->description;
}
public function render(?Formatter $formatter = null) : string
public function render(?Formatter $formatter = null): string
{
if ($formatter === null) {
$formatter = new Formatter\PassthroughFormatter();
@@ -20,6 +20,7 @@ use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_key_exists;
use function explode;
@@ -48,7 +49,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null,
?FqsenResolver $resolver = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($descriptionFactory);
Assert::notNull($resolver);
@@ -61,7 +62,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
);
}
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen
{
Assert::notNull($fqsenResolver);
$fqsenParts = explode('::', $parts);
@@ -77,7 +78,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;
}
@@ -85,7 +86,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation of this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -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;
/**
@@ -61,7 +62,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();
}
@@ -85,7 +86,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;
}
@@ -93,7 +94,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Tag;
use Webmozart\Assert\Assert;
use function array_key_exists;
use function preg_match;
use function rawurlencode;
@@ -66,7 +67,7 @@ final class Example implements Tag, Factory\StaticMethod
$this->isURI = $isURI;
}
public function getContent() : string
public function getContent(): string
{
if ($this->content === null || $this->content === '') {
$filePath = $this->filePath;
@@ -82,12 +83,12 @@ final class Example implements Tag, Factory\StaticMethod
return $this->content;
}
public function getDescription() : ?string
public function getDescription(): ?string
{
return $this->content;
}
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+))(?:\s+(.*))?$/sux', $body, $matches)) {
@@ -137,7 +138,7 @@ final class Example implements Tag, Factory\StaticMethod
* @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 trim($this->filePath, '"');
}
@@ -145,9 +146,9 @@ final class Example implements Tag, Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
$filePath = (string) $this->filePath;
$filePath = $this->filePath;
$isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0;
$startingLine = !$isDefaultLine ? (string) $this->startingLine : '';
$lineCount = !$isDefaultLine ? (string) $this->lineCount : '';
@@ -168,27 +169,27 @@ final class Example implements Tag, Factory\StaticMethod
/**
* 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 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;
}
public function getName() : string
public function getName(): string
{
return 'example';
}
public function render(?Formatter $formatter = null) : string
public function render(?Formatter $formatter = null): string
{
if ($formatter === null) {
$formatter = new Formatter\PassthroughFormatter();
@@ -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;
}
@@ -15,6 +15,7 @@ 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;
@@ -37,7 +38,7 @@ 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(
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use function trim;
class PassthroughFormatter implements Formatter
@@ -22,7 +23,7 @@ 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() . ' ' . $tag);
}
@@ -19,6 +19,7 @@ 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;
/**
@@ -50,7 +51,7 @@ final class Generic extends BaseTag implements Factory\StaticMethod
string $name = '',
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($name);
Assert::notNull($descriptionFactory);
@@ -62,7 +63,7 @@ final class Generic extends BaseTag implements Factory\StaticMethod
/**
* Returns the tag as a serialized string
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -76,7 +77,7 @@ final 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(
@@ -11,6 +11,7 @@ use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use Throwable;
use function array_map;
use function get_class;
use function get_resource_type;
@@ -46,22 +47,22 @@ final class InvalidTag implements Tag
$this->body = $body;
}
public function getException() : ?Throwable
public function getException(): ?Throwable
{
return $this->throwable;
}
public function getName() : string
public function getName(): string
{
return $this->name;
}
public static function create(string $body, string $name = '') : self
public static function create(string $body, string $name = ''): self
{
return new self($name, $body);
}
public function withError(Throwable $exception) : self
public function withError(Throwable $exception): self
{
$this->flattenExceptionBacktrace($exception);
$tag = new self($this->name, $this->body);
@@ -76,7 +77,7 @@ final class InvalidTag implements Tag
* Not all objects are serializable. So we need to remove them from the
* stored exception to be sure that we do not break existing library usage.
*/
private function flattenExceptionBacktrace(Throwable $exception) : void
private function flattenExceptionBacktrace(Throwable $exception): void
{
$traceProperty = (new ReflectionClass(Exception::class))->getProperty('trace');
$traceProperty->setAccessible(true);
@@ -85,8 +86,8 @@ final class InvalidTag implements Tag
$trace = $exception->getTrace();
if (isset($trace[0]['args'])) {
$trace = array_map(
function (array $call) : array {
$call['args'] = array_map([$this, 'flattenArguments'], $call['args']);
function (array $call): array {
$call['args'] = array_map([$this, 'flattenArguments'], $call['args'] ?? []);
return $call;
},
@@ -128,7 +129,7 @@ final class InvalidTag implements Tag
return $value;
}
public function render(?Formatter $formatter = null) : string
public function render(?Formatter $formatter = null): string
{
if ($formatter === null) {
$formatter = new Formatter\PassthroughFormatter();
@@ -137,7 +138,7 @@ final class InvalidTag implements Tag
return $formatter->format($this);
}
public function __toString() : string
public function __toString(): string
{
return $this->body;
}
@@ -43,7 +43,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::notNull($descriptionFactory);
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
@@ -55,7 +55,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
/**
* Gets the link
*/
public function getLink() : string
public function getLink(): string
{
return $this->link;
}
@@ -63,7 +63,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -71,7 +71,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
$description = '';
}
$link = (string) $this->link;
$link = $this->link;
return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : '');
}
@@ -22,6 +22,7 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Void_;
use Webmozart\Assert\Assert;
use function array_keys;
use function explode;
use function implode;
@@ -58,7 +59,6 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param array<int, array<string, Type|string>> $arguments
*
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*/
public function __construct(
@@ -86,7 +86,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : ?self {
): ?self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -100,8 +100,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
// 5. then a word with underscores, followed by ( and any character
// until a ) and whitespace : as method name with signature
// 6. any remaining text : as description
if (!preg_match(
'/^
if (
!preg_match(
'/^
# Static keyword
# Declares a static method ONLY if type is also present
(?:
@@ -131,9 +132,10 @@ final class Method extends BaseTag implements Factory\StaticMethod
# Description
(.*)
$/sux',
$body,
$matches
)) {
$body,
$matches
)
) {
return null;
}
@@ -176,17 +178,16 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* Retrieves the method name.
*/
public function getMethodName() : string
public function getMethodName(): string
{
return $this->methodName;
}
/**
* @return array<int, array<string, Type|string>>
*
* @phpstan-return array<int, array{name: string, type: Type}>
*/
public function getArguments() : array
public function getArguments(): array
{
return $this->arguments;
}
@@ -196,17 +197,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) {
@@ -225,7 +226,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$returnType = (string) $this->returnType;
$methodName = (string) $this->methodName;
$methodName = $this->methodName;
return $static
. ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '')
@@ -236,13 +237,12 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param mixed[][]|string[] $arguments
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*
* @return mixed[][]
*
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
* @phpstan-return array<int, array{name: string, type: Type}>
*/
private function filterArguments(array $arguments = []) : array
private function filterArguments(array $arguments = []): array
{
$result = [];
foreach ($arguments as $argument) {
@@ -268,7 +268,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
return $result;
}
private static function stripRestArg(string $argument) : string
private static function stripRestArg(string $argument): string
{
if (strpos($argument, '...') === 0) {
$argument = trim(substr($argument, 3));
@@ -20,11 +20,13 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_shift;
use function array_unshift;
use function implode;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -61,7 +63,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -114,7 +116,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
/**
* Returns the variable's name.
*/
public function getVariableName() : ?string
public function getVariableName(): ?string
{
return $this->variableName;
}
@@ -122,7 +124,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
/**
* Returns whether this tag is variadic.
*/
public function isVariadic() : bool
public function isVariadic(): bool
{
return $this->isVariadic;
}
@@ -130,7 +132,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
/**
* Returns whether this tag is passed by reference.
*/
public function isReference() : bool
public function isReference(): bool
{
return $this->isReference;
}
@@ -138,7 +140,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -159,7 +161,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
}
private static function strStartsWithVariable(string $str) : bool
private static function strStartsWithVariable(string $str): bool
{
return strpos($str, '$') === 0
||
@@ -20,11 +20,13 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_shift;
use function array_unshift;
use function implode;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -50,7 +52,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -88,7 +90,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
/**
* Returns the variable's name.
*/
public function getVariableName() : ?string
public function getVariableName(): ?string
{
return $this->variableName;
}
@@ -96,7 +98,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -20,11 +20,13 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_shift;
use function array_unshift;
use function implode;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -50,7 +52,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -88,7 +90,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
/**
* Returns the variable's name.
*/
public function getVariableName() : ?string
public function getVariableName(): ?string
{
return $this->variableName;
}
@@ -96,7 +98,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -20,11 +20,13 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_shift;
use function array_unshift;
use function implode;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -50,7 +52,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -88,7 +90,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
/**
* Returns the variable's name.
*/
public function getVariableName() : ?string
public function getVariableName(): ?string
{
return $this->variableName;
}
@@ -96,7 +98,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -31,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;
}
@@ -18,5 +18,5 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference;
*/
interface Reference
{
public function __toString() : string;
public function __toString(): string;
}
@@ -29,7 +29,7 @@ final class Url implements Reference
$this->uri = $uri;
}
public function __toString() : string
public function __toString(): string
{
return $this->uri;
}
@@ -37,7 +37,7 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -49,7 +49,7 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
return new static($type, $description);
}
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -59,6 +59,6 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
$type = $this->type ? '' . $this->type : 'mixed';
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
return $type . ($description !== '' ? ' ' . $description : '');
}
}
@@ -23,6 +23,7 @@ use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_key_exists;
use function explode;
use function preg_match;
@@ -52,21 +53,21 @@ final class See extends BaseTag implements Factory\StaticMethod
?FqsenResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::notNull($descriptionFactory);
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
// https://tools.ietf.org/html/rfc2396#section-3
if (preg_match('/\w:\/\/\w/i', $parts[0])) {
if (preg_match('#\w://\w#', $parts[0])) {
return new static(new Url($parts[0]), $description);
}
return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description);
}
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen
{
Assert::notNull($fqsenResolver);
$fqsenParts = explode('::', $parts);
@@ -82,7 +83,7 @@ final class See extends BaseTag implements Factory\StaticMethod
/**
* Returns the ref of this tag.
*/
public function getReference() : Reference
public function getReference(): Reference
{
return $this->refers;
}
@@ -90,7 +91,7 @@ final class See extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation of this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -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;
/**
@@ -58,7 +59,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
?string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : ?self {
): ?self {
if (empty($body)) {
return new static();
}
@@ -79,7 +80,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;
}
@@ -87,7 +88,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -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;
/**
@@ -51,7 +52,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($descriptionFactory);
@@ -69,7 +70,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
$description = $matches[3];
}
return new static($startingLine, $lineCount, $descriptionFactory->create($description??'', $context));
return new static($startingLine, $lineCount, $descriptionFactory->create($description ?? '', $context));
}
/**
@@ -78,7 +79,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;
}
@@ -89,12 +90,12 @@ 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
{
if ($this->description) {
$description = $this->description->render();
@@ -104,14 +105,12 @@ final class Source extends BaseTag implements Factory\StaticMethod
$startingLine = (string) $this->startingLine;
$lineCount = $this->lineCount !== null ? '' . $this->lineCount : '';
$lineCount = $this->lineCount !== null ? ' ' . $this->lineCount : '';
return $startingLine
. ($lineCount !== ''
? ($startingLine || $startingLine === '0' ? ' ' : '') . $lineCount
: '')
. $lineCount
. ($description !== ''
? ($startingLine || $startingLine === '0' || $lineCount !== '' ? ' ' : '') . $description
? ' ' . $description
: '');
}
}
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Type;
use function in_array;
use function strlen;
use function substr;
@@ -27,7 +28,7 @@ abstract class TagWithType extends BaseTag
/**
* Returns the type section of the variable.
*/
public function getType() : ?Type
public function getType(): ?Type
{
return $this->type;
}
@@ -35,7 +36,7 @@ abstract class TagWithType extends BaseTag
/**
* @return string[]
*/
protected static function extractTypeFromBody(string $body) : array
protected static function extractTypeFromBody(string $body): array
{
$type = '';
$nestingLevel = 0;
@@ -37,7 +37,7 @@ final class Throws extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -49,7 +49,7 @@ final class Throws extends TagWithType implements Factory\StaticMethod
return new static($type, $description);
}
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -20,6 +20,7 @@ use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_key_exists;
use function explode;
@@ -48,7 +49,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
?FqsenResolver $resolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::notNull($resolver);
Assert::notNull($descriptionFactory);
@@ -60,7 +61,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
);
}
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen
{
Assert::notNull($fqsenResolver);
$fqsenParts = explode('::', $parts);
@@ -76,7 +77,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;
}
@@ -84,7 +85,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation of this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -20,11 +20,13 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use Webmozart\Assert\Assert;
use function array_shift;
use function array_unshift;
use function implode;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
/**
@@ -50,7 +52,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) : self {
): self {
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
@@ -89,7 +91,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
/**
* Returns the variable's name.
*/
public function getVariableName() : ?string
public function getVariableName(): ?string
{
return $this->variableName;
}
@@ -97,7 +99,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -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;
/**
@@ -58,7 +59,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();
}
@@ -82,7 +83,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;
}
@@ -90,7 +91,7 @@ final class Version extends BaseTag implements Factory\StaticMethod
/**
* Returns a string representation for this tag.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
@@ -20,6 +20,7 @@ use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\TagFactory;
use Webmozart\Assert\Assert;
use function array_shift;
use function count;
use function explode;
@@ -54,7 +55,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*
* @param array<string, class-string<Tag>> $additionalTags
*/
public static function createInstance(array $additionalTags = []) : self
public static function createInstance(array $additionalTags = []): self
{
$fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver);
@@ -75,7 +76,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* @param object|string $docblock A string containing the DocBlock to parse or an object supporting the
* getDocComment method (such as a ReflectionClass object).
*/
public function create($docblock, ?Types\Context $context = null, ?Location $location = null) : DocBlock
public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock
{
if (is_object($docblock)) {
if (!method_exists($docblock, 'getDocComment')) {
@@ -112,7 +113,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/**
* @param class-string<Tag> $handler
*/
public function registerTagHandler(string $tagName, string $handler) : void
public function registerTagHandler(string $tagName, string $handler): void
{
$this->tagFactory->registerTagHandler($tagName, $handler);
}
@@ -122,7 +123,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*
* @param string $comment String containing the comment text.
*/
private function stripDocComment(string $comment) : string
private function stripDocComment(string $comment): string
{
$comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]?(.*)?#u', '$1', $comment);
Assert::string($comment);
@@ -231,7 +232,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*
* @return DocBlock\Tag[]
*/
private function parseTagBlock(string $tags, Types\Context $context) : array
private function parseTagBlock(string $tags, Types\Context $context): array
{
$tags = $this->filterTagBlock($tags);
if ($tags === null) {
@@ -250,7 +251,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/**
* @return string[]
*/
private function splitTagBlockIntoTagLines(string $tags) : array
private function splitTagBlockIntoTagLines(string $tags): array
{
$result = [];
foreach (explode("\n", $tags) as $tagLine) {
@@ -264,7 +265,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
return $result;
}
private function filterTagBlock(string $tags) : ?string
private function filterTagBlock(string $tags): ?string
{
$tags = trim($tags);
if (!$tags) {
@@ -14,10 +14,10 @@ interface DocBlockFactoryInterface
*
* @param array<string, class-string<Tag>> $additionalTags
*/
public static function createInstance(array $additionalTags = []) : DocBlockFactory;
public static function createInstance(array $additionalTags = []): DocBlockFactory;
/**
* @param string|object $docblock
*/
public function create($docblock, ?Types\Context $context = null, ?Location $location = null) : DocBlock;
public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock;
}
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\Exception;
use InvalidArgumentException;
use const PREG_BACKTRACK_LIMIT_ERROR;
use const PREG_BAD_UTF8_ERROR;
use const PREG_BAD_UTF8_OFFSET_ERROR;
@@ -15,19 +16,24 @@ use const PREG_RECURSION_LIMIT_ERROR;
final class PcreException extends InvalidArgumentException
{
public static function createFromPhpError(int $errorCode) : self
public static function createFromPhpError(int $errorCode): self
{
switch ($errorCode) {
case PREG_BACKTRACK_LIMIT_ERROR:
return new self('Backtrack limit error');
case PREG_RECURSION_LIMIT_ERROR:
return new self('Recursion limit error');
case PREG_BAD_UTF8_ERROR:
return new self('Bad UTF8 error');
case PREG_BAD_UTF8_OFFSET_ERROR:
return new self('Bad UTF8 offset error');
case PREG_JIT_STACKLIMIT_ERROR:
return new self('Jit stacklimit error');
case PREG_NO_ERROR:
case PREG_INTERNAL_ERROR:
default:
+8 -3
View File
@@ -14,6 +14,8 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\Exception\PcreException;
use Webmozart\Assert\Assert;
use function preg_last_error;
use function preg_split as php_preg_split;
@@ -28,7 +30,7 @@ abstract class Utils
*
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param int|null $limit If specified, then only substrings up to limit are returned with the
* @param int $limit If specified, then only substrings up to limit are returned with the
* rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit".
* @param int $flags flags can be any combination of the following flags (combined with the | bitwise operator):
* *PREG_SPLIT_NO_EMPTY*
@@ -41,17 +43,20 @@ abstract class Utils
* Note that this changes the return value in an array where every element is an array consisting of the
* matched string at offset 0 and its string offset into subject at offset 1.
*
* @return string[] Returns an array containing substrings of subject split along boundaries matched by pattern
* @return string[] Returns an array containing substrings of subject
* split along boundaries matched by pattern
*
* @throws PcreException
*/
public static function pregSplit(string $pattern, string $subject, ?int $limit = -1, int $flags = 0) : array
public static function pregSplit(string $pattern, string $subject, int $limit = -1, int $flags = 0): array
{
$parts = php_preg_split($pattern, $subject, $limit, $flags);
if ($parts === false) {
throw PcreException::createFromPhpError(preg_last_error());
}
Assert::allString($parts);
return $parts;
}
}
+2 -1
View File
@@ -14,7 +14,8 @@
"phpdocumentor/reflection-common": "^2.0"
},
"require-dev": {
"ext-tokenizer": "*"
"ext-tokenizer": "*",
"psalm/phar": "^4.8"
},
"autoload": {
"psr-4": {
-71
View File
@@ -1,71 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ee8aea1f755e1772266bc7e041d8ee5b",
"packages": [
{
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b",
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jaap van Otterdijk",
"email": "opensource@ijaap.nl"
}
],
"description": "Common reflection classes used by phpdocumentor to reflect the code structure",
"homepage": "http://www.phpdoc.org",
"keywords": [
"FQSEN",
"phpDocumentor",
"phpdoc",
"reflection",
"static analysis"
],
"time": "2020-06-27T09:03:43+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.2 || ^8.0"
},
"platform-dev": {
"ext-tokenizer": "*"
}
}
-10
View File
@@ -1,10 +0,0 @@
{
"bootstrap": "vendor/autoload.php",
"path": "tests/benchmark",
"extensions": [
"Jaapio\\Blackfire\\Extension"
],
"blackfire" : {
"env": "c12030d0-c177-47e2-b466-4994c40dc993"
}
}
+4 -3
View File
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection;
use InvalidArgumentException;
use phpDocumentor\Reflection\Types\Context;
use function explode;
use function implode;
use function strpos;
@@ -29,7 +30,7 @@ class FqsenResolver
/** @var string Definition of the NAMESPACE operator in PHP */
private const OPERATOR_NAMESPACE = '\\';
public function resolve(string $fqsen, ?Context $context = null) : Fqsen
public function resolve(string $fqsen, ?Context $context = null): Fqsen
{
if ($context === null) {
$context = new Context('');
@@ -45,7 +46,7 @@ class FqsenResolver
/**
* Tests whether the given type is a Fully Qualified Structural Element Name.
*/
private function isFqsen(string $type) : bool
private function isFqsen(string $type): bool
{
return strpos($type, self::OPERATOR_NAMESPACE) === 0;
}
@@ -56,7 +57,7 @@ class FqsenResolver
*
* @throws InvalidArgumentException When type is not a valid FQSEN.
*/
private function resolvePartialStructuralElementName(string $type, Context $context) : Fqsen
private function resolvePartialStructuralElementName(string $type, Context $context): Fqsen
{
$typeParts = explode(self::OPERATOR_NAMESPACE, $type, 2);
+1 -1
View File
@@ -15,5 +15,5 @@ namespace phpDocumentor\Reflection;
interface PseudoType extends Type
{
public function underlyingType() : Type;
public function underlyingType(): Type;
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class CallableString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'callable-string';
}
}
@@ -16,6 +16,7 @@ namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Boolean;
use function class_alias;
/**
@@ -25,12 +26,12 @@ use function class_alias;
*/
final class False_ extends Boolean implements PseudoType
{
public function underlyingType() : Type
public function underlyingType(): Type
{
return new Boolean();
}
public function __toString() : string
public function __toString(): string
{
return 'false';
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class HtmlEscapedString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'html-escaped-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class LiteralString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'literal-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class LowercaseString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'lowercase-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class NonEmptyLowercaseString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'non-empty-lowercase-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class NonEmptyString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'non-empty-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class NumericString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'numeric-string';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Integer;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class PositiveInteger extends Integer implements PseudoType
{
public function underlyingType(): Type
{
return new Integer();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'positive-int';
}
}
@@ -0,0 +1,39 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\String_;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class TraitString extends String_ implements PseudoType
{
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'trait-string';
}
}
@@ -16,6 +16,7 @@ namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Boolean;
use function class_alias;
/**
@@ -25,12 +26,12 @@ use function class_alias;
*/
final class True_ extends Boolean implements PseudoType
{
public function underlyingType() : Type
public function underlyingType(): Type
{
return new Boolean();
}
public function __toString() : string
public function __toString(): string
{
return 'true';
}
+1 -1
View File
@@ -21,5 +21,5 @@ interface Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string;
public function __toString(): string;
}
+103 -33
View File
@@ -16,18 +16,21 @@ namespace phpDocumentor\Reflection;
use ArrayIterator;
use InvalidArgumentException;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\ArrayKey;
use phpDocumentor\Reflection\Types\ClassString;
use phpDocumentor\Reflection\Types\Collection;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Expression;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\InterfaceString;
use phpDocumentor\Reflection\Types\Intersection;
use phpDocumentor\Reflection\Types\Iterable_;
use phpDocumentor\Reflection\Types\Nullable;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use RuntimeException;
use function array_key_exists;
use function array_pop;
use function array_values;
@@ -41,6 +44,7 @@ use function preg_split;
use function strpos;
use function strtolower;
use function trim;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;
@@ -71,29 +75,41 @@ final class TypeResolver
private $keywords = [
'string' => Types\String_::class,
'class-string' => Types\ClassString::class,
'interface-string' => Types\InterfaceString::class,
'html-escaped-string' => PseudoTypes\HtmlEscapedString::class,
'lowercase-string' => PseudoTypes\LowercaseString::class,
'non-empty-lowercase-string' => PseudoTypes\NonEmptyLowercaseString::class,
'non-empty-string' => PseudoTypes\NonEmptyString::class,
'numeric-string' => PseudoTypes\NumericString::class,
'trait-string' => PseudoTypes\TraitString::class,
'int' => Types\Integer::class,
'integer' => Types\Integer::class,
'positive-int' => PseudoTypes\PositiveInteger::class,
'bool' => Types\Boolean::class,
'boolean' => Types\Boolean::class,
'real' => Types\Float_::class,
'float' => Types\Float_::class,
'double' => Types\Float_::class,
'object' => Object_::class,
'object' => Types\Object_::class,
'mixed' => Types\Mixed_::class,
'array' => Array_::class,
'array' => Types\Array_::class,
'array-key' => Types\ArrayKey::class,
'resource' => Types\Resource_::class,
'void' => Types\Void_::class,
'null' => Types\Null_::class,
'scalar' => Types\Scalar::class,
'callback' => Types\Callable_::class,
'callable' => Types\Callable_::class,
'callable-string' => PseudoTypes\CallableString::class,
'false' => PseudoTypes\False_::class,
'true' => PseudoTypes\True_::class,
'literal-string' => PseudoTypes\LiteralString::class,
'self' => Types\Self_::class,
'$this' => Types\This::class,
'static' => Types\Static_::class,
'parent' => Types\Parent_::class,
'iterable' => Iterable_::class,
'iterable' => Types\Iterable_::class,
'never' => Types\Never_::class,
];
/**
@@ -126,7 +142,7 @@ final class TypeResolver
*
* @param string $type The relative or absolute type.
*/
public function resolve(string $type, ?Context $context = null) : Type
public function resolve(string $type, ?Context $context = null): Type
{
$type = trim($type);
if (!$type) {
@@ -162,7 +178,7 @@ final class TypeResolver
* @param int $parserContext on of self::PARSER_* constants, indicating
* the context where we are in the parsing
*/
private function parseTypes(ArrayIterator $tokens, Context $context, int $parserContext) : Type
private function parseTypes(ArrayIterator $tokens, Context $context, int $parserContext): Type
{
$types = [];
$token = '';
@@ -182,11 +198,12 @@ final class TypeResolver
);
}
if (!in_array($parserContext, [
self::PARSER_IN_COMPOUND,
self::PARSER_IN_ARRAY_EXPRESSION,
self::PARSER_IN_COLLECTION_EXPRESSION,
], true)
if (
!in_array($parserContext, [
self::PARSER_IN_COMPOUND,
self::PARSER_IN_ARRAY_EXPRESSION,
self::PARSER_IN_COLLECTION_EXPRESSION,
], true)
) {
throw new RuntimeException(
'Unexpected type separator'
@@ -196,11 +213,12 @@ final class TypeResolver
$compoundToken = $token;
$tokens->next();
} elseif ($token === '?') {
if (!in_array($parserContext, [
self::PARSER_IN_COMPOUND,
self::PARSER_IN_ARRAY_EXPRESSION,
self::PARSER_IN_COLLECTION_EXPRESSION,
], true)
if (
!in_array($parserContext, [
self::PARSER_IN_COMPOUND,
self::PARSER_IN_ARRAY_EXPRESSION,
self::PARSER_IN_COLLECTION_EXPRESSION,
], true)
) {
throw new RuntimeException(
'Unexpected nullable character'
@@ -224,7 +242,7 @@ final class TypeResolver
$resolvedType = new Expression($type);
$types[] = $resolvedType;
} elseif ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION && $token[0] === ')') {
} elseif ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION && isset($token[0]) && $token[0] === ')') {
break;
} elseif ($token === '<') {
if (count($types) === 0) {
@@ -237,13 +255,16 @@ final class TypeResolver
if ($classType !== null) {
if ((string) $classType === 'class-string') {
$types[] = $this->resolveClassString($tokens, $context);
} elseif ((string) $classType === 'interface-string') {
$types[] = $this->resolveInterfaceString($tokens, $context);
} else {
$types[] = $this->resolveCollection($tokens, $classType, $context);
}
}
$tokens->next();
} elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
} elseif (
$parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
&& ($token === '>' || trim($token) === ',')
) {
break;
@@ -313,13 +334,15 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function resolveSingleType(string $type, Context $context) : object
private function resolveSingleType(string $type, Context $context): object
{
switch (true) {
case $this->isKeyword($type):
return $this->resolveKeyword($type);
case $this->isFqsen($type):
return $this->resolveTypedObject($type);
case $this->isPartialStructuralElementName($type):
return $this->resolveTypedObject($type, $context);
@@ -339,7 +362,7 @@ final class TypeResolver
*
* @psalm-param class-string<Type> $typeClassName
*/
public function addKeyword(string $keyword, string $typeClassName) : void
public function addKeyword(string $keyword, string $typeClassName): void
{
if (!class_exists($typeClassName)) {
throw new InvalidArgumentException(
@@ -348,7 +371,15 @@ final class TypeResolver
);
}
if (!in_array(Type::class, class_implements($typeClassName), true)) {
$interfaces = class_implements($typeClassName);
if ($interfaces === false) {
throw new InvalidArgumentException(
'The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class'
. ' but we could not find the class ' . $typeClassName
);
}
if (!in_array(Type::class, $interfaces, true)) {
throw new InvalidArgumentException(
'The class "' . $typeClassName . '" must implement the interface "phpDocumentor\Reflection\Type"'
);
@@ -364,7 +395,7 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function isKeyword(string $type) : bool
private function isKeyword(string $type): bool
{
return array_key_exists(strtolower($type), $this->keywords);
}
@@ -376,9 +407,9 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function isPartialStructuralElementName(string $type) : bool
private function isPartialStructuralElementName(string $type): bool
{
return ($type[0] !== self::OPERATOR_NAMESPACE) && !$this->isKeyword($type);
return (isset($type[0]) && $type[0] !== self::OPERATOR_NAMESPACE) && !$this->isKeyword($type);
}
/**
@@ -386,7 +417,7 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function isFqsen(string $type) : bool
private function isFqsen(string $type): bool
{
return strpos($type, self::OPERATOR_NAMESPACE) === 0;
}
@@ -396,7 +427,7 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function resolveKeyword(string $type) : Type
private function resolveKeyword(string $type): Type
{
$className = $this->keywords[strtolower($type)];
@@ -408,7 +439,7 @@ final class TypeResolver
*
* @psalm-mutation-free
*/
private function resolveTypedObject(string $type, ?Context $context = null) : Object_
private function resolveTypedObject(string $type, ?Context $context = null): Object_
{
return new Object_($this->fqsenResolver->resolve($type, $context));
}
@@ -418,7 +449,7 @@ final class TypeResolver
*
* @param ArrayIterator<int, (string|null)> $tokens
*/
private function resolveClassString(ArrayIterator $tokens, Context $context) : Type
private function resolveClassString(ArrayIterator $tokens, Context $context): Type
{
$tokens->next();
@@ -446,6 +477,39 @@ final class TypeResolver
return new ClassString($classType->getFqsen());
}
/**
* Resolves class string
*
* @param ArrayIterator<int, (string|null)> $tokens
*/
private function resolveInterfaceString(ArrayIterator $tokens, Context $context): Type
{
$tokens->next();
$classType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
if (!$classType instanceof Object_ || $classType->getFqsen() === null) {
throw new RuntimeException(
$classType . ' is not a interface string'
);
}
$token = $tokens->current();
if ($token !== '>') {
if (empty($token)) {
throw new RuntimeException(
'interface-string: ">" is missing'
);
}
throw new RuntimeException(
'Unexpected character "' . $token . '", ">" is missing'
);
}
return new InterfaceString($classType->getFqsen());
}
/**
* Resolves the collection values and keys
*
@@ -453,14 +517,16 @@ final class TypeResolver
*
* @return Array_|Iterable_|Collection
*/
private function resolveCollection(ArrayIterator $tokens, Type $classType, Context $context) : Type
private function resolveCollection(ArrayIterator $tokens, Type $classType, Context $context): Type
{
$isArray = ((string) $classType === 'array');
$isIterable = ((string) $classType === 'iterable');
// allow only "array", "iterable" or class name before "<"
if (!$isArray && !$isIterable
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)) {
if (
!$isArray && !$isIterable
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)
) {
throw new RuntimeException(
$classType . ' is not a collection'
);
@@ -478,7 +544,9 @@ final class TypeResolver
if ($isArray) {
// check the key type for an "array" collection. We allow only
// strings or integers.
if (!$keyType instanceof String_ &&
if (
!$keyType instanceof ArrayKey &&
!$keyType instanceof String_ &&
!$keyType instanceof Integer &&
!$keyType instanceof Compound
) {
@@ -489,7 +557,9 @@ final class TypeResolver
if ($keyType instanceof Compound) {
foreach ($keyType->getIterator() as $item) {
if (!$item instanceof String_ &&
if (
!$item instanceof ArrayKey &&
!$item instanceof String_ &&
!$item instanceof Integer
) {
throw new RuntimeException(
@@ -536,7 +606,7 @@ final class TypeResolver
/**
* @psalm-pure
*/
private function makeCollectionFromObject(Object_ $object, Type $valueType, ?Type $keyType = null) : Collection
private function makeCollectionFromObject(Object_ $object, Type $valueType, ?Type $keyType = null): Collection
{
return new Collection($object->getFqsen(), $valueType, $keyType);
}
@@ -48,7 +48,7 @@ abstract class AbstractList implements Type
/**
* Returns the type for the keys of this array.
*/
public function getKeyType() : Type
public function getKeyType(): Type
{
return $this->keyType ?? $this->defaultKeyType;
}
@@ -56,7 +56,7 @@ abstract class AbstractList implements Type
/**
* Returns the value for the keys of this array.
*/
public function getValueType() : Type
public function getValueType(): Type
{
return $this->valueType;
}
@@ -64,7 +64,7 @@ abstract class AbstractList implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->keyType) {
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\Types;
use ArrayIterator;
use IteratorAggregate;
use phpDocumentor\Reflection\Type;
use function array_key_exists;
use function implode;
@@ -53,7 +54,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* Returns the type at the given index.
*/
public function get(int $index) : ?Type
public function get(int $index): ?Type
{
if (!$this->has($index)) {
return null;
@@ -65,7 +66,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* Tests if this compound type has a type with the given index.
*/
public function has(int $index) : bool
public function has(int $index): bool
{
return array_key_exists($index, $this->types);
}
@@ -73,7 +74,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* Tests if this compound type contains the given type.
*/
public function contains(Type $type) : bool
public function contains(Type $type): bool
{
foreach ($this->types as $typePart) {
// if the type is duplicate; do not add it
@@ -88,7 +89,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return implode($this->token, $this->types);
}
@@ -96,7 +97,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* @return ArrayIterator<int, Type>
*/
public function getIterator() : ArrayIterator
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->types);
}
@@ -104,7 +105,7 @@ abstract class AggregatedType implements Type, IteratorAggregate
/**
* @psalm-suppress ImpureMethodCall
*/
private function add(Type $type) : void
private function add(Type $type): void
{
if ($type instanceof self) {
foreach ($type->getIterator() as $subType) {
@@ -0,0 +1,42 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\Types;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
/**
* Value Object representing a array-key Type.
*
* A array-key Type is the supertype (but not a union) of int and string.
*
* @psalm-immutable
*/
final class ArrayKey extends AggregatedType implements PseudoType
{
public function __construct()
{
parent::__construct([new String_(), new Integer()], '|');
}
public function underlyingType(): Type
{
return new Compound([new String_(), new Integer()]);
}
public function __toString(): string
{
return 'array-key';
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ class Boolean implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'bool';
}
+1 -1
View File
@@ -25,7 +25,7 @@ final class Callable_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'callable';
}
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\Types;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
/**
@@ -21,7 +22,7 @@ use phpDocumentor\Reflection\Type;
*
* @psalm-immutable
*/
final class ClassString implements Type
final class ClassString extends String_ implements PseudoType
{
/** @var Fqsen|null */
private $fqsen;
@@ -34,10 +35,15 @@ final class ClassString implements Type
$this->fqsen = $fqsen;
}
public function underlyingType(): Type
{
return new String_();
}
/**
* Returns the FQSEN associated with this object.
*/
public function getFqsen() : ?Fqsen
public function getFqsen(): ?Fqsen
{
return $this->fqsen;
}
@@ -45,7 +51,7 @@ final class ClassString implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->fqsen === null) {
return 'class-string';
@@ -47,7 +47,7 @@ final class Collection extends AbstractList
/**
* Returns the FQSEN associated with this object.
*/
public function getFqsen() : ?Fqsen
public function getFqsen(): ?Fqsen
{
return $this->fqsen;
}
@@ -55,7 +55,7 @@ final class Collection extends AbstractList
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
$objectType = (string) ($this->fqsen ?? 'object');
+2 -4
View File
@@ -50,7 +50,6 @@ final class Context
*
* @param string $namespace The namespace where this DocBlock resides in.
* @param string[] $namespaceAliases List of namespace aliases => Fully Qualified Namespace.
*
* @psalm-param array<string, string> $namespaceAliases
*/
public function __construct(string $namespace, array $namespaceAliases = [])
@@ -77,7 +76,7 @@ final class Context
/**
* Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in.
*/
public function getNamespace() : string
public function getNamespace(): string
{
return $this->namespace;
}
@@ -87,10 +86,9 @@ final class Context
* the alias for the imported Namespace.
*
* @return string[]
*
* @psalm-return array<string, string>
*/
public function getNamespaceAliases() : array
public function getNamespaceAliases(): array
{
return $this->namespaceAliases;
}
@@ -23,6 +23,7 @@ use ReflectionProperty;
use Reflector;
use RuntimeException;
use UnexpectedValueException;
use function define;
use function defined;
use function file_exists;
@@ -34,10 +35,13 @@ use function strrpos;
use function substr;
use function token_get_all;
use function trim;
use const T_AS;
use const T_CLASS;
use const T_CURLY_OPEN;
use const T_DOLLAR_OPEN_CURLY_BRACES;
use const T_NAME_FULLY_QUALIFIED;
use const T_NAME_QUALIFIED;
use const T_NAMESPACE;
use const T_NS_SEPARATOR;
use const T_STRING;
@@ -73,7 +77,7 @@ final class ContextFactory
*
* @see Context for more information on Contexts.
*/
public function createFromReflector(Reflector $reflector) : Context
public function createFromReflector(Reflector $reflector): Context
{
if ($reflector instanceof ReflectionClass) {
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
@@ -101,50 +105,43 @@ final class ContextFactory
throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector));
}
private function createFromReflectionParameter(ReflectionParameter $parameter) : Context
private function createFromReflectionParameter(ReflectionParameter $parameter): Context
{
$class = $parameter->getDeclaringClass();
if (!$class) {
throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName());
}
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @var ReflectionClass<object> $class */
return $this->createFromReflectionClass($class);
}
private function createFromReflectionMethod(ReflectionMethod $method) : Context
private function createFromReflectionMethod(ReflectionMethod $method): Context
{
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @var ReflectionClass<object> $class */
$class = $method->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
private function createFromReflectionProperty(ReflectionProperty $property) : Context
private function createFromReflectionProperty(ReflectionProperty $property): Context
{
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @var ReflectionClass<object> $class */
$class = $property->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
private function createFromReflectionClassConstant(ReflectionClassConstant $constant) : Context
private function createFromReflectionClassConstant(ReflectionClassConstant $constant): Context
{
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @var ReflectionClass<object> $class */
/** @phpstan-var ReflectionClass<object> $class */
$class = $constant->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
/**
* @param ReflectionClass<object> $class
* @phpstan-param ReflectionClass<object> $class
*/
private function createFromReflectionClass(ReflectionClass $class) : Context
private function createFromReflectionClass(ReflectionClass $class): Context
{
$fileName = $class->getFileName();
$namespace = $class->getNamespaceName();
@@ -170,7 +167,7 @@ final class ContextFactory
* this method first normalizes.
* @param string $fileContents The file's contents to retrieve the aliases from with the given namespace.
*/
public function createForNamespace(string $namespace, string $fileContents) : Context
public function createForNamespace(string $namespace, string $fileContents): Context
{
$namespace = trim($namespace, '\\');
$useStatements = [];
@@ -191,8 +188,10 @@ final class ContextFactory
$firstBraceFound = false;
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
$currentToken = $tokens->current();
if ($currentToken === '{'
|| in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)) {
if (
$currentToken === '{'
|| in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)
) {
if (!$firstBraceFound) {
$firstBraceFound = true;
}
@@ -227,7 +226,7 @@ final class ContextFactory
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*/
private function parseNamespace(ArrayIterator $tokens) : string
private function parseNamespace(ArrayIterator $tokens): string
{
// skip to the first string or namespace separator
$this->skipToNextStringOrNamespaceSeparator($tokens);
@@ -248,10 +247,9 @@ final class ContextFactory
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*
* @return string[]
*
* @psalm-return array<string, string>
*/
private function parseUseStatement(ArrayIterator $tokens) : array
private function parseUseStatement(ArrayIterator $tokens): array
{
$uses = [];
@@ -273,7 +271,7 @@ final class ContextFactory
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*/
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens): void
{
while ($tokens->valid()) {
$currentToken = $tokens->current();
@@ -300,12 +298,11 @@ final class ContextFactory
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*
* @return string[]
* @psalm-return array<string, string>
*
* @psalm-suppress TypeDoesNotContainType
*
* @psalm-return array<string, string>
*/
private function extractUseStatements(ArrayIterator $tokens) : array
private function extractUseStatements(ArrayIterator $tokens): array
{
$extractedUseStatements = [];
$groupedNs = '';
@@ -36,7 +36,7 @@ final class Expression implements Type
/**
* Returns the value for the keys of this array.
*/
public function getValueType() : Type
public function getValueType(): Type
{
return $this->valueType;
}
@@ -44,7 +44,7 @@ final class Expression implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return '(' . $this->valueType . ')';
}
+1 -1
View File
@@ -25,7 +25,7 @@ final class Float_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'float';
}
+2 -2
View File
@@ -20,12 +20,12 @@ use phpDocumentor\Reflection\Type;
*
* @psalm-immutable
*/
final class Integer implements Type
class Integer implements Type
{
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'int';
}
@@ -0,0 +1,56 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\Types;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Type;
/**
* Value Object representing the type 'string'.
*
* @psalm-immutable
*/
final class InterfaceString implements Type
{
/** @var Fqsen|null */
private $fqsen;
/**
* Initializes this representation of a class string with the given Fqsen.
*/
public function __construct(?Fqsen $fqsen = null)
{
$this->fqsen = $fqsen;
}
/**
* Returns the FQSEN associated with this object.
*/
public function getFqsen(): ?Fqsen
{
return $this->fqsen;
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
if ($this->fqsen === null) {
return 'interface-string';
}
return 'interface-string<' . (string) $this->fqsen . '>';
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ final class Iterable_ extends AbstractList
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
if ($this->keyType) {
return 'iterable<' . $this->keyType . ',' . $this->valueType . '>';
+1 -1
View File
@@ -25,7 +25,7 @@ final class Mixed_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'mixed';
}
+35
View File
@@ -0,0 +1,35 @@
<?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.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\Types;
use phpDocumentor\Reflection\Type;
/**
* Value Object representing the return-type 'never'.
*
* Never is generally only used when working with return types as it signifies that the method that only
* ever throw or exit.
*
* @psalm-immutable
*/
final class Never_ implements Type
{
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'never';
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ final class Null_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'null';
}
+2 -2
View File
@@ -36,7 +36,7 @@ final class Nullable implements Type
/**
* Provide access to the actual type directly, if needed.
*/
public function getActualType() : Type
public function getActualType(): Type
{
return $this->realType;
}
@@ -44,7 +44,7 @@ final class Nullable implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return '?' . $this->realType->__toString();
}
+3 -2
View File
@@ -16,6 +16,7 @@ namespace phpDocumentor\Reflection\Types;
use InvalidArgumentException;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Type;
use function strpos;
/**
@@ -52,12 +53,12 @@ final class Object_ implements Type
/**
* Returns the FQSEN associated with this object.
*/
public function getFqsen() : ?Fqsen
public function getFqsen(): ?Fqsen
{
return $this->fqsen;
}
public function __toString() : string
public function __toString(): string
{
if ($this->fqsen) {
return (string) $this->fqsen;
+1 -1
View File
@@ -27,7 +27,7 @@ final class Parent_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'parent';
}
+1 -1
View File
@@ -25,7 +25,7 @@ final class Resource_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'resource';
}
+1 -1
View File
@@ -25,7 +25,7 @@ final class Scalar implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'scalar';
}
+1 -1
View File
@@ -27,7 +27,7 @@ final class Self_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'self';
}
+1 -1
View File
@@ -32,7 +32,7 @@ final class Static_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'static';
}
+2 -2
View File
@@ -20,12 +20,12 @@ use phpDocumentor\Reflection\Type;
*
* @psalm-immutable
*/
final class String_ implements Type
class String_ implements Type
{
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'string';
}
+1 -1
View File
@@ -28,7 +28,7 @@ final class This implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return '$this';
}
+2 -2
View File
@@ -16,7 +16,7 @@ namespace phpDocumentor\Reflection\Types;
use phpDocumentor\Reflection\Type;
/**
* Value Object representing the pseudo-type 'void'.
* Value Object representing the return-type 'void'.
*
* Void is generally only used when working with return types as it signifies that the method intentionally does not
* return any value.
@@ -28,7 +28,7 @@ final class Void_ implements Type
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString() : string
public function __toString(): string
{
return 'void';
}