| Conditions | 12 |
| Paths | 256 |
| Total Lines | 59 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 42 | public static function create( |
||
| 43 | string $method, |
||
| 44 | string $url, |
||
| 45 | array $params = [], |
||
| 46 | array $headers = [], |
||
| 47 | array $files = [] |
||
| 48 | ) { |
||
| 49 | $parsed = parse_url($url); |
||
| 50 | |||
| 51 | $server = Server::getInstance(); |
||
| 52 | |||
| 53 | $server->flush(); |
||
| 54 | |||
| 55 | $server->set('REQUEST_METHOD', strtoupper($method)); |
||
| 56 | |||
| 57 | $path = isset($parsed['path']) ? ltrim($parsed['path'], '/') : '/'; |
||
| 58 | |||
| 59 | $server->set('REQUEST_URI', $path); |
||
| 60 | |||
| 61 | if (isset($parsed['scheme'])) { |
||
| 62 | $server->set('REQUEST_SCHEME', $parsed['scheme']); |
||
| 63 | $server->set('HTTPS', $parsed['scheme'] === 'https' ? 'on' : 'off'); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (isset($parsed['host'])) { |
||
| 67 | $server->set('HTTP_HOST', $parsed['host']); |
||
| 68 | $server->set('SERVER_NAME', $parsed['host']); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (isset($parsed['port'])) { |
||
| 72 | $server->set('SERVER_PORT', $parsed['port']); |
||
| 73 | } else { |
||
| 74 | $server->set('SERVER_PORT', ($parsed['scheme'] ?? '') === 'https' ? 443 : 80); |
||
| 75 | } |
||
| 76 | |||
| 77 | if (isset($parsed['query'])) { |
||
| 78 | $server->set('QUERY_STRING', $parsed['query']); |
||
| 79 | } else { |
||
| 80 | $server->set('QUERY_STRING', ''); |
||
| 81 | } |
||
| 82 | |||
| 83 | self::detectAndSetContentType($server, $params, $files); |
||
| 84 | |||
| 85 | if ($headers !== []) { |
||
| 86 | foreach ($headers as $name => $value) { |
||
| 87 | $server->set('HTTP_' . strtoupper(str_replace('-', '_', $name)), $value); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | self::flush(); |
||
| 92 | |||
| 93 | self::init($server); |
||
| 94 | |||
| 95 | if ($params !== []) { |
||
| 96 | self::setRequestParams($params); |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($files !== []) { |
||
| 100 | self::setUploadedFiles(self::handleFiles($files)); |
||
| 101 | } |
||
| 122 |