Passed
Pull Request — develop (#5)
by ANTHONIUS
03:52
created

EventDispatcher::dispatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
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 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Doyo\Behat\Coverage\Bridge\Symfony;
5
6
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyEventDispatcher;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
/**
10
 * Maintain backward compatibility with symfony version
11
 *
12
 * @package Doyo\Behat\Coverage\Bridge\Symfony
13
 */
14
class EventDispatcher
15
{
16
    private $version = '4.2';
17
18
    /**
19
     * @var SymfonyEventDispatcher
20
     */
21
    private $dispatcher;
22
23 1
    public function __construct()
24
    {
25 1
        $dispatcher = new SymfonyEventDispatcher();
26 1
        $r = new \ReflectionObject($dispatcher);
27 1
        $params = $r->getMethod('dispatch')->getParameters();
28
29 1
        if('event' === $params[0]->getName()){
30 1
            $this->version = '4.3';
31
        }
32
33 1
        $this->dispatcher = $dispatcher;
34
    }
35
36 1
    public function addSubscriber(EventSubscriberInterface $subscriber)
37
    {
38 1
        $this->dispatcher->addSubscriber($subscriber);
39
    }
40
41
    /**
42
     * @param Event     $event
43
     * @param string    $eventName
44
     *
45
     * @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...
46
     */
47 1
    public function dispatch($event, $eventName = null)
48
    {
49 1
        $dispatcher = $this->dispatcher;
50 1
        if('4.2' === $this->version){
51
            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...
52
        }
53 1
        return $dispatcher->dispatch($event, $eventName);
54
    }
55
}
56
    
57