Skip to content

Commit 263a580

Browse files
committed
Fixed empty @return tag. Issue #7.
1 parent 6b68df9 commit 263a580

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

src/CheckerFileProcessor.php

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public function processFile(string $file): array
148148
continue;
149149
}
150150

151+
if ($method['return'] === 'void') {
152+
continue;
153+
}
154+
151155
$warnings[] = [
152156
'type' => 'return-missing',
153157
'file' => $file,

src/FileProcessor.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,13 @@ protected function processDocblock(string $text, array $uses = []): array
242242
}
243243

244244
$types = [];
245-
foreach (\explode('|', $type) as $tmpType) {
246-
if (isset($uses[$tmpType])) {
247-
$tmpType = $uses[$tmpType];
245+
if ($type) {
246+
foreach (\explode('|', $type) as $tmpType) {
247+
if (isset($uses[$tmpType])) {
248+
$tmpType = $uses[$tmpType];
249+
}
250+
$types[] = \substr($tmpType, 0, 1) === '\\' ? \substr($tmpType, 1) : $tmpType;
248251
}
249-
$types[] = \substr($tmpType, 0, 1) === '\\' ? \substr($tmpType, 1) : $tmpType;
250252
}
251253
$result['return'] = \implode('|', $types);
252254
}

tests/data/TestClass.php

+27
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@ public function test121(int $param1): bool
5959
return false;
6060
}
6161

62+
/**
63+
* @param int $param1
64+
*
65+
* @return
66+
*/
67+
public function test122(int $param1)
68+
{
69+
}
70+
71+
/**
72+
* @param int $param1
73+
*
74+
* @return
75+
*/
76+
public function test123(int $param1): void
77+
{
78+
}
79+
80+
/**
81+
* @param int $param1
82+
*
83+
* @return
84+
*/
85+
public function test124(int $param1): bool
86+
{
87+
}
88+
6289
/**
6390
* @param int|null $param1
6491
*

tests/src/CheckerFileProcessorTest.php

+20-8
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ public function testProcessFile()
114114
'param' => '$param1',
115115
'param-type' => 'int',
116116
'doc-type' => 'int|null',
117+
], [
118+
'type' => 'return-missing',
119+
'file' => 'TestClass.php',
120+
'class' => 'Test\Example\TestClass',
121+
'method' => 'test124',
122+
'line' => 85,
117123
], [
118124
'type' => 'param-mismatch',
119125
'file' => 'TestClass.php',
120126
'class' => 'Test\Example\TestClass',
121127
'method' => 'test132',
122-
'line' => 87,
128+
'line' => 114,
123129
'param' => '$param1',
124130
'param-type' => 'int|null',
125131
'doc-type' => 'int',
@@ -128,15 +134,15 @@ public function testProcessFile()
128134
'file' => 'TestClass.php',
129135
'class' => 'Test\Example\TestClass',
130136
'method' => 'test132',
131-
'line' => 87,
137+
'line' => 114,
132138
'return-type' => 'bool|null',
133139
'doc-type' => 'bool',
134140
], [
135141
'type' => 'param-mismatch',
136142
'file' => 'TestClass.php',
137143
'class' => 'Test\Example\TestClass',
138144
'method' => 'test141',
139-
'line' => 117,
145+
'line' => 144,
140146
'param' => '$param1',
141147
'param-type' => 'int|float',
142148
'doc-type' => 'int',
@@ -145,7 +151,7 @@ public function testProcessFile()
145151
'file' => 'TestClass.php',
146152
'class' => 'Test\Example\TestClass',
147153
'method' => 'test141',
148-
'line' => 117,
154+
'line' => 144,
149155
'return-type' => 'bool|int',
150156
'doc-type' => 'bool',
151157
]
@@ -256,12 +262,18 @@ public function testProcessFile()
256262
'line' => 57,
257263
'doc-type' => 'bool|int',
258264
'return-type' => 'bool'
265+
], [
266+
'type' => 'return-missing',
267+
'file' => 'TestClass.php',
268+
'class' => 'Test\Example\TestClass',
269+
'method' => 'test124',
270+
'line' => 85,
259271
], [
260272
'type' => 'param-mismatch',
261273
'file' => 'TestClass.php',
262274
'class' => 'Test\Example\TestClass',
263275
'method' => 'test132',
264-
'line' => 87,
276+
'line' => 114,
265277
'param' => '$param1',
266278
'param-type' => 'int|null',
267279
'doc-type' => 'int',
@@ -270,15 +282,15 @@ public function testProcessFile()
270282
'file' => 'TestClass.php',
271283
'class' => 'Test\Example\TestClass',
272284
'method' => 'test132',
273-
'line' => 87,
285+
'line' => 114,
274286
'return-type' => 'bool|null',
275287
'doc-type' => 'bool',
276288
], [
277289
'type' => 'param-mismatch',
278290
'file' => 'TestClass.php',
279291
'class' => 'Test\Example\TestClass',
280292
'method' => 'test141',
281-
'line' => 117,
293+
'line' => 144,
282294
'param' => '$param1',
283295
'param-type' => 'int|float',
284296
'doc-type' => 'int',
@@ -287,7 +299,7 @@ public function testProcessFile()
287299
'file' => 'TestClass.php',
288300
'class' => 'Test\Example\TestClass',
289301
'method' => 'test141',
290-
'line' => 117,
302+
'line' => 144,
291303
'return-type' => 'bool|int',
292304
'doc-type' => 'bool',
293305
]

0 commit comments

Comments
 (0)