MethodDocCreatedListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A enhanceMethodDoc() 0 11 2
A __construct() 0 3 1
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 3
    public function __construct(ConstraintToParamsDocTransformer $paramDocConverter)
20
    {
21 3
        $this->paramDocConverter = $paramDocConverter;
22
    }
23
24
    /**
25
     * @param MethodDocCreatedEvent $event
26
     *
27
     * @throws \ReflectionException
28
     */
29 3
    public function enhanceMethodDoc(MethodDocCreatedEvent $event)
30
    {
31 3
        $jsonRpcMethod = $event->getMethod();
32 3
        if ($jsonRpcMethod instanceof MethodWithValidatedParamsInterface) {
33 2
            $paramsDoc = $this->paramDocConverter->transform($jsonRpcMethod->getParamsConstraint());
34
35
            // If method have arguments, they are required and not nullable
36 2
            $paramsDoc->setNullable(false)
37 2
                ->setRequired(true);
38
39 2
            $event->getDoc()->setParamsDoc($paramsDoc);
40
        }
41
    }
42
}
43