Completed
Push — master ( 9ec350...609c82 )
by Nils
03:00
created

SuccessStatusRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A validate() 0 6 2
1
<?php
2
3
namespace whm\Smoke\Rules\Http\Header;
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 the http status code of a request is less than 400.
11
 */
12
class SuccessStatusRule implements Rule
13
{
14
    private $maxStatusCode;
15
16
    public function init($maxStatusCode = 399)
17
    {
18
        $this->maxStatusCode = $maxStatusCode;
19
    }
20
21
    public function validate(Response $response)
22
    {
23
        if ($response->getStatus() > $this->maxStatusCode) {
24
            throw new ValidationFailedException('Status code ' . $response->getStatus() . ' found.');
25
        }
26
    }
27
}
28