Conditions | 4 |
Paths | 6 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
23 | 7 | public function by(Request $request, $params) |
|
|
|||
24 | { |
||
25 | 7 | $callbackResponse = false; |
|
26 | |||
27 | 7 | if (isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
28 | 3 | $callbackResponse = call_user_func_array( |
|
29 | 3 | $this->callback, |
|
30 | 3 | array_merge(explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))), $params) |
|
31 | ); |
||
32 | 5 | } elseif (isset($_SERVER['PHP_AUTH_USER'])) { |
|
33 | 3 | $callbackResponse = call_user_func_array( |
|
34 | 3 | $this->callback, |
|
35 | 3 | array_merge(array($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']), $params) |
|
36 | ); |
||
37 | } |
||
38 | |||
39 | 7 | if ($callbackResponse === false) { |
|
40 | 3 | header('HTTP/1.1 401'); |
|
41 | 3 | header("WWW-Authenticate: Basic realm=\"{$this->realm}\""); |
|
42 | |||
43 | 3 | return call_user_func($this->callback, null, null); |
|
44 | } |
||
45 | |||
46 | 4 | return $callbackResponse; |
|
47 | } |
||
48 | } |
||
49 |
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: