| Conditions | 10 |
| Paths | 76 |
| Total Lines | 37 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 30 | public function collect(): array |
||
| 31 | { |
||
| 32 | $domains = WebsiteUtil::extractDomains($this->inventory); |
||
| 33 | |||
| 34 | $badHeaders = []; |
||
| 35 | |||
| 36 | foreach ($domains as $domain) { |
||
| 37 | try { |
||
| 38 | $url = $domain; |
||
| 39 | if (!str_starts_with($url, 'http')) $url = 'https://' . $url; |
||
| 40 | $response = $this->client->get($url); |
||
| 41 | } catch (ClientException $e) { |
||
| 42 | $response = $e->getResponse(); |
||
| 43 | } catch (ServerException $e) { |
||
| 44 | $response = $e->getResponse(); |
||
| 45 | } catch (\Exception $e) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | $headers = $response->getHeaders(); |
||
| 50 | |||
| 51 | if (array_key_exists('Server', $headers)) { |
||
| 52 | if (str_contains($headers['Server'][0], 'Apache/')) { |
||
| 53 | $badHeaders[$domain]['apache_version'] = $headers['Server'][0]; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | if (array_key_exists('X-Powered-By', $headers)) { |
||
| 58 | if (str_contains($headers['X-Powered-By'][0], 'PHP/')) { |
||
| 59 | $badHeaders[$domain]['php_version'] = $headers['X-Powered-By'][0]; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | var_dump($badHeaders); |
||
|
|
|||
| 65 | |||
| 66 | return $badHeaders; |
||
| 67 | } |
||
| 69 |