| Conditions | 4 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 43 | public function getSensiolabVulnerabilties($fileLock) |
||
| 44 | {
|
||
| 45 | $this->addVerboseLog('Send request to sensiolab: <info>'.$fileLock.'</info>');
|
||
| 46 | |||
| 47 | $debug = false;//set to true to log into console output |
||
| 48 | $headers = [ |
||
| 49 | //OPTIONS |
||
| 50 | 'allow_redirects' => [ |
||
| 51 | 'max' => 3, // allow at most 10 redirects. |
||
| 52 | 'strict' => true, // use "strict" RFC compliant redirects. |
||
| 53 | 'referer' => true, // add a Referer header |
||
| 54 | 'protocols' => ['http', 'https'], // only allow http and https URLs |
||
| 55 | 'track_redirects' => false |
||
| 56 | ], |
||
| 57 | 'connect_timeout' => 20,//Use 0 to wait connection indefinitely |
||
| 58 | 'timeout' => 30, //Use 0 to wait response indefinitely |
||
| 59 | 'debug' => $debug, |
||
| 60 | //HEADERS |
||
| 61 | 'headers' => [ |
||
| 62 | 'Accept' => 'application/json' |
||
| 63 | ], |
||
| 64 | //UPLOAD FORM FILE |
||
| 65 | 'multipart' => [ |
||
| 66 | [ |
||
| 67 | 'name' => 'lock', |
||
| 68 | 'contents' => fopen($fileLock, 'r') |
||
| 69 | ] |
||
| 70 | ] |
||
| 71 | ]; |
||
| 72 | $response = null; |
||
| 73 | |||
| 74 | try {
|
||
| 75 | $iResponse = $this->guzzle->request('POST', 'https://security.sensiolabs.org/check_lock', $headers);
|
||
| 76 | $responseBody = $iResponse->getBody()->getContents(); |
||
| 77 | $response = json_decode($responseBody, true); |
||
| 78 | } catch (\GuzzleHttp\Exception\ClientException $e) {
|
||
| 79 | $this->command->error("ClientException!\nMessage: ".$e->getMessage());
|
||
| 80 | $colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode()); |
||
| 81 | $this->command->line("HTTP StatusCode: <{$colorTag}>".$e->getResponse()->getStatusCode()."<{$colorTag}>");
|
||
| 82 | $this->printMessage($e->getResponse()); |
||
| 83 | $this->printMessage($e->getRequest()); |
||
| 84 | } catch (\GuzzleHttp\Exception\RequestException $e) {
|
||
| 85 | $this->command->error("RequestException!\nMessage: ".$e->getMessage());
|
||
| 86 | $this->printMessage($e->getRequest()); |
||
| 87 | if ($e->hasResponse()) {
|
||
| 88 | $colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode()); |
||
| 89 | $this->command->line("HTTP StatusCode: <{$colorTag}>".$e->getResponse()->getStatusCode()."<{$colorTag}>");
|
||
| 90 | $this->printMessage($e->getResponse()); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | return $response; |
||
| 94 | } |
||
| 95 | |||
| 187 | } |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: