HeaderValidator::addRule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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