Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3.009 |
Changes | 0 |
1 | <?php |
||
21 | 7 | public function createServerRequestFromArray(array $server) |
|
|
|||
22 | { |
||
23 | 7 | if (!isset($server['REQUEST_METHOD'])) { |
|
24 | throw new \InvalidArgumentException('Cannot determine HTTP method'); |
||
25 | } |
||
26 | // TODO: find a MUCH better way |
||
27 | 7 | $method = $server['REQUEST_METHOD']; |
|
28 | 7 | $SERVER = $_SERVER; |
|
29 | 7 | $_SERVER = $server; |
|
30 | // Until https://github.com/guzzle/psr7/pull/116 is resolved |
||
31 | 7 | if (!isset($_SERVER['HTTPS'])) { |
|
32 | 7 | $_SERVER['HTTPS'] = 'off'; |
|
33 | } |
||
34 | 7 | $uri = ServerRequest::getUriFromGlobals(); |
|
35 | |||
36 | 7 | return new ServerRequest($method, $uri, [], null, '1.1', $server); |
|
37 | } |
||
38 | } |
||
39 |
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: