Passed
Push — trunk ( 60c287...522604 )
by Christian
21:52 queued 08:22
created

CollectingEventDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 9 2
A getEvents() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Test\Stub\EventDispatcher;
4
5
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
6
7
/**
8
 * @final
9
 */
10
class CollectingEventDispatcher implements EventDispatcherInterface
11
{
12
    /**
13
     * @var array<object>
14
     */
15
    private array $events = [];
16
17
    public function dispatch(object $event, ?string $eventName = null): object
18
    {
19
        if ($eventName) {
20
            $this->events[$eventName] = $event;
21
        } else {
22
            $this->events[] = $event;
23
        }
24
25
        return $event;
26
    }
27
28
    /**
29
     * @return array<object>
30
     */
31
    public function getEvents(): array
32
    {
33
        return $this->events;
34
    }
35
}
36