HasContentType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A matches() 0 7 3
A toString() 0 3 1
A failureDescription() 0 4 2
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 HasContentType extends Constraint
10
{
11
    /**
12
     * @var string
13
     */
14
    private $contentType;
15
16
    /**
17
     * HasContentType constructor.
18
     *
19
     * @param string $contentType
20
     */
21 10
    public function __construct($contentType)
22
    {
23 10
        $this->contentType = $contentType;
24 10
    }
25
26 7
    protected function matches($other): bool
27
    {
28 7
        if ($other instanceof ResponseInterface) {
29 6
            return $other->hasHeader('Content-Type')
30 6
                && ($other->getHeaderLine('Content-Type') === $this->contentType);
31
        }
32 1
        return false;
33
    }
34
35 1
    public function toString(): string
36
    {
37 1
        return \sprintf("has expected Content-Type '%s'", $this->contentType);
38
    }
39
40
    /**
41
     * @return string
42
     */
43 1
    protected function failureDescription($other): string
44
    {
45 1
        $contentType = $other instanceof ResponseInterface ? $other->getHeaderLine('Content-Type') : (string) $other;
46 1
        return 'a HTTP Response with Content-Type \'' . $contentType . '\' ' . $this->toString();
47
    }
48
}
49