Completed
Push — master ( b9492e...31cd44 )
by Alexander
11:15
created

Dispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yiisoft\EventDispatcher;
3
4
use Psr\EventDispatcher\EventDispatcherInterface;
5
use Psr\EventDispatcher\ListenerProviderInterface;
6
use Psr\EventDispatcher\StoppableEventInterface;
7
8
/**
9
 * Dispatcher executes listeners attached to event passed
10
 * @see https://www.php-fig.org/psr/psr-14/
11
 */
12
final class Dispatcher implements EventDispatcherInterface
13
{
14
    private $listenerProvider;
15
16
    public function __construct(ListenerProviderInterface $listenerProvider)
17
    {
18
        $this->listenerProvider = $listenerProvider;
19
    }
20
21
    public function dispatch(object $event)
22
    {
23
        foreach ($this->listenerProvider->getListenersForEvent($event) as $listener) {
24
            if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
0 ignored issues
show
Bug introduced by
The class Psr\EventDispatcher\StoppableEventInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
25
                return $event;
26
            }
27
            $listener($event);
28
        }
29
30
        return $event;
31
    }
32
}
33