Skip to content

Commit 4438ee7

Browse files
committed
add more unit tests and normalize the "__toString" methods
-> fix code style + psalm reported errors
1 parent 4e6d7ec commit 4438ee7

File tree

9 files changed

+18
-11
lines changed

9 files changed

+18
-11
lines changed

src/DocBlock/Tags/Example.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,15 @@ public function __toString() : string
154154
$content = (string) $this->content;
155155

156156
return $filePath
157-
. ($startingLine !== '' ? ($filePath !== '' ? ' ' : '') . $startingLine : '')
158-
. ($lineCount !== '' ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount : '')
159-
. ($content !== '' ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content : '');
157+
. ($startingLine !== ''
158+
? ($filePath !== '' ? ' ' : '') . $startingLine
159+
: '')
160+
. ($lineCount !== ''
161+
? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount
162+
: '')
163+
. ($content !== ''
164+
? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content
165+
: '');
160166
}
161167

162168
/**

src/DocBlock/Tags/Method.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public function __toString() : string
212212
foreach ($this->arguments as $argument) {
213213
$arguments[] = $argument['type'] . ' $' . $argument['name'];
214214
}
215+
215216
$argumentStr = '(' . implode(', ', $arguments) . ')';
216217

217218
if ($this->description) {

src/DocBlock/Tags/Param.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function __toString() : string
149149
$variableName = '';
150150
if ($this->variableName) {
151151
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
152-
$variableName .= ($this->variableName ? '$' . $this->variableName : '');
152+
$variableName .= '$' . $this->variableName;
153153
}
154154

155155
$type = (string) $this->type;

src/DocBlock/Tags/Property.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function __toString() : string
105105
}
106106

107107
if ($this->variableName) {
108-
$variableName = ($this->variableName ? '$' . $this->variableName : '');
108+
$variableName = '$' . $this->variableName;
109109
} else {
110110
$variableName = '';
111111
}

src/DocBlock/Tags/PropertyRead.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function __toString() : string
105105
}
106106

107107
if ($this->variableName) {
108-
$variableName = ($this->variableName ? '$' . $this->variableName : '');
108+
$variableName = '$' . $this->variableName;
109109
} else {
110110
$variableName = '';
111111
}

src/DocBlock/Tags/PropertyWrite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function __toString() : string
105105
}
106106

107107
if ($this->variableName) {
108-
$variableName = ($this->variableName ? '$' . $this->variableName : '');
108+
$variableName = '$' . $this->variableName;
109109
} else {
110110
$variableName = '';
111111
}

src/DocBlock/Tags/Source.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __toString() : string
107107
$lineCount = $this->lineCount !== null ? '' . $this->lineCount : '';
108108

109109
return $startingLine
110-
. ($lineCount !== '' ? ($startingLine !== '' ? ' ' : '') . $lineCount : '')
111-
. ($description !== '' ? ($startingLine !== '' || $lineCount !== '' ? ' ' : '') . $description : '');
110+
. ($lineCount !== '' ? ($startingLine || $startingLine === '0' ? ' ' : '') . $lineCount : '')
111+
. ($description !== '' ? ($startingLine || $startingLine === '0' || $lineCount !== '' ? ' ' : '') . $description : '');
112112
}
113113
}

src/DocBlock/Tags/Var_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function __toString() : string
106106
}
107107

108108
if ($this->variableName) {
109-
$variableName = ($this->variableName ? '$' . $this->variableName : '');
109+
$variableName = '$' . $this->variableName;
110110
} else {
111111
$variableName = '';
112112
}

tests/unit/DocBlock/Tags/MethodTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function testStringRepresentationIsReturned() : void
277277
*/
278278
public function testStringRepresentationIsReturnedWithoutDescription() : void
279279
{
280-
$fixture = new Method('myMethod', [], null, false, new Description(''));
280+
$fixture = new Method('myMethod', [], null, false, new Description(''));
281281

282282
$this->assertSame(
283283
'void myMethod()',

0 commit comments

Comments
 (0)