| Conditions | 5 |
| Paths | 7 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 14 | public function validate(Response $response) |
||
| 15 | { |
||
| 16 | $url = (string) $response->getUri(); |
||
| 17 | |||
| 18 | if (substr_count($url, '/') === 2) { |
||
| 19 | $filename = $robotsUrl = $url . '/robots.txt'; |
||
|
|
|||
| 20 | } elseif (substr_count($url, '/') === 3) { |
||
| 21 | $filename = $robotsUrl = $url . 'robots.txt'; |
||
| 22 | } else { |
||
| 23 | return; |
||
| 24 | } |
||
| 25 | |||
| 26 | if (!file_exists($filename)) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $content = file_get_contents($filename); |
||
| 31 | $normalizedContent = str_replace(' ', '', $content); |
||
| 32 | |||
| 33 | if (strpos($normalizedContent, 'Disallow:/' . PHP_EOL) !== false) { |
||
| 34 | throw new ValidationFailedException('The robots.txt contains disallow all (Disallow: /)'); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.