BurningFlipside /
CommonCode
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Http\Rest; |
||
| 3 | |||
| 4 | use \Psr\Http\Message\ServerRequestInterface as Request; |
||
| 5 | use \Psr\Http\Message\ResponseInterface as Response; |
||
| 6 | |||
| 7 | require 'vendor/autoload.php'; |
||
| 8 | |||
| 9 | const SUCCESS = 0; |
||
| 10 | const UNRECOGNIZED_METHOD = 1; |
||
| 11 | const INVALID_PARAM = 2; |
||
| 12 | const ALREADY_LOGGED_IN = 3; |
||
| 13 | const INVALID_LOGIN = 4; |
||
| 14 | const ACCESS_DENIED = 5; |
||
| 15 | const INTERNAL_ERROR = 6; |
||
| 16 | const UNKNOWN_ERROR = 255; |
||
| 17 | |||
| 18 | class RestAPI |
||
| 19 | { |
||
| 20 | public function setup($app) |
||
| 21 | { |
||
| 22 | return $app->any('[/]', $this); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function validateLoggedIn($request) |
||
| 26 | { |
||
| 27 | $this->user = $request->getAttribute('user'); |
||
|
0 ignored issues
–
show
|
|||
| 28 | if($this->user === false) |
||
| 29 | { |
||
| 30 | throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: