HeaderValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

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