add more unit tests and normalize the "__toString" methods

This commit is contained in:
Lars Moelleken
2020-09-03 00:33:09 +02:00
parent bbe0f54877
commit 97863e0c44
34 changed files with 548 additions and 44 deletions
+9 -1
View File
@@ -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 : '');
}
/**
+9 -1
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+4 -1
View File
@@ -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 : '');
}
/**
+7 -1
View File
@@ -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;
}
/**
+9 -1
View File
@@ -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 : '');
}
}
+18 -5
View File
@@ -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 : '');
}
/**
+17 -5
View File
@@ -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
+17 -3
View File
@@ -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 : '');
}
}
+17 -3
View File
@@ -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 : '');
}
}
+17 -3
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+13 -3
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+9 -1
View File
@@ -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 : '');
}
}
+17 -3
View File
@@ -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 : '');
}
}
+9 -2
View File
@@ -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 : '');
}
}