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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribe() 0 4 1
A publish() 0 12 4
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
}