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

MethodDocNormalizer::__construct()   A

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 3
cp 0
crap 2
rs 10
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) : array
28
    {
29
        $docDescription = $docTags = $paramsSchema = $responseSchema = [];
30
31
        if (null !== $doc->getDescription()) {
32
            $docDescription['description'] = $doc->getDescription();
33
        }
34
        if (count($doc->getTags())) {
35
            $docTags['tags'] = $doc->getTags();
36
        }
37
        if (null !== $doc->getParamsDoc()) {
38
            $paramsSchema = [
39
                'params' => $this->TypeDocNormalizer->normalize($doc->getParamsDoc())
40
            ];
41
        }
42
43
        // Create custom result schema if provided
44
        if (null !== $doc->getResultDoc()) {
45
            $responseSchema['result'] = $this->TypeDocNormalizer->normalize($doc->getResultDoc());
46
        }
47
48
        return $docDescription
49
            + $docTags
50
            + [
51
                'identifier' => $doc->getIdentifier(),
52
                'name' =>$doc->getMethodName(),
53
            ]
54
            + $paramsSchema
55
            + $responseSchema
56
        ;
57
    }
58
}
59