Conditions | 20 |
Paths | 15360 |
Total Lines | 65 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
24 | public function toIlluminateRequest(array $rawServer = [], array $rawEnv = []) |
||
25 | { |
||
26 | $__GET = isset($this->swooleRequest->get) ? $this->swooleRequest->get : []; |
||
27 | $__POST = isset($this->swooleRequest->post) ? $this->swooleRequest->post : []; |
||
28 | $__COOKIE = isset($this->swooleRequest->cookie) ? $this->swooleRequest->cookie : []; |
||
29 | $server = isset($this->swooleRequest->server) ? $this->swooleRequest->server : []; |
||
30 | $headers = isset($this->swooleRequest->header) ? $this->swooleRequest->header : []; |
||
31 | $__FILES = isset($this->swooleRequest->files) ? $this->swooleRequest->files : []; |
||
32 | $__CONTENT = empty($__FILES) ? $this->swooleRequest->rawContent() : ''; // Cannot call rawContent() to avoid double the file memory when uploading a file. |
||
33 | $_REQUEST = []; |
||
34 | $_SESSION = []; |
||
35 | |||
36 | static $headerServerMapping = [ |
||
37 | 'x-real-ip' => 'REMOTE_ADDR', |
||
38 | 'x-real-port' => 'REMOTE_PORT', |
||
39 | 'server-protocol' => 'SERVER_PROTOCOL', |
||
40 | 'server-name' => 'SERVER_NAME', |
||
41 | 'server-addr' => 'SERVER_ADDR', |
||
42 | 'server-port' => 'SERVER_PORT', |
||
43 | 'scheme' => 'REQUEST_SCHEME', |
||
44 | ]; |
||
45 | |||
46 | $_ENV = $rawEnv; |
||
47 | $_SERVER = $rawServer; |
||
48 | foreach ($headers as $key => $value) { |
||
49 | // Fix client && server's info |
||
50 | if (isset($headerServerMapping[$key])) { |
||
51 | $server[$headerServerMapping[$key]] = $value; |
||
52 | } else { |
||
53 | $key = str_replace('-', '_', $key); |
||
54 | $server['http_' . $key] = $value; |
||
55 | } |
||
56 | } |
||
57 | $server = array_change_key_case($server, CASE_UPPER); |
||
58 | $_SERVER = array_merge($_SERVER, $server); |
||
59 | if (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') { |
||
60 | $_SERVER['HTTPS'] = 'on'; |
||
61 | } |
||
62 | |||
63 | // Fix REQUEST_URI with QUERY_STRING |
||
64 | if (strpos($_SERVER['REQUEST_URI'], '?') === false |
||
65 | && isset($_SERVER['QUERY_STRING']) |
||
66 | && $_SERVER['QUERY_STRING'] !== '' |
||
67 | ) { |
||
68 | $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
||
69 | } |
||
70 | |||
71 | // Fix argv & argc |
||
72 | if (!isset($_SERVER['argv'])) { |
||
73 | $_SERVER['argv'] = isset($GLOBALS['argv']) ? $GLOBALS['argv'] : []; |
||
74 | $_SERVER['argc'] = isset($GLOBALS['argc']) ? $GLOBALS['argc'] : 0; |
||
75 | } |
||
76 | |||
77 | // Initialize laravel request |
||
78 | IlluminateRequest::enableHttpMethodParameterOverride(); |
||
79 | $request = IlluminateRequest::createFromBase(new \Symfony\Component\HttpFoundation\Request($__GET, $__POST, [], $__COOKIE, $__FILES, $_SERVER, $__CONTENT)); |
||
80 | |||
81 | if (0 === strpos($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
||
82 | && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH']) |
||
83 | ) { |
||
84 | parse_str($request->getContent(), $data); |
||
85 | $request->request = new ParameterBag($data); |
||
86 | } |
||
87 | |||
88 | return $request; |
||
89 | } |
||
91 |