Skip to content

Commit

Permalink
Fixed empty @return tag. Issue #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed Oct 7, 2023
1 parent e5f5602 commit a7b223f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/CheckerFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public function processFile(string $file): array
continue;
}

if ($method['return'] === 'void') {
continue;
}

$warnings[] = [
'type' => 'return-missing',
'file' => $file,
Expand Down
10 changes: 6 additions & 4 deletions src/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/data/TestClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
14 changes: 10 additions & 4 deletions tests/src/CheckerFileProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -127,15 +133,15 @@ public function testProcessFile()
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test132',
'line' => 80,
'line' => 107,
'return-type' => 'bool|null',
'doc-type' => 'bool',
], [
'type' => 'param-mismatch',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test141',
'line' => 107,
'line' => 134,
'param' => '$param1',
'param-type' => 'int|float',
'doc-type' => 'int',
Expand All @@ -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',
]
Expand Down

0 comments on commit a7b223f

Please sign in to comment.