Completed
Push — master ( a22340...df9c14 )
by Nils
04:26
created

PageSpeedRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 23 5
1
<?php
2
3
namespace whm\Smoke\Rules\Seo;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\Rule;
7
use whm\Smoke\Rules\ValidationFailedException;
8
9
/**
10
 * This rule checks if a given json file is valid.
11
 */
12
class PageSpeedRule 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';
0 ignored issues
show
Unused Code introduced by
$robotsUrl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
        } elseif (substr_count($url, '/') === 3) {
21
            $filename = $robotsUrl = $url . 'robots.txt';
0 ignored issues
show
Unused Code introduced by
$robotsUrl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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