ErrorDocNormalizer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Infra\Normalizer;
3
4
use Yoanm\JsonRpcServerDoc\Domain\Model\ErrorDoc;
5
6
/**
7
 * Class ErrorDocNormalizer
8
 */
9
class ErrorDocNormalizer
10
{
11
    /** @var TypeDocNormalizer */
12
    private $typeDocNormalizer;
13
14
    /**
15
     * @param TypeDocNormalizer $typeDocNormalizer
16
     */
17 22
    public function __construct(TypeDocNormalizer $typeDocNormalizer)
18
    {
19 22
        $this->typeDocNormalizer = $typeDocNormalizer;
20
    }
21
22
    /**
23
     * @param ErrorDoc $errorDoc
24
     *
25
     * @return array
26
     *
27
     * @throws \ReflectionException
28
     */
29 13
    public function normalize(ErrorDoc $errorDoc) : array
30
    {
31 13
        $properties = ['code' => $errorDoc->getCode()];
32 13
        if (null !== $errorDoc->getDataDoc()) {
33 1
            $properties['data'] = $this->typeDocNormalizer->normalize($errorDoc->getDataDoc());
34
        }
35 13
        if (null !== $errorDoc->getMessage()) {
36 10
            $properties['message'] = $errorDoc->getMessage();
37
        }
38
39 13
        return [
40 13
            'id' => $errorDoc->getIdentifier(),
41 13
            'title' => $errorDoc->getTitle(),
42 13
            'type' => 'object',
43 13
            'properties' => $properties,
44 13
        ];
45
    }
46
}
47