add more unit tests and fixed the output

This commit is contained in:
Lars Moelleken
2020-09-02 22:23:55 +02:00
parent acf538a461
commit be6ed8b0d8
10 changed files with 392 additions and 13 deletions
+5 -3
View File
@@ -85,7 +85,9 @@ final class Param extends TagWithType implements Factory\StaticMethod
// if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name
if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) {
$variableName = array_shift($parts);
array_shift($parts);
if ($type) {
array_shift($parts);
}
Assert::notNull($variableName);
@@ -141,8 +143,8 @@ final class Param extends TagWithType implements Factory\StaticMethod
return ($this->type ? $this->type . ' ' : '')
. ($this->isReference() ? '&' : '')
. ($this->isVariadic() ? '...' : '')
. ($this->variableName !== null ? '$' . $this->variableName : '')
. ($this->description ? ' ' . $this->description : '');
. ($this->variableName ? '$' . $this->variableName : '')
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
}
private static function strStartsWithVariable(string $str) : bool
+5 -3
View File
@@ -68,10 +68,12 @@ final class Property extends TagWithType implements Factory\StaticMethod
array_unshift($parts, $firstPart);
}
// if the next item starts with a $ or ...$ it must be the variable name
// if the next item starts with a $ it must be the variable name
if (isset($parts[0]) && strpos($parts[0], '$') === 0) {
$variableName = array_shift($parts);
array_shift($parts);
if ($type) {
array_shift($parts);
}
Assert::notNull($variableName);
@@ -98,6 +100,6 @@ final class Property extends TagWithType implements Factory\StaticMethod
{
return ($this->type ? $this->type . ' ' : '')
. ($this->variableName ? '$' . $this->variableName : '')
. ($this->description ? ' ' . $this->description : '');
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
}
}
+4 -2
View File
@@ -71,7 +71,9 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) && strpos($parts[0], '$') === 0) {
$variableName = array_shift($parts);
array_shift($parts);
if ($type) {
array_shift($parts);
}
Assert::notNull($variableName);
@@ -98,6 +100,6 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
{
return ($this->type ? $this->type . ' ' : '')
. ($this->variableName ? '$' . $this->variableName : '')
. ($this->description ? ' ' . $this->description : '');
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
}
}
+4 -2
View File
@@ -71,7 +71,9 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) && strpos($parts[0], '$') === 0) {
$variableName = array_shift($parts);
array_shift($parts);
if ($type) {
array_shift($parts);
}
Assert::notNull($variableName);
@@ -98,6 +100,6 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
{
return ($this->type ? $this->type . ' ' : '')
. ($this->variableName ? '$' . $this->variableName : '')
. ($this->description ? ' ' . $this->description : '');
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
}
}
+5 -3
View File
@@ -72,7 +72,9 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) && strpos($parts[0], '$') === 0) {
$variableName = array_shift($parts);
array_shift($parts);
if ($type) {
array_shift($parts);
}
Assert::notNull($variableName);
@@ -98,7 +100,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
public function __toString() : string
{
return ($this->type ? $this->type . ' ' : '')
. (empty($this->variableName) ? '' : '$' . $this->variableName)
. ($this->description ? ' ' . $this->description : '');
. ($this->variableName ? '$' . $this->variableName : '')
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
}
}