Passed
Push — master ( 20a97f...aaa4d8 )
by Yo
45s queued 10s
created

MethodDocCreatedListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A enhanceMethodDoc() 0 11 2
1
<?php
2
namespace Yoanm\SymfonyJsonRpcParamsSfConstraintsDoc\Listener;
3
4
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\Infra\Transformer\ConstraintToParamsDocTransformer;
5
use Yoanm\JsonRpcParamsSymfonyValidator\Domain\MethodWithValidatedParamsInterface;
6
use Yoanm\SymfonyJsonRpcHttpServerDoc\Event\MethodDocCreatedEvent;
7
8
/**
9
 * Class MethodDocCreatedListener
10
 */
11
class MethodDocCreatedListener
12
{
13
    /** ConstraintToParamsDocTransformer */
14
    private $paramDocConverter;
15
16
    /**
17
     * @param ConstraintToParamsDocTransformer $paramDocConverter
18
     */
19 2
    public function __construct(ConstraintToParamsDocTransformer $paramDocConverter)
20
    {
21 2
        $this->paramDocConverter = $paramDocConverter;
22 2
    }
23
24
    /**
25
     * @param MethodDocCreatedEvent $event
26
     *
27
     * @throws \ReflectionException
28
     */
29 2
    public function enhanceMethodDoc(MethodDocCreatedEvent $event)
30
    {
31 2
        $jsonRpcMethod = $event->getMethod();
32 2
        if ($jsonRpcMethod instanceof MethodWithValidatedParamsInterface) {
33 1
            $paramsDoc = $this->paramDocConverter->transform($jsonRpcMethod->getParamsConstraint());
34
35
            // If method have arguments, they are required and not nullable
36 1
            $paramsDoc->setNullable(false)
37 1
                ->setRequired(true);
38
39 1
            $event->getDoc()->setParamsDoc($paramsDoc);
40
        }
41 2
    }
42
}
43