Passed
Push — master ( 4c3482...c264b6 )
by Yo
53s queued 10s
created

ResultDocNormalizer::__construct()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcHttpServerSwaggerDoc\App\Normalizer\Component;
3
4
use Yoanm\JsonRpcHttpServerSwaggerDoc\App\Resolver\DefinitionRefResolver;
5
use Yoanm\JsonRpcServerDoc\Domain\Model\MethodDoc;
6
7
/**
8
 * Class ResultDocNormalizer
9
 */
10
class ResultDocNormalizer
11
{
12
    /** @var DefinitionRefResolver */
13
    private $definitionRefResolver;
14
15
    /**
16
     * @param DefinitionRefResolver $definitionRefResolver
17
     */
18 2
    public function __construct(DefinitionRefResolver $definitionRefResolver)
19
    {
20 2
        $this->definitionRefResolver = $definitionRefResolver;
21 2
    }
22
23
    /**
24
     * @param MethodDoc $method
25
     *
26
     * @return array
27
     */
28 2
    public function normalize(MethodDoc $method) : array
29
    {
30 2
        if (null !== $method->getResultDoc()) {
31
            return [
32 1
                '$ref' => $this->definitionRefResolver->getDefinitionRef(
33 1
                    $this->definitionRefResolver->getMethodDefinitionId(
34 1
                        $method,
35 1
                        DefinitionRefResolver::METHOD_RESULT_DEFINITION_TYPE
36
                    )
37
                )
38
            ];
39
        }
40
41 1
        return ['description' => 'Method result'];
42
    }
43
}
44