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 6b68df9 commit 263a580
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/CheckerFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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 @@ -242,11 +242,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 @@ -59,6 +59,33 @@ public function test121(int $param1): bool
return false;
}

/**
* @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
28 changes: 20 additions & 8 deletions tests/src/CheckerFileProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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' => 85,
], [
'type' => 'param-mismatch',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test132',
'line' => 87,
'line' => 114,
'param' => '$param1',
'param-type' => 'int|null',
'doc-type' => 'int',
Expand All @@ -128,15 +134,15 @@ public function testProcessFile()
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test132',
'line' => 87,
'line' => 114,
'return-type' => 'bool|null',
'doc-type' => 'bool',
], [
'type' => 'param-mismatch',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test141',
'line' => 117,
'line' => 144,
'param' => '$param1',
'param-type' => 'int|float',
'doc-type' => 'int',
Expand All @@ -145,7 +151,7 @@ public function testProcessFile()
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test141',
'line' => 117,
'line' => 144,
'return-type' => 'bool|int',
'doc-type' => 'bool',
]
Expand Down Expand Up @@ -256,12 +262,18 @@ public function testProcessFile()
'line' => 57,
'doc-type' => 'bool|int',
'return-type' => 'bool'
], [
'type' => 'return-missing',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test124',
'line' => 85,
], [
'type' => 'param-mismatch',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test132',
'line' => 87,
'line' => 114,
'param' => '$param1',
'param-type' => 'int|null',
'doc-type' => 'int',
Expand All @@ -270,15 +282,15 @@ public function testProcessFile()
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test132',
'line' => 87,
'line' => 114,
'return-type' => 'bool|null',
'doc-type' => 'bool',
], [
'type' => 'param-mismatch',
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test141',
'line' => 117,
'line' => 144,
'param' => '$param1',
'param-type' => 'int|float',
'doc-type' => 'int',
Expand All @@ -287,7 +299,7 @@ public function testProcessFile()
'file' => 'TestClass.php',
'class' => 'Test\Example\TestClass',
'method' => 'test141',
'line' => 117,
'line' => 144,
'return-type' => 'bool|int',
'doc-type' => 'bool',
]
Expand Down

0 comments on commit 263a580

Please sign in to comment.