Completed
Push — develop ( e716a3...960a7a )
by Baptiste
02:59
created

Format::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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\ServerRequestInterface;
12
use Negotiation\Negotiator;
13
14
final class Format
15
{
16
    private $accept;
17
    private $contentType;
18
    private $negotiator;
19
20 4
    public function __construct(
21
        Formats $accept,
22
        Formats $contentType
23
    ) {
24 4
        $this->accept = $accept;
25 4
        $this->contentType = $contentType;
26 4
        $this->negotiator = new Negotiator;
27 4
    }
28
29 3
    public function acceptable(ServerRequestInterface $request): FormatFormat
30
    {
31 3
        return $this->accept->matching(
0 ignored issues
show
Bug introduced by
The method matching() does not seem to exist on object<Innmind\Rest\Server\Formats>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
            (string) $request
33 3
                ->headers()
34 3
                ->get('Accept')
35 3
                ->values()
36 3
                ->join(', ')
37
        );
38
    }
39
40 1
    public function contentType(ServerRequestInterface $request): FormatFormat
41
    {
42 1
        return $this->contentType->matching(
0 ignored issues
show
Bug introduced by
The method matching() does not seem to exist on object<Innmind\Rest\Server\Formats>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
            (string) $request
44 1
                ->headers()
45 1
                ->get('Content-Type')
46 1
                ->values()
47 1
                ->current()
48
        );
49
    }
50
}
51