Conditions | 11 |
Paths | 10 |
Total Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
81 | protected function extractMultipart(Request $request, $values) { |
||
82 | // The request body parameters might contain file upload mutations. We treat |
||
83 | // them according to the graphql multipart request specification. |
||
84 | // |
||
85 | // @see https://github.com/jaydenseric/graphql-multipart-request-spec#server |
||
86 | if ($body = JsonHelper::decodeParams($request->request->all())) { |
||
87 | // Flatten the operations array if it exists. |
||
88 | $operations = isset($body['operations']) && is_array($body['operations']) ? $body['operations'] : []; |
||
89 | $values = array_merge($values, $body, $operations); |
||
90 | } |
||
91 | |||
92 | // According to the graphql multipart request specification, uploaded files |
||
93 | // are referenced to variable placeholders in a map. Here, we resolve this |
||
94 | // map by assigning the uploaded files to the corresponding variables. |
||
95 | if (!empty($values['map']) && is_array($values['map']) && $files = $request->files->all()) { |
||
96 | foreach ($files as $key => $file) { |
||
97 | if (!isset($values['map'][$key])) { |
||
98 | continue; |
||
99 | } |
||
100 | |||
101 | $paths = (array) $values['map'][$key]; |
||
102 | foreach ($paths as $path) { |
||
103 | $path = explode('.', $path); |
||
104 | |||
105 | if (NestedArray::keyExists($values, $path)) { |
||
106 | NestedArray::setValue($values, $path, $file); |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | return $values; |
||
113 | } |
||
114 | |||
117 |