HeaderIsEqualTo::matches()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
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 HeaderIsEqualTo extends Constraint
10
{
11 1
    use WithHeaderResponseExporter;
12
13
    /**
14
     * @var string
15
     */
16
    private $header;
17
18
    /**
19
     * @var string
20
     */
21
    private $value;
22
23
    /**
24
     * HeaderIsEqualTo constructor.
25
     *
26
     * @param string $header
27
     * @param string $value
28
     */
29 9
    public function __construct(string $header, string $value)
30
    {
31 9
        $this->header = $header;
32 9
        $this->value = $value;
33 9
    }
34
35 7
    protected function matches($other): bool
36
    {
37 7
        if ($other instanceof ResponseInterface
38 7
            && $other->hasHeader($this->header)
39
        ) {
40 6
            return $other->getHeaderLine($this->header) === $this->value;
41
        }
42 1
        return false;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    protected function failureDescription($other): string
49
    {
50 1
        return $this->exporter()->export($other) . ' ' . $this->toString();
51
    }
52
53
54 1
    public function toString(): string
55
    {
56 1
        return \sprintf(" has value '%s' for header '%s'", $this->value, $this->header);
57
    }
58
}
59