Conditions | 4 |
Paths | 10 |
Total Lines | 52 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Tests | 36 |
CRAP Score | 4 |
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 |
||
43 | 10 | public function getSensiolabVulnerabilties($fileLock) |
|
44 | { |
||
45 | 10 | $this->addVerboseLog('Send request to sensiolab: <info>'.$fileLock.'</info>'); |
|
46 | |||
47 | 10 | $debug = false;//set to true to log into console output |
|
48 | $headers = [ |
||
49 | //OPTIONS |
||
50 | 'allow_redirects' => [ |
||
51 | 10 | 'max' => 3, // allow at most 10 redirects. |
|
52 | 10 | 'strict' => true, // use "strict" RFC compliant redirects. |
|
53 | 10 | 'referer' => true, // add a Referer header |
|
54 | 10 | 'protocols' => ['http', 'https'], // only allow http and https URLs |
|
55 | 'track_redirects' => false |
||
56 | 10 | ], |
|
57 | 10 | 'connect_timeout' => 20,//Use 0 to wait connection indefinitely |
|
58 | 10 | 'timeout' => 30, //Use 0 to wait response indefinitely |
|
59 | 10 | 'debug' => $debug, |
|
60 | //HEADERS |
||
61 | 'headers' => [ |
||
62 | 'Accept' => 'application/json' |
||
63 | 10 | ], |
|
64 | //UPLOAD FORM FILE |
||
65 | 'multipart' => [ |
||
66 | [ |
||
67 | 10 | 'name' => 'lock', |
|
68 | 10 | 'contents' => fopen($fileLock, 'r') |
|
69 | 10 | ] |
|
70 | 10 | ] |
|
71 | 10 | ]; |
|
72 | 10 | $response = null; |
|
73 | |||
74 | try { |
||
75 | 10 | $iResponse = $this->guzzle->request('POST', 'https://security.sensiolabs.org/check_lock', $headers); |
|
76 | 4 | $responseBody = $iResponse->getBody()->getContents(); |
|
77 | 4 | $response = json_decode($responseBody, true); |
|
78 | 10 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
79 | 4 | $this->command->error("ClientException!\nMessage: ".$e->getMessage()); |
|
80 | 4 | $colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode()); |
|
81 | 4 | $this->command->line("HTTP StatusCode: <{$colorTag}>".$e->getResponse()->getStatusCode()."<{$colorTag}>"); |
|
82 | 4 | $this->printMessage($e->getResponse()); |
|
83 | 4 | $this->printMessage($e->getRequest()); |
|
84 | 6 | } catch (\GuzzleHttp\Exception\RequestException $e) { |
|
85 | 4 | $this->command->error("RequestException!\nMessage: ".$e->getMessage()); |
|
86 | 4 | $this->printMessage($e->getRequest()); |
|
87 | 4 | if ($e->hasResponse()) { |
|
88 | 2 | $colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode()); |
|
89 | 2 | $this->command->line("HTTP StatusCode: <{$colorTag}>".$e->getResponse()->getStatusCode()."<{$colorTag}>"); |
|
90 | 2 | $this->printMessage($e->getResponse()); |
|
91 | 2 | } |
|
92 | } |
||
93 | 10 | return $response; |
|
94 | } |
||
95 | |||
188 | } |