Code Duplication    Length = 26-26 lines in 2 locations

src/Rules/Seo/PageSpeedRule.php 1 location

@@ 12-37 (lines=26) @@
9
/**
10
 * This rule checks if a given json file is valid.
11
 */
12
class RobotsDisallowAllRule implements Rule
13
{
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

src/Rules/Seo/RobotsDisallowAllRule.php 1 location

@@ 12-37 (lines=26) @@
9
/**
10
 * This rule checks if a given json file is valid.
11
 */
12
class RobotsDisallowAllRule implements Rule
13
{
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