phpstan: False positive on return null|void
Bug report
/**
* Overview action
*
* @return \Cake\Http\Response|null|void
*/
public function index() { ... }
Framework controller actions usually don’t have to return, the |void addition should suffice to silence PHPStan.
But it complains with
Method DatabaseLog\Controller\Admin\LogsController::index() should
return Cake\Http\Response|void|null but return statement is missing.
Expected output
No error here. Only with \Cake\Http\Response|null I would expect the above message.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 25 (14 by maintainers)
I understand, I’ll think about it.
On Fri, 6 Dec 2019 at 18:08, Mark Sch. notifications@github.com wrote:
–
Ondřej Mirtes
Released as 0.12.5 😃
I was surprised that the other side was already fixed in PHPStan: https://github.com/phpstan/phpstan-src/commit/80afe105a5bc00b2f7ea06a876226fe6b9d59a2d
I now fixed the remaining case, e.g.
returnin a function isn’t required in case of void union: https://github.com/phpstan/phpstan-src/commit/e208c0599555cd6e54b9c38ff0412e89c2c2ac36We might rethink this when PHP 8 is out. PHPStan typically wants the same constraints from phpDoc types as from the native types (so that they can be automatically converted by other tools).