Format   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 2
cbo 4
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A acceptable() 0 10 1
A contentType() 0 10 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