MaxAgeRule::validate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8

Duplication

Lines 3
Ratio 37.5 %

Importance

Changes 0
Metric Value
dl 3
loc 8
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Http\Header\Cache;
4
5
use Psr\Http\Message\ResponseInterface;
6
use whm\Smoke\Rules\Rule;
7
use whm\Smoke\Rules\ValidationFailedException;
8
9
/**
10
 * Checks if the max-age cache header is not 0.
11
 */
12
class MaxAgeRule implements Rule
13
{
14
    private $maxStatusCode;
15
16
    public function init($maxStatusCode = 200)
17
    {
18
        $this->maxStatusCode = $maxStatusCode;
19
    }
20
21
    public function validate(ResponseInterface $response)
22
    {
23
        if ($response->getStatusCode() <= $this->maxStatusCode) {
24 View Code Duplication
            if ($response->hasHeader('Cache-Control') && false !== strpos($response->getHeader('Cache-Control')[0], 'max-age=0')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
                throw new ValidationFailedException('max-age=0 was found');
26
            }
27
        }
28
    }
29
}
30