ErrorDocNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10
wmc 4

2 Methods

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