| Conditions | 4 | 
| Paths | 4 | 
| Total Lines | 14 | 
| Code Lines | 10 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 20 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 1 | 
| 1 | <?php | ||
| 40 | private function authorizeApi() | ||
|  | |||
| 41 |     { | ||
| 42 |         if (!isset($_SERVER['HTTP_AUTHORIZATION'])) { | ||
| 43 | http_response_code(401); | ||
| 44 |             $this->returnErrorJson(Craft::t('Authorization header missing')); | ||
| 45 | } | ||
| 46 | $key = $_SERVER['HTTP_AUTHORIZATION']; | ||
| 47 |         list($bearer, $token) = explode(' ', $key); | ||
| 48 |         if ($bearer != 'Bearer' || !craft()->apiAuth->authenticateKey($token)) { | ||
| 49 | http_response_code(401); | ||
| 50 |             $this->returnErrorJson(Craft::t('Invalid key used')); | ||
| 51 | } | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | 
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: