EventDispatcherMiddleware::dispatcher()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
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
namespace Cubiche\Core\EventBus\Middlewares\EventDispatcher;
13
14
use Cubiche\Core\EventDispatcher\EventDispatcherInterface;
15
use Cubiche\Core\EventBus\Event\EventInterface;
16
use Cubiche\Core\Bus\Middlewares\MiddlewareInterface;
17
18
/**
19
 * EventDispatcherMiddleware class.
20
 *
21
 * @author Ivannis Suárez Jerez <[email protected]>
22
 */
23
class EventDispatcherMiddleware implements MiddlewareInterface
24
{
25
    /**
26
     * @var EventDispatcherInterface
27
     */
28
    protected $dispatcher;
29
30
    /**
31
     * EventDispatcherMiddleware constructor.
32
     *
33
     * @param EventDispatcherInterface $dispatcher
34
     */
35
    public function __construct(EventDispatcherInterface $dispatcher)
36
    {
37
        $this->dispatcher = $dispatcher;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function handle($event, callable $next)
44
    {
45 View Code Duplication
        if (!$event instanceof EventInterface) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
            throw new \InvalidArgumentException(
47
                sprintf(
48
                    'The object must be an instance of %s. Instance of %s given',
49
                    EventInterface::class,
50
                    get_class($event)
51
                )
52
            );
53
        }
54
55
        $this->dispatcher->dispatch($event);
56
57
        $next($event);
58
    }
59
60
    /**
61
     * @return EventDispatcherInterface
62
     */
63
    public function dispatcher()
64
    {
65
        return $this->dispatcher;
66
    }
67
}
68