Conditions | 6 |
Paths | 6 |
Total Lines | 54 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
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 |
||
15 | private string $endpoint = 'https://sts.itau.com.br/seguranca/v1/certificado/solicitacao'; |
||
16 | |||
17 | public function criarCertificado(string $token, string $certificadoCSR) |
||
18 | { |
||
19 | return $this->executeRequest($token, $certificadoCSR); |
||
20 | } |
||
21 | |||
22 | public function renovarCertificado(Itau $credentials, string $certificadoCSR) |
||
23 | { |
||
24 | echo "<h1>API</h1>"; |
||
25 | var_dump($credentials->getAuthorizationToken()); |
||
|
|||
26 | if (!$credentials->getAuthorizationToken()) { |
||
27 | echo '<hr>'; |
||
28 | var_dump($credentials); |
||
29 | new Request($credentials); |
||
30 | } |
||
31 | $token = $credentials->getAuthorizationToken(); |
||
32 | echo '<hr>'; |
||
33 | var_dump($token); |
||
34 | return $this->executeRequest($token, $certificadoCSR); |
||
35 | } |
||
36 | |||
37 | private function executeRequest(string $token, string $certificadoCSR) |
||
38 | { |
||
39 | $headers = [ |
||
40 | 'Content-Type: text/plain', |
||
41 | 'Authorization: Bearer ' . $token |
||
42 | ]; |
||
43 | |||
44 | $curl = curl_init(); |
||
45 | |||
46 | curl_setopt_array($curl, [ |
||
47 | CURLOPT_URL => $this->endpoint, |
||
48 | CURLOPT_HTTPHEADER => $headers, |
||
49 | CURLOPT_RETURNTRANSFER => true, |
||
50 | CURLOPT_CUSTOMREQUEST => 'POST', |
||
51 | CURLOPT_POSTFIELDS => $certificadoCSR, |
||
52 | ]); |
||
53 | |||
54 | try { |
||
55 | $response = curl_exec($curl); |
||
56 | } catch (Exception $e) { |
||
57 | curl_close($curl); |
||
58 | throw new ItauException($e->getMessage(), 100); |
||
59 | } |
||
60 | |||
61 | if ($response === false) { |
||
62 | $error = curl_error($curl); |
||
63 | curl_close($curl); |
||
64 | throw new ItauException('CURL Error: ' . $error, 100); |
||
65 | } |
||
66 | |||
67 | $statusCode = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); |
||
68 | curl_close($curl); |
||
69 | |||
94 |