DocProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDoc() 0 9 1
A __construct() 0 8 1
A supports() 0 3 1
1
<?php
2
namespace Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\Provider;
3
4
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
5
use Yoanm\JsonRpcHttpServerSwaggerDoc\Infra\Normalizer\DocNormalizer;
6
use Yoanm\SymfonyJsonRpcHttpServerDoc\Creator\HttpServerDocCreator;
7
use Yoanm\SymfonyJsonRpcHttpServerDoc\Provider\DocProviderInterface;
8
use Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\Event\SwaggerDocCreatedEvent;
9
10
/**
11
 * Class DocProvider
12
 */
13
class DocProvider implements DocProviderInterface
14
{
15
    /** @var EventDispatcherInterface */
16
    private $dispatcher;
17
    /** @var HttpServerDocCreator */
18
    private $serverDocCreator;
19
    /** @var DocNormalizer */
20
    private $docNormalizer;
21
22
    /**
23
     * @param EventDispatcherInterface $dispatcher
24
     * @param HttpServerDocCreator     $serverDocCreator
25
     * @param DocNormalizer            $docNormalizer
26
     */
27 5
    public function __construct(
28
        EventDispatcherInterface $dispatcher,
29
        HttpServerDocCreator $serverDocCreator,
30
        DocNormalizer $docNormalizer
31
    ) {
32 5
        $this->dispatcher = $dispatcher;
33 5
        $this->serverDocCreator = $serverDocCreator;
34 5
        $this->docNormalizer = $docNormalizer;
35
    }
36
37
    /**
38
     * @param string|null $host
39
     *
40
     * @return array
41
     *
42
     * @throws \ReflectionException
43
     */
44 4
    public function getDoc($host = null) : array
45
    {
46 4
        $rawDoc = $this->serverDocCreator->create($host);
47 4
        $swaggerDoc = $this->docNormalizer->normalize($rawDoc);
48
49 4
        $event = new SwaggerDocCreatedEvent($swaggerDoc, $rawDoc);
50 4
        $this->dispatcher->dispatch($event, $event::EVENT_NAME);
51
52 4
        return $event->getSwaggerDoc();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 3
    public function supports($filename, $host = null) : bool
59
    {
60 3
        return 'swagger.json' === $filename;
61
    }
62
}
63