Format::acceptable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle;
5
6
use Innmind\Rest\Server\{
7
    Formats,
8
    Format\Format as FormatFormat,
9
    Format\MediaType
10
};
11
use Innmind\Http\Message\ServerRequest;
12
use Negotiation\Negotiator;
13
14
final class Format
15
{
16
    private $accept;
17
    private $contentType;
18
    private $negotiator;
19
20 28
    public function __construct(
21
        Formats $accept,
22
        Formats $contentType
23
    ) {
24 28
        $this->accept = $accept;
25 28
        $this->contentType = $contentType;
26 28
        $this->negotiator = new Negotiator;
27 28
    }
28
29 14
    public function acceptable(ServerRequest $request): FormatFormat
30
    {
31 14
        return $this->accept->matching(
32
            (string) $request
33 14
                ->headers()
34 14
                ->get('Accept')
35 14
                ->values()
36 14
                ->join(', ')
37
        );
38
    }
39
40 6
    public function contentType(ServerRequest $request): FormatFormat
41
    {
42 6
        return $this->contentType->matching(
43
            (string) $request
44 6
                ->headers()
45 6
                ->get('Content-Type')
46 6
                ->values()
47 6
                ->current()
48
        );
49
    }
50
}
51