HeaderContains   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 47
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 8 3
A __construct() 0 4 1
A failureDescription() 0 3 1
A toString() 0 3 1
1
<?php declare(strict_types=1);
2
3
4
namespace Pitchart\Phlunit\Constraint\HttpResponse;
5
6
use PHPUnit\Framework\Constraint\Constraint;
7
use Psr\Http\Message\ResponseInterface;
8
9
class HeaderContains extends Constraint
10
{
11 1
    use WithHeaderResponseExporter;
12
    /**
13
     * @var string
14
     */
15
    private $header;
16
17
    /**
18
     * @var string
19
     */
20
    private $value;
21
22
    /**
23
     * HeaderIsEqualTo constructor.
24
     *
25
     * @param string $header
26
     * @param string $value
27
     */
28 13
    public function __construct(string $header, string $value)
29
    {
30 13
        $this->header = $header;
31 13
        $this->value = $value;
32 13
    }
33
34 10
    protected function matches($other): bool
35
    {
36 10
        if ($other instanceof ResponseInterface
37 10
            && $other->hasHeader($this->header)
38
        ) {
39 9
            return (bool) \preg_match('/' . \preg_quote($this->value) . '/i', $other->getHeaderLine($this->header));
40
        }
41 1
        return false;
42
    }
43
44
    /**
45
     * @return string
46
     */
47 1
    protected function failureDescription($other): string
48
    {
49 1
        return $this->exporter()->export($other) . ' ' . $this->toString();
50
    }
51
52
53 1
    public function toString(): string
54
    {
55 1
        return \sprintf(" contains value '%s' for header '%s'", $this->value, $this->header);
56
    }
57
}
58