HeaderIsEqualTo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
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 48
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A matches() 0 8 3
A toString() 0 3 1
A failureDescription() 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 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