Completed
Push — master ( 47d481...b68680 )
by Julián
12:05
created

EventBus::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * event-symfony-event-dispatcher (https://github.com/phpgears/event-symfony-event-dispatcher).
5
 * Event bus with Symfony Event Dispatcher.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event-symfony-event-dispatcher
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Event\Symfony\Dispatcher;
15
16
use Gears\Event\Event;
17
use Gears\Event\EventBus as EventBusInterface;
18
19
final class EventBus implements EventBusInterface
20
{
21
    /**
22
     * Wrapped event dispatcher.
23
     *
24
     * @var ContainerAwareDispatcher
25
     */
26
    private $wrappedDispatcher;
27
28
    /**
29
     * EventBus constructor.
30
     *
31
     * @param ContainerAwareDispatcher $wrappedDispatcher
0 ignored issues
show
Documentation introduced by
Should the type for parameter $wrappedDispatcher not be EventDispatcher?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
32
     */
33
    public function __construct(EventDispatcher $wrappedDispatcher)
34
    {
35
        $this->wrappedDispatcher = $wrappedDispatcher;
0 ignored issues
show
Documentation Bug introduced by
$wrappedDispatcher is of type object<Gears\Event\Symfo...atcher\EventDispatcher>, but the property $wrappedDispatcher was declared to be of type object<Gears\Event\Symfo...ntainerAwareDispatcher>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function dispatch(Event $event): void
42
    {
43
        $this->wrappedDispatcher->dispatch(\get_class($event), new EventEnvelope($event));
44
    }
45
}
46