Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 5b677a0

Browse files
author
Sergei Filonich
committed
Fix issue with checking nullable return statements.
1 parent 687bb03 commit 5b677a0

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Check/ReturnCheck.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ public function check(FileInfo $file)
5050
if ($method['return'] === 'array' && substr($method['docblock']['return'], -2) === '[]') {
5151
// Do nothing because this is fine.
5252
} else {
53-
$this->fileStatus->add(
54-
new ReturnMismatchWarning(
55-
$file->getFileName(),
56-
$name,
57-
$method['line'],
58-
$name,
59-
$method['return'],
60-
$method['docblock']['return']
61-
)
62-
);
53+
if (!is_array($method['return']) || !$this->checkMultipleReturnStatements($method)) {
54+
$this->fileStatus->add(
55+
new ReturnMismatchWarning(
56+
$file->getFileName(),
57+
$name,
58+
$method['line'],
59+
$name,
60+
$method['return'],
61+
$method['docblock']['return']
62+
)
63+
);
64+
}
6365
}
6466
}
6567
}
@@ -73,4 +75,16 @@ public function enabled()
7375
{
7476
return !$this->config->isSkipSignatures();
7577
}
78+
79+
/**
80+
* @param array $method
81+
* @return bool
82+
*/
83+
private function checkMultipleReturnStatements(array $method): bool
84+
{
85+
$dockReturn = explode('|', $method['docblock']['return']);
86+
$methodReturn = $method['return'];
87+
88+
return count(array_diff($dockReturn, $methodReturn)) == 0 && count(array_diff($methodReturn, $dockReturn)) == 0;
89+
}
7690
}

0 commit comments

Comments
 (0)