Conditions | 10 |
Paths | 128 |
Total Lines | 46 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
38 | public static function create(string $method, string $url, array $data = null, array $files = null): void |
||
39 | { |
||
40 | $parsed = parse_url($url); |
||
41 | |||
42 | $server = Server::getInstance(); |
||
43 | |||
44 | $server->set('REQUEST_METHOD', strtoupper($method)); |
||
45 | |||
46 | $path = isset($parsed['path']) ? ltrim($parsed['path'], '/') : '/'; |
||
47 | |||
48 | $server->set('REQUEST_URI', $path); |
||
49 | |||
50 | if (isset($parsed['scheme'])) { |
||
51 | $server->set('REQUEST_SCHEME', $parsed['scheme']); |
||
52 | $server->set('HTTPS', $parsed['scheme'] === 'https' ? 'on' : 'off'); |
||
53 | } |
||
54 | |||
55 | if (isset($parsed['host'])) { |
||
56 | $server->set('HTTP_HOST', $parsed['host']); |
||
57 | $server->set('SERVER_NAME', $parsed['host']); |
||
58 | } |
||
59 | |||
60 | if (isset($parsed['port'])) { |
||
61 | $server->set('SERVER_PORT', $parsed['port']); |
||
62 | } else { |
||
63 | $server->set('SERVER_PORT', ($parsed['scheme'] ?? '') === 'https' ? 443 : 80); |
||
64 | } |
||
65 | |||
66 | if (isset($parsed['query'])) { |
||
67 | $server->set('QUERY_STRING', $parsed['query']); |
||
68 | } else { |
||
69 | $server->set('QUERY_STRING', ''); |
||
70 | } |
||
71 | |||
72 | self::detectAndSetContentType($server, $data, $files); |
||
73 | |||
74 | static::flush(); |
||
75 | |||
76 | static::init(Server::getInstance()); |
||
77 | |||
78 | if ($data) { |
||
79 | self::setRequestParams($data); |
||
80 | } |
||
81 | |||
82 | if ($files) { |
||
83 | self::setUploadedFiles(self::handleFiles($files)); |
||
84 | } |
||
104 | } |