| Conditions | 8 | 
| Paths | 28 | 
| Total Lines | 71 | 
| Code Lines | 44 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 25 | ||
| 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  | 
            ||
| 118 | private function send(Itau $credentials, $fullUrl, $method, $jsonBody = null)  | 
            ||
| 119 |     { | 
            ||
| 120 | $curl = curl_init($fullUrl);  | 
            ||
| 121 | |||
| 122 | $defaultCurlOptions = array(  | 
            ||
| 123 | CURLOPT_CONNECTTIMEOUT => 60,  | 
            ||
| 124 | CURLOPT_RETURNTRANSFER => true,  | 
            ||
| 125 | CURLOPT_TIMEOUT => 60,  | 
            ||
| 126 | CURLOPT_VERBOSE => 0,  | 
            ||
| 127 | CURLOPT_HTTPHEADER => array(  | 
            ||
| 128 | 'Content-Type: application/json; charset=utf-8'  | 
            ||
| 129 | ),  | 
            ||
| 130 | CURLOPT_SSLCERT => $credentials->getCertificate(),  | 
            ||
| 131 | CURLOPT_SSLKEY => $credentials->getCertificateKey(),  | 
            ||
| 132 | CURLOPT_CAINFO => $credentials->getCertificate(),  | 
            ||
| 133 | CURLOPT_SSL_VERIFYHOST => 2,  | 
            ||
| 134 | CURLOPT_SSL_VERIFYPEER => 0  | 
            ||
| 135 | );  | 
            ||
| 136 | |||
| 137 | $defaultCurlOptions[CURLOPT_HTTPHEADER][] = 'Authorization: Bearer ' . $credentials->getAuthorizationToken();  | 
            ||
| 138 | $defaultCurlOptions[CURLOPT_HTTPHEADER][] = 'x-itau-apikey: ' . $credentials->getClientId();  | 
            ||
| 139 | $defaultCurlOptions[CURLOPT_HTTPHEADER][] = 'x-itau-correlationID: 2';  | 
            ||
| 140 | |||
| 141 | // Add custom method  | 
            ||
| 142 | if (in_array($method, [  | 
            ||
| 143 | self::CURL_TYPE_DELETE,  | 
            ||
| 144 | self::CURL_TYPE_PUT,  | 
            ||
| 145 | self::CURL_TYPE_GET,  | 
            ||
| 146 | 'PATCH'  | 
            ||
| 147 |         ])) { | 
            ||
| 148 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);  | 
            ||
| 149 | }  | 
            ||
| 150 | |||
| 151 | // Add body params  | 
            ||
| 152 |         if (! empty($jsonBody)) { | 
            ||
| 153 | curl_setopt($curl, CURLOPT_POST, 1);  | 
            ||
| 154 | curl_setopt($curl, CURLOPT_POSTFIELDS, is_string($jsonBody) ? $jsonBody : json_encode($jsonBody));  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | curl_setopt_array($curl, $defaultCurlOptions);  | 
            ||
| 158 | |||
| 159 | $response = null;  | 
            ||
| 160 | $errorMessage = '';  | 
            ||
| 161 | |||
| 162 |         try { | 
            ||
| 163 | $response = curl_exec($curl);  | 
            ||
| 164 |         } catch (Exception $e) { | 
            ||
| 165 |             throw new ItauException("Request Exception, error: {$e->getMessage()}", 100); | 
            ||
| 166 | }  | 
            ||
| 167 | |||
| 168 | // Verify error  | 
            ||
| 169 |         if ($response === false) { | 
            ||
| 170 | $errorMessage = curl_error($curl);  | 
            ||
| 171 | }  | 
            ||
| 172 | |||
| 173 | $statusCode = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);  | 
            ||
| 174 | curl_close($curl);  | 
            ||
| 175 | |||
| 176 |         if ($statusCode >= 400) { | 
            ||
| 177 | // TODO see what it means code 100  | 
            ||
| 178 | throw new ItauException($response, 100);  | 
            ||
| 179 | }  | 
            ||
| 180 | |||
| 181 | $responseDecode = json_decode($response, true);  | 
            ||
| 182 |         if(is_null($responseDecode)){ | 
            ||
| 183 | $responseDecode = ['status_code' => $statusCode];  | 
            ||
| 184 |         } else { | 
            ||
| 185 | array_push($responseDecode, ['status_code' => $statusCode]);  | 
            ||
| 186 | }  | 
            ||
| 187 | |||
| 188 | return $responseDecode;  | 
            ||
| 189 | }  | 
            ||
| 191 |