| Conditions | 12 |
| Paths | 256 |
| Total Lines | 60 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 43 | public static function create( |
||
| 44 | string $method, |
||
| 45 | string $url, |
||
| 46 | array $params = [], |
||
| 47 | array $headers = [], |
||
| 48 | array $files = [] |
||
| 49 | ) |
||
| 50 | { |
||
| 51 | $parsed = parse_url($url); |
||
| 52 | |||
| 53 | $server = Server::getInstance(); |
||
| 54 | |||
| 55 | $server->flush(); |
||
| 56 | |||
| 57 | $server->set('REQUEST_METHOD', strtoupper($method)); |
||
| 58 | |||
| 59 | $path = isset($parsed['path']) ? ltrim($parsed['path'], '/') : '/'; |
||
| 60 | |||
| 61 | $server->set('REQUEST_URI', $path); |
||
| 62 | |||
| 63 | if (isset($parsed['scheme'])) { |
||
| 64 | $server->set('REQUEST_SCHEME', $parsed['scheme']); |
||
| 65 | $server->set('HTTPS', $parsed['scheme'] === 'https' ? 'on' : 'off'); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (isset($parsed['host'])) { |
||
| 69 | $server->set('HTTP_HOST', $parsed['host']); |
||
| 70 | $server->set('SERVER_NAME', $parsed['host']); |
||
| 71 | } |
||
| 72 | |||
| 73 | if (isset($parsed['port'])) { |
||
| 74 | $server->set('SERVER_PORT', $parsed['port']); |
||
| 75 | } else { |
||
| 76 | $server->set('SERVER_PORT', ($parsed['scheme'] ?? '') === 'https' ? 443 : 80); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (isset($parsed['query'])) { |
||
| 80 | $server->set('QUERY_STRING', $parsed['query']); |
||
| 81 | } else { |
||
| 82 | $server->set('QUERY_STRING', ''); |
||
| 83 | } |
||
| 84 | |||
| 85 | self::detectAndSetContentType($server, $params, $files); |
||
| 86 | |||
| 87 | if ($headers) { |
||
|
|
|||
| 88 | foreach ($headers as $name => $value) { |
||
| 89 | $server->set('HTTP_' . strtoupper($name), $value); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | self::flush(); |
||
| 94 | |||
| 95 | self::init($server); |
||
| 96 | |||
| 97 | if ($params) { |
||
| 98 | self::setRequestParams($params); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($files) { |
||
| 102 | self::setUploadedFiles(self::handleFiles($files)); |
||
| 103 | } |
||
| 123 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.