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.

SimpleEventBus::publish()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
c 0
b 0
f 0
cc 4
nc 6
nop 1
crap 4
rs 9.8666
1
<?php
2
namespace SmoothPhp\EventBus;
3
4
use SmoothPhp\Contracts\Domain\DomainEventStream;
5
use SmoothPhp\Contracts\Domain\DomainMessage;
6
use SmoothPhp\Contracts\EventBus\EventBus;
7
use SmoothPhp\Contracts\EventBus\EventListener;
8
9
/**
10
 * Class SimpleEventBus
11
 * @package SmoothPhp\EventBus
12
 * @author Simon Bennett <[email protected]>
13
 */
14
final class SimpleEventBus implements EventBus
15
{
16
    /**
17
     * @var EventListener[]
18
     */
19
    private $eventListeners = [];
20
21
    /**
22
     * @var DomainMessage[]
23
     */
24
    private $queue = [];
25
26
    /**
27
     * @param $eventListener
28
     * @return mixed
29
     */
30 3
    public function subscribe(EventListener $eventListener)
31
    {
32 3
        $this->eventListeners[] = $eventListener;
33 3
    }
34
35
    /**
36
     * @param DomainEventStream $domainEventStream
37
     * @return void
38
     */
39 6
    public function publish(DomainEventStream $domainEventStream)
40
    {
41 6
        foreach ($domainEventStream as $domainMessage) {
42 3
            $this->queue[] = $domainMessage;
43
        }
44
45 6
        while ($domainMessage = array_shift($this->queue)) {
46 3
            foreach ($this->eventListeners as $eventListener) {
47 3
                $eventListener->handle($domainMessage);
48
            }
49
        }
50
    }
51
}