| Conditions | 6 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function createServerRequest(array $server, $method = null, $uri = null) |
||
|
1 ignored issue
–
show
|
|||
| 19 | { |
||
| 20 | if (null === $method && isset($server['REQUEST_METHOD'])) { |
||
| 21 | $method = $server['REQUEST_METHOD']; |
||
| 22 | } |
||
| 23 | if (null === $method) { |
||
| 24 | throw new \InvalidArgumentException('Cannot determine HTTP method'); |
||
| 25 | } |
||
| 26 | // TODO: find a MUCH better way |
||
| 27 | if (null === $uri) { |
||
| 28 | $SERVER = $_SERVER; |
||
| 29 | $_SERVER = $server; |
||
| 30 | // Until https://github.com/guzzle/psr7/pull/116 is resolved |
||
| 31 | if (!isset($_SERVER['HTTPS'])) { |
||
| 32 | $_SERVER['HTTPS'] = 'off'; |
||
| 33 | } |
||
| 34 | $uri = ServerRequest::getUriFromGlobals(); |
||
| 35 | $_SERVER = $SERVER; |
||
| 36 | unset($SERVER); |
||
| 37 | } |
||
| 38 | |||
| 39 | return new ServerRequest($method, $uri, [], null, '1.1', $server); |
||
| 40 | } |
||
| 41 | } |
||
| 42 |
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: