From 4438ee7955e384e4cc1a16369f384ca7c4c4a5af Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Thu, 3 Sep 2020 02:38:39 +0200 Subject: [PATCH] add more unit tests and normalize the "__toString" methods -> fix code style + psalm reported errors --- src/DocBlock/Tags/Example.php | 12 +++++++++--- src/DocBlock/Tags/Method.php | 1 + src/DocBlock/Tags/Param.php | 2 +- src/DocBlock/Tags/Property.php | 2 +- src/DocBlock/Tags/PropertyRead.php | 2 +- src/DocBlock/Tags/PropertyWrite.php | 2 +- src/DocBlock/Tags/Source.php | 4 ++-- src/DocBlock/Tags/Var_.php | 2 +- tests/unit/DocBlock/Tags/MethodTest.php | 2 +- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 4f95c89..3face1e 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -154,9 +154,15 @@ final class Example implements Tag, Factory\StaticMethod $content = (string) $this->content; return $filePath - . ($startingLine !== '' ? ($filePath !== '' ? ' ' : '') . $startingLine : '') - . ($lineCount !== '' ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount : '') - . ($content !== '' ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content : ''); + . ($startingLine !== '' + ? ($filePath !== '' ? ' ' : '') . $startingLine + : '') + . ($lineCount !== '' + ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount + : '') + . ($content !== '' + ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content + : ''); } /** diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index e568363..08c0407 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -212,6 +212,7 @@ final class Method extends BaseTag implements Factory\StaticMethod foreach ($this->arguments as $argument) { $arguments[] = $argument['type'] . ' $' . $argument['name']; } + $argumentStr = '(' . implode(', ', $arguments) . ')'; if ($this->description) { diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 9b5d8b7..83419e9 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -149,7 +149,7 @@ final class Param extends TagWithType implements Factory\StaticMethod $variableName = ''; if ($this->variableName) { $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); - $variableName .= ($this->variableName ? '$' . $this->variableName : ''); + $variableName .= '$' . $this->variableName; } $type = (string) $this->type; diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index b832156..0389757 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -105,7 +105,7 @@ final class Property extends TagWithType implements Factory\StaticMethod } if ($this->variableName) { - $variableName = ($this->variableName ? '$' . $this->variableName : ''); + $variableName = '$' . $this->variableName; } else { $variableName = ''; } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index fbe387f..7ff55d5 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -105,7 +105,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod } if ($this->variableName) { - $variableName = ($this->variableName ? '$' . $this->variableName : ''); + $variableName = '$' . $this->variableName; } else { $variableName = ''; } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 42c9207..cc1e4b6 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -105,7 +105,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod } if ($this->variableName) { - $variableName = ($this->variableName ? '$' . $this->variableName : ''); + $variableName = '$' . $this->variableName; } else { $variableName = ''; } diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index 78ea7fd..ee12357 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -107,7 +107,7 @@ final class Source extends BaseTag implements Factory\StaticMethod $lineCount = $this->lineCount !== null ? '' . $this->lineCount : ''; return $startingLine - . ($lineCount !== '' ? ($startingLine !== '' ? ' ' : '') . $lineCount : '') - . ($description !== '' ? ($startingLine !== '' || $lineCount !== '' ? ' ' : '') . $description : ''); + . ($lineCount !== '' ? ($startingLine || $startingLine === '0' ? ' ' : '') . $lineCount : '') + . ($description !== '' ? ($startingLine || $startingLine === '0' || $lineCount !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index a2d4426..762c262 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -106,7 +106,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod } if ($this->variableName) { - $variableName = ($this->variableName ? '$' . $this->variableName : ''); + $variableName = '$' . $this->variableName; } else { $variableName = ''; } diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 3b5786e..a07c98a 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -277,7 +277,7 @@ class MethodTest extends TestCase */ public function testStringRepresentationIsReturnedWithoutDescription() : void { - $fixture = new Method('myMethod', [], null, false, new Description('')); + $fixture = new Method('myMethod', [], null, false, new Description('')); $this->assertSame( 'void myMethod()',