GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EventDispatchingDecorator::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Chief\Decorators;
4
5
use Chief\Busses\SynchronousCommandBus;
6
use Chief\Command;
7
use Chief\CommandBus;
8
use Chief\Decorator;
9
use Exception;
10
11
class EventDispatchingDecorator implements Decorator
12
{
13
    /**
14
     * @var EventDispatcher
15
     */
16
    protected $dispatcher;
17
18
    /**
19
     * @var CommandBus
20
     */
21
    protected $innerCommandBus;
22
23
    /**
24
     * @param EventDispatcher $dispatcher
25
     * @param CommandBus $innerCommandBus
26
     */
27
    public function __construct(EventDispatcher $dispatcher, CommandBus $innerCommandBus = null)
28
    {
29
        $this->dispatcher = $dispatcher;
30
        $this->setInnerBus($innerCommandBus ?: new SynchronousCommandBus());
31
    }
32
33
    public function setInnerBus(CommandBus $bus)
34
    {
35
        $this->innerCommandBus = $bus;
36
    }
37
38
    /**
39
     * Execute a command and dispatch and event
40
     *
41
     * @param Command $command
42
     * @return mixed
43
     * @throws \Exception
44
     */
45
    public function execute(Command $command)
46
    {
47
        if (!$this->innerCommandBus) {
48
            throw new Exception('No inner bus defined for this decorator. Set an inner bus with setInnerBus()');
49
        }
50
51
        $response = $this->innerCommandBus->execute($command);
52
53
        $eventName = $this->getEventName($command);
54
55
        $this->dispatcher->dispatch($eventName, [$command]);
56
57
        return $response;
58
    }
59
60
    /**
61
     * Get the event name for a given Command
62
     *
63
     * @param Command $command
64
     * @return string
65
     */
66
    protected function getEventName(Command $command)
67
    {
68
        return str_replace('\\', '.', get_class($command));
69
    }
70
}
71