diff --git a/src/CheckerFileProcessor.php b/src/CheckerFileProcessor.php index 1426d0b..d576b23 100644 --- a/src/CheckerFileProcessor.php +++ b/src/CheckerFileProcessor.php @@ -152,6 +152,10 @@ public function processFile(string $file): array continue; } + if ($method['return'] === 'void') { + continue; + } + $warnings[] = [ 'type' => 'return-missing', 'file' => $file, diff --git a/src/FileProcessor.php b/src/FileProcessor.php index c948e16..862e84b 100644 --- a/src/FileProcessor.php +++ b/src/FileProcessor.php @@ -260,11 +260,13 @@ protected function processDocblock(string $text, array $uses = []): array } $types = []; - foreach (\explode('|', $type) as $tmpType) { - if (isset($uses[$tmpType])) { - $tmpType = $uses[$tmpType]; + if ($type) { + foreach (\explode('|', $type) as $tmpType) { + if (isset($uses[$tmpType])) { + $tmpType = $uses[$tmpType]; + } + $types[] = \substr($tmpType, 0, 1) === '\\' ? \substr($tmpType, 1) : $tmpType; } - $types[] = \substr($tmpType, 0, 1) === '\\' ? \substr($tmpType, 1) : $tmpType; } $result['return'] = \implode('|', $types); } diff --git a/tests/data/TestClass.php b/tests/data/TestClass.php index baa240c..62b44bb 100644 --- a/tests/data/TestClass.php +++ b/tests/data/TestClass.php @@ -54,6 +54,33 @@ public function test121(int $param1): bool { } + /** + * @param int $param1 + * + * @return + */ + public function test122(int $param1) + { + } + + /** + * @param int $param1 + * + * @return + */ + public function test123(int $param1): void + { + } + + /** + * @param int $param1 + * + * @return + */ + public function test124(int $param1): bool + { + } + /** * @param int|null $param1 * diff --git a/tests/src/CheckerFileProcessorTest.php b/tests/src/CheckerFileProcessorTest.php index c172fdf..6e02f5a 100644 --- a/tests/src/CheckerFileProcessorTest.php +++ b/tests/src/CheckerFileProcessorTest.php @@ -113,12 +113,18 @@ public function testProcessFile() 'param' => '$param1', 'param-type' => 'int', 'doc-type' => 'int|null', + ], [ + 'type' => 'return-missing', + 'file' => 'TestClass.php', + 'class' => 'Test\Example\TestClass', + 'method' => 'test124', + 'line' => 80, ], [ 'type' => 'param-mismatch', 'file' => 'TestClass.php', 'class' => 'Test\Example\TestClass', 'method' => 'test132', - 'line' => 80, + 'line' => 107, 'param' => '$param1', 'param-type' => 'int|null', 'doc-type' => 'int', @@ -127,7 +133,7 @@ public function testProcessFile() 'file' => 'TestClass.php', 'class' => 'Test\Example\TestClass', 'method' => 'test132', - 'line' => 80, + 'line' => 107, 'return-type' => 'bool|null', 'doc-type' => 'bool', ], [ @@ -135,7 +141,7 @@ public function testProcessFile() 'file' => 'TestClass.php', 'class' => 'Test\Example\TestClass', 'method' => 'test141', - 'line' => 107, + 'line' => 134, 'param' => '$param1', 'param-type' => 'int|float', 'doc-type' => 'int', @@ -144,7 +150,7 @@ public function testProcessFile() 'file' => 'TestClass.php', 'class' => 'Test\Example\TestClass', 'method' => 'test141', - 'line' => 107, + 'line' => 134, 'return-type' => 'bool|int', 'doc-type' => 'bool', ]