Failed Conditions
Pull Request — feature/init (#3)
by Yo
01:46
created

MethodDocNormalizer::normalize()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 16
nc 16
nop 1
dl 0
loc 30
ccs 0
cts 25
cp 0
crap 30
rs 8.439
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Normalizer;
3
4
use Yoanm\JsonRpcServerDoc\Model\MethodDoc;
5
6
/**
7
 * Class MethodDocNormalizer
8
 */
9
class MethodDocNormalizer
10
{
11
    /** @var TypeDocNormalizer */
12
    private $TypeDocNormalizer;
13
14
    /**
15
     * @param TypeDocNormalizer $TypeDocNormalizer
16
     */
17
    public function __construct(TypeDocNormalizer $TypeDocNormalizer)
18
    {
19
        $this->TypeDocNormalizer = $TypeDocNormalizer;
20
    }
21
22
    /**
23
     * @param MethodDoc $doc
24
     *
25
     * @return array
26
     */
27
    public function normalize(MethodDoc $doc)
28
    {
29
        $docDescription = $docTags = $paramsSchema = $responseSchema = [];
30
31
        if (null !== $doc->getDescription()) {
32
            $docDescription['description'] = $doc->getDescription();
33
        }
34
35
        if (count($doc->getTags())) {
36
            $docTags['tags'] = $doc->getTags();
37
        }
38
        if (null !== $doc->getParamsDoc()) {
39
            $paramsSchema = [
40
                'params' => $this->TypeDocNormalizer->normalize($doc->getParamsDoc())
41
            ];
42
        }
43
44
        // Create custom result schema if provided
45
        if (null !== $doc->getResultDoc()) {
46
            $responseSchema['result'] = $this->TypeDocNormalizer->normalize($doc->getResultDoc());
47
        }
48
49
        return $docDescription
50
            + $docTags
51
            + [
52
                'identifier' => $doc->getIdentifier(),
53
                'name' =>$doc->getMethodName(),
54
            ]
55
            + $paramsSchema
56
            + $responseSchema
57
        ;
58
    }
59
}
60