-
-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Description
Hello,
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.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels