Completed
Push — develop ( c86111...2faf16 )
by ANTHONIUS
21s
created

EventDispatcher::dispatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Behat\Coverage\Bridge\Symfony;
15
16
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyEventDispatcher;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
/**
20
 * Maintain backward compatibility with symfony version.
21
 */
22
class EventDispatcher
23
{
24
    private $version = '4.2';
25
26
    /**
27
     * @var SymfonyEventDispatcher
28
     */
29
    private $dispatcher;
30
31 1
    public function __construct()
32
    {
33 1
        $dispatcher = new SymfonyEventDispatcher();
34 1
        $r          = new \ReflectionObject($dispatcher);
35 1
        $params     = $r->getMethod('dispatch')->getParameters();
36
37 1
        if ('event' === $params[0]->getName()) {
38 1
            $this->version = '4.3';
39
        }
40
41 1
        $this->dispatcher = $dispatcher;
42
    }
43
44 1
    public function addSubscriber(EventSubscriberInterface $subscriber)
45
    {
46 1
        $this->dispatcher->addSubscriber($subscriber);
47
    }
48
49
    /**
50
     * @param Event  $event
51
     * @param string $eventName
52
     *
53
     * @return \Symfony\Component\EventDispatcher\Event|\Symfony\Contract\EventDispatcher\Event
0 ignored issues
show
Bug introduced by
The type Symfony\Contract\EventDispatcher\Event was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
     */
55 5
    public function dispatch($event, $eventName = null)
56
    {
57 5
        $dispatcher = $this->dispatcher;
58 5
        if ('4.2' === $this->version) {
59
            return $dispatcher->dispatch($eventName, $event);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $dispatcher->dispatch($eventName, $event) also could return the type string which is incompatible with the documented return type Symfony\Component\EventD...t\EventDispatcher\Event.
Loading history...
60
        }
61
62 5
        return $dispatcher->dispatch($event, $eventName);
63
    }
64
}
65