🏆 A full-stack component-based MVC kernel for PHP that helps you write powerful and modern web applications. Write less, have cleaner code and your work will bring you joy.
I think methods like sendJson() should contain PHPStan annotation @phpstan-return never-return like this:
/**
* Sends JSON data to the output.
* @throws Nette\Application\AbortException
* @phpstan-return never-return
*/
public function sendJson(mixed $data): void
{
$this->sendResponse(new Responses\JsonResponse($data));
}
Currently, this can generate hundreds of errors when PhpStan reports possible undefined variables. The annotation marks the code after this call as dead.
For example:
public function actionDefault(): void
{
if ($this->variable) {
$a = 1;
} else {
$this->sendJson('error');
}
echo $a; // generate possible undefined variable, but it is not true
}
Yes, there is an official extension for PhpStan and Nette framework that does this solution, but it would be good to have native support as well.
Hello,
I think methods like
sendJson()
should contain PHPStan annotation@phpstan-return never-return
like this:Currently, this can generate hundreds of errors when PhpStan reports possible undefined variables. The annotation marks the code after this call as dead.
For example:
Yes, there is an official extension for PhpStan and Nette framework that does this solution, but it would be good to have native support as well.
Thanks!