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

CollectingEventDispatcher::dispatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
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