Completed
Branch master (1f9106)
by Nils
02:44
created

StandardRule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
doValidation() 0 1 ?
B validate() 0 16 5
A assert() 0 6 2
1
<?php
2
3
namespace whm\Smoke\Rules;
4
5
use whm\Smoke\Http\Response;
6
7
abstract class StandardRule implements Rule
8
{
9
    protected $contentTypes = array();
10
11
    public function validate(Response $response)
12
    {
13
        if (count($this->contentTypes) > 0) {
14
            $valid = false;
15
            foreach ($this->contentTypes as $validContentType) {
16
                if (strpos($response->getContentType(), $validContentType) !== false) {
17
                    $valid = true;
18
                    break;
19
                }
20
            }
21
            if (!$valid) {
22
                return;
23
            }
24
        }
25
        $this->doValidation($response);
26
    }
27
28
    abstract protected function doValidation(Response $response);
29
30
    protected function assert($valueToBeTrue, $errorMessage)
31
    {
32
        if (!$valueToBeTrue) {
33
            throw new ValidationFailedException($errorMessage);
34
        }
35
    }
36
}
37