RequestManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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;
10
11
final class RequestManager implements RequestManagerInterface
12
{
13
    /**
14
     * @var DeserializerInterface
15
     */
16
    private $deserializer;
17
18
    public function __construct(DeserializerInterface $deserializer)
19
    {
20
        $this->deserializer = $deserializer;
21 2
    }
22
23 2
    /**
24 2
     * @param object|string $object
25
     *
26
     * @return object
27
     */
28
    public function getDataFromRequestQuery(
29
        ServerRequestInterface $request,
30
        $object,
31
        DenormalizerContextInterface $context = null
32
    ) {
33 1
        return $this->deserializer->denormalize($object, $request->getQueryParams(), $context);
34
    }
35
36
    /**
37
     * @param object|string $object
38 1
     *
39
     * @return object
40
     */
41
    public function getDataFromRequestBody(
42
        ServerRequestInterface $request,
43
        $object,
44
        string $contentType,
45
        DenormalizerContextInterface $context = null
46
    ) {
47
        return $this->deserializer->deserialize($object, (string) $request->getBody(), $contentType, $context);
48
    }
49
}
50