| Conditions | 10 |
| Paths | 25 |
| Total Lines | 41 |
| 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 |
||
| 38 | public function validate(ResponseInterface $response) |
||
| 39 | { |
||
| 40 | /** @var UriAwareResponse $response */ |
||
| 41 | $uri = $response->getUri(); |
||
| 42 | |||
| 43 | if ('https' !== $uri->getScheme()) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | $htmlDocument = new Document((string)$response->getBody()); |
||
| 48 | |||
| 49 | $resources = $htmlDocument->getDependencies($uri, false); |
||
| 50 | |||
| 51 | $unsecures = array(); |
||
| 52 | |||
| 53 | foreach ($resources as $resource) { |
||
| 54 | if ($resource->getScheme() && 'https' !== $resource->getScheme()) { |
||
| 55 | $excluded = false; |
||
| 56 | foreach ($this->excludedFiles as $excludedFile) { |
||
| 57 | if (preg_match('~' . $excludedFile . '~', (string)$resource)) { |
||
| 58 | $excluded = true; |
||
| 59 | break; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | if (!$excluded) { |
||
| 63 | $unsecures[] = $resource; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (count($unsecures) > 0) { |
||
| 69 | $message = 'At least one dependency was found on a secure url, that was transfered insecure.<ul>'; |
||
| 70 | foreach ($unsecures as $unsecure) { |
||
| 71 | $message .= '<li>' . (string)$unsecure . '</li>'; |
||
| 72 | } |
||
| 73 | $message .= '</ul>'; |
||
| 74 | return new CheckResult(CheckResult::STATUS_FAILURE, $message, count($unsecures)); |
||
| 75 | } else { |
||
| 76 | return new CheckResult(CheckResult::STATUS_SUCCESS, 'No insecure http element found.', 0); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.