DocProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A getDoc() 0 10 1
A __construct() 0 8 1
1
<?php
2
namespace Yoanm\SymfonyJsonRpcHttpServerOpenAPIDoc\Provider;
3
4
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5
use Yoanm\JsonRpcHttpServerOpenAPIDoc\Infra\Normalizer\DocNormalizer;
6
use Yoanm\SymfonyJsonRpcHttpServerDoc\Creator\HttpServerDocCreator;
7
use Yoanm\SymfonyJsonRpcHttpServerDoc\Provider\DocProviderInterface;
8
use Yoanm\SymfonyJsonRpcHttpServerOpenAPIDoc\Event\OpenAPIDocCreatedEvent;
9
10
/**
11
 * Class DocProvider
12
 */
13
class DocProvider implements DocProviderInterface
14
{
15
    /** @var EventDispatcherInterface */
16
    private $dispatcher;
17
    /** @var HttpServerDocCreator */
18
    private $httpServerDocCreator;
19
    /** @var DocNormalizer */
20
    private $docNormalizer;
21
22
    /**
23
     * @param EventDispatcherInterface $dispatcher
24
     * @param HttpServerDocCreator         $HttpServerDocCreator
25
     * @param DocNormalizer     $docNormalizer
26
     */
27 3
    public function __construct(
28
        EventDispatcherInterface $dispatcher,
29
        HttpServerDocCreator $HttpServerDocCreator,
30
        DocNormalizer $docNormalizer
31
    ) {
32 3
        $this->dispatcher = $dispatcher;
33 3
        $this->httpServerDocCreator = $HttpServerDocCreator;
34 3
        $this->docNormalizer = $docNormalizer;
35 3
    }
36
37
    /**
38
     * @param string|null $host
39
     *
40
     * @return array
41
     *
42
     * @throws \ReflectionException
43
     */
44 2
    public function getDoc($host = null) : array
45
    {
46 2
        $rawDoc = $this->httpServerDocCreator->create($host);
47
48 2
        $openApiDoc = $this->docNormalizer->normalize($rawDoc);
49
50 2
        $event = new OpenAPIDocCreatedEvent($openApiDoc, $rawDoc);
51 2
        $this->dispatcher->dispatch($event::EVENT_NAME, $event);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with $event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->dispatcher->/** @scrutinizer ignore-call */ 
52
                           dispatch($event::EVENT_NAME, $event);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
53 2
        return $event->getOpenAPIDoc();
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 1
    public function supports($filename, $host = null) : bool
60
    {
61 1
        return 'openapi.json' === $filename;
62
    }
63
}
64