Passed
Push — master ( 575ff1...6ee2a9 )
by Dominik
03:30
created

RequestManager::getAcceptLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiHttp\Manager;
6
7
use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
8
use Chubbyphp\Deserialization\DeserializerInterface;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
11
final class RequestManager implements RequestManagerInterface
12
{
13
    /**
14
     * @var DeserializerInterface
15
     */
16
    private $deserializer;
17
18
    /**
19
     * @param DeserializerInterface $deserializer
20
     */
21 2
    public function __construct(DeserializerInterface $deserializer)
22
    {
23 2
        $this->deserializer = $deserializer;
24 2
    }
25
26
    /**
27
     * @param Request                      $request
28
     * @param object|string                $object
29
     * @param string                       $contentType
30
     * @param DenormalizerContextInterface $context
31
     *
32
     * @return object
33
     */
34 1
    public function getDataFromRequestBody(
35
        Request $request,
36
        $object,
37
        string $contentType,
38
        DenormalizerContextInterface $context = null
39
    ) {
40 1
        return $this->deserializer->deserialize($object, (string) $request->getBody(), $contentType, $context);
41
    }
42
43
    /**
44
     * @param Request                      $request
45
     * @param object|string                $object
46
     * @param DenormalizerContextInterface $context
47
     *
48
     * @return object
49
     */
50 1
    public function getDataFromRequestQuery(Request $request, $object, DenormalizerContextInterface $context = null)
51
    {
52 1
        return $this->deserializer->denormalize($object, $request->getQueryParams(), $context);
53
    }
54
}
55