Passed
Pull Request — develop (#5)
by ANTHONIUS
05:33
created

EventDispatcher::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
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 BaseEventDispatcher;
7
8
/**
9
 * Maintain backward compatibility with symfony version
10
 *
11
 * @package Doyo\Behat\Coverage\Bridge\Symfony
12
 */
13
class EventDispatcher extends BaseEventDispatcher
14
{
15
    private $version = '4.2';
16
17 1
    public function __construct()
18
    {
19 1
        parent::__construct();
20
21 1
        $r = new \ReflectionClass('\Symfony\Component\EventDispatcher\EventDispatcher');
22 1
        $params = $r->getMethod('dispatch')->getParameters();
23 1
        if('event' === $params[0]->getName()){
24 1
            $this->version = '4.3';
25
        }
26
    }
27
28
    /**
29
     * @param Event     $event
30
     * @param string    $eventName
31
     *
32
     * @return Event
33
     */
34 1
    public function dispatch($event, $eventName = null)
35
    {
36 1
        if('4.2' === $this->version){
37
            return parent::dispatch($eventName, $event);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::dispatch($eventName, $event) also could return the type string which is incompatible with the documented return type Doyo\Behat\Coverage\Bridge\Symfony\Event.
Loading history...
38
        }
39 1
        return parent::dispatch($event, $eventName);
40
    }
41
}
42