RequestManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 37
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataFromRequestBody() 0 7 1
A __construct() 0 3 1
A getDataFromRequestQuery() 0 6 1
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