| Conditions | 10 |
| Paths | 38 |
| Total Lines | 43 |
| Code Lines | 28 |
| 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 |
||
| 121 | public function getMenu( |
||
| 122 | string $token, |
||
| 123 | string $userEmail, |
||
| 124 | bool $isMobile = false |
||
| 125 | ): array { |
||
| 126 | $response = []; |
||
| 127 | $menuUrl = $isMobile ? (string) $this->get('mobile_menu_url') : (string) $this->get('normal_menu_url'); |
||
| 128 | if (!empty($menuUrl) && !empty($token) && !empty($userEmail)) { |
||
| 129 | $menuUrl = substr($menuUrl, -1) === '/' ? $menuUrl : $menuUrl.'/'; |
||
| 130 | $curl = curl_init(); |
||
| 131 | |||
| 132 | curl_setopt_array($curl, [ |
||
| 133 | CURLOPT_URL => $menuUrl.$userEmail, |
||
| 134 | CURLOPT_RETURNTRANSFER => true, |
||
| 135 | CURLOPT_ENCODING => '', |
||
| 136 | CURLOPT_MAXREDIRS => 10, |
||
| 137 | CURLOPT_TIMEOUT => 5, |
||
| 138 | CURLOPT_NOSIGNAL => 1, |
||
| 139 | CURLOPT_FOLLOWLOCATION => true, |
||
| 140 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||
| 141 | CURLOPT_CUSTOMREQUEST => 'GET', |
||
| 142 | CURLOPT_HTTPHEADER => [ |
||
| 143 | "Authorization: Bearer $token", |
||
| 144 | ], |
||
| 145 | ]); |
||
| 146 | |||
| 147 | $curlResponse = curl_exec($curl); |
||
| 148 | if (false !== $curlResponse) { |
||
| 149 | $curlResponse = json_decode($curlResponse, true); |
||
| 150 | if (isset($curlResponse['data']['data']['html']['data'])) { |
||
| 151 | $response['html'] = $curlResponse['data']['data']['html']['data']; |
||
| 152 | } |
||
| 153 | if (isset($curlResponse['data']['data']['css']['data'])) { |
||
| 154 | $response['css'] = $curlResponse['data']['data']['css']['data']; |
||
| 155 | } |
||
| 156 | if (isset($curlResponse['data']['data']['js']['data'])) { |
||
| 157 | $response['js'] = $curlResponse['data']['data']['js']['data']; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | curl_close($curl); |
||
| 161 | } |
||
| 162 | |||
| 163 | return $response; |
||
| 164 | } |
||
| 195 |