-
-
Save 84m/1cb41b41fcacf65d1017f4f1c8c09700 to your computer and use it in GitHub Desktop.
phpstan example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "foo", | |
"type": "project", | |
"require": { | |
"symfony/http-foundation": "^4.2", | |
"phpstan/phpstan": "^0.11.0" | |
}, | |
"autoload": { | |
"classmap": [ | |
"Controller.php" | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types = 1); | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
class Controller | |
{ | |
public function getFoo(Request $request) | |
{ | |
$userId = $request->get('userid'); | |
if (isset($userId)) { | |
$userId = (int)($userId); | |
} | |
// ... | |
$response = new Response(); | |
if (isset($userId)) { | |
$response->headers->add(['userId' => $userId]); | |
} | |
return $response; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vender/bin/phpstan analyse --level max Controller.php | |
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% | |
------ ---------------------------------------------------------------- | |
Line Controller.php | |
------ ---------------------------------------------------------------- | |
21 Variable $userId in isset() always exists and is not nullable. | |
------ ---------------------------------------------------------------- | |
[ERROR] Found 1 error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment