mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
add more unit tests and normalize the "__toString" methods
This commit is contained in:
@@ -71,7 +71,15 @@ final class Author extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->authorName . ($this->authorEmail !== '' ? ' <' . $this->authorEmail . '>' : '');
|
||||
if ($this->authorEmail) {
|
||||
$authorEmail = '<' . $this->authorEmail . '>';
|
||||
} else {
|
||||
$authorEmail = '';
|
||||
}
|
||||
|
||||
$authorName = (string) $this->authorName;
|
||||
|
||||
return $authorName . ($authorEmail !== '' ? ($authorName !== '' ? ' ' : '') . $authorEmail : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,6 +72,14 @@ final class Covers extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$refers = (string) $this->refers;
|
||||
|
||||
return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,14 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->version ?? '') . ($this->description ? ' ' . $this->description->render() : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$version = (string) $this->version;
|
||||
|
||||
return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,10 @@ final class Example implements Tag, Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->filePath . ($this->content ? ' ' . $this->content : '');
|
||||
$filePath = (string) $this->filePath;
|
||||
$content = (string) $this->content;
|
||||
|
||||
return $filePath . ($content !== '' ? ($filePath !== '' ? ' ' : '') . $content : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,13 @@ final class Generic extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->description ? $this->description->render() : '';
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,6 +65,14 @@ final class Link extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->link . ($this->description ? ' ' . $this->description->render() : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$link = (string) $this->link;
|
||||
|
||||
return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,12 +212,25 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
||||
foreach ($this->arguments as $argument) {
|
||||
$arguments[] = $argument['type'] . ' $' . $argument['name'];
|
||||
}
|
||||
$argumentStr = '(' . implode(', ', $arguments) . ')';
|
||||
|
||||
return trim(($this->isStatic() ? 'static ' : '')
|
||||
. (string) $this->returnType . ' '
|
||||
. $this->methodName
|
||||
. '(' . implode(', ', $arguments) . ')'
|
||||
. ($this->description ? ' ' . $this->description->render() : ''));
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$static = $this->isStatic ? 'static' : '';
|
||||
|
||||
$returnType = (string) $this->returnType;
|
||||
|
||||
$methodName = (string) $this->methodName;
|
||||
|
||||
return $static
|
||||
. ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '')
|
||||
. ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $methodName : '')
|
||||
. $argumentStr
|
||||
. ($description !== '' ? ' ' . $description : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,11 +140,23 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
|
||||
. ($this->isReference() ? '&' : '')
|
||||
. ($this->isVariadic() ? '...' : '')
|
||||
. ($this->variableName ? '$' . $this->variableName : '')
|
||||
. (('' . $this->description) ? ' ' . $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$variableName = '';
|
||||
if ($this->variableName) {
|
||||
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
|
||||
$variableName .= ($this->variableName ? '$' . $this->variableName : '');
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type
|
||||
. ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '')
|
||||
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
|
||||
private static function strStartsWithVariable(string $str) : bool
|
||||
|
||||
@@ -98,8 +98,22 @@ final class Property extends TagWithType implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
|
||||
. ($this->variableName ? '$' . $this->variableName : '')
|
||||
. (('' . $this->description) ? ' ' . $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if ($this->variableName) {
|
||||
$variableName = ($this->variableName ? '$' . $this->variableName : '');
|
||||
} else {
|
||||
$variableName = '';
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type
|
||||
. ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '')
|
||||
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,22 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
|
||||
. ($this->variableName ? '$' . $this->variableName : '')
|
||||
. (('' . $this->description) ? ' ' . $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if ($this->variableName) {
|
||||
$variableName = ($this->variableName ? '$' . $this->variableName : '');
|
||||
} else {
|
||||
$variableName = '';
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type
|
||||
. ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '')
|
||||
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,22 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
|
||||
. ($this->variableName ? '$' . $this->variableName : '')
|
||||
. (('' . $this->description) ? ' ' . $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if ($this->variableName) {
|
||||
$variableName = ($this->variableName ? '$' . $this->variableName : '');
|
||||
} else {
|
||||
$variableName = '';
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type
|
||||
. ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '')
|
||||
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,14 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ?: 'mixed') . ' ' . (string) $this->description;
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$type = $this->type ? '' . $this->type : 'mixed';
|
||||
|
||||
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,14 @@ final class See extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$refers = (string) $this->refers;
|
||||
|
||||
return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,14 @@ final class Since extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return (string) $this->version . ($this->description ? ' ' . (string) $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$version = (string) $this->version;
|
||||
|
||||
return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,18 @@ final class Source extends BaseTag implements Factory\StaticMethod
|
||||
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->startingLine
|
||||
. ($this->lineCount !== null ? ' ' . $this->lineCount : '')
|
||||
. ($this->description ? ' ' . (string) $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$startingLine = (string) $this->startingLine;
|
||||
|
||||
$lineCount = $this->lineCount !== null ? '' . $this->lineCount : '';
|
||||
|
||||
return $startingLine
|
||||
. ($lineCount !== '' ? ($startingLine !== '' ? ' ' : '') . $lineCount : '')
|
||||
. ($description !== '' ? ($startingLine !== '' || $lineCount !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,14 @@ final class Throws extends TagWithType implements Factory\StaticMethod
|
||||
|
||||
public function __toString() : string
|
||||
{
|
||||
return (string) $this->type . ' ' . (string) $this->description;
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,14 @@ final class Uses extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->refers . ' ' . (string) $this->description;
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$refers = (string) $this->refers;
|
||||
|
||||
return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,22 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
|
||||
. ($this->variableName ? '$' . $this->variableName : '')
|
||||
. (('' . $this->description) ? ' ' . $this->description : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if ($this->variableName) {
|
||||
$variableName = ($this->variableName ? '$' . $this->variableName : '');
|
||||
} else {
|
||||
$variableName = '';
|
||||
}
|
||||
|
||||
$type = (string) $this->type;
|
||||
|
||||
return $type
|
||||
. ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '')
|
||||
. ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,14 @@ final class Version extends BaseTag implements Factory\StaticMethod
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ((string) $this->version) .
|
||||
($this->description instanceof Description ? ' ' . $this->description->render() : '');
|
||||
if ($this->description) {
|
||||
$description = $this->description->render();
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
$version = (string) $this->version;
|
||||
|
||||
return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : '');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user