Completed
Push — master ( 156e6d...37b0e3 )
by Marcel
03:16
created

HeaderValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRule() 0 6 1
A conforms() 0 14 3
1
<?php
2
3
namespace UMA\Psr\Http\Message\Internal;
4
5
use Psr\Http\Message\MessageInterface;
6
7
class HeaderValidator
8
{
9
    private $rules = [];
10
11
    /**
12
     * @param string $header
13
     * @param string $rule
14
     *
15
     * @return HeaderValidator
16
     */
17 91
    public function addRule($header, $rule)
18
    {
19 91
        $this->rules[$header] = $rule;
20
21 91
        return $this;
22
    }
23
24
    /**
25
     * @param MessageInterface $message
26
     *
27
     * @return array|bool
28
     */
29 91
    public function conforms(MessageInterface $message)
30
    {
31 91
        $allMatches = [];
32
33 91
        foreach ($this->rules as $header => $rule) {
34 91
            if (0 === preg_match($rule, $message->getHeaderLine($header), $matches)) {
35 91
                return false;
36
            }
37
38 77
            $allMatches[$header] = $matches;
39 77
        }
40
41 70
        return $allMatches;
42
    }
43
}
44