DispatcherAwareTrait::dispatcher()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ\Support;
6
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
9
/**
10
 * Trait DispatcherAwareTrait
11
 */
12
trait DispatcherAwareTrait
13
{
14
15
    /**
16
     * @var EventDispatcher
17
     */
18
    private $dispatcher;
19
20
    /**
21
     * @param bool $fresh To force recreate the dispatcher.
22
     *
23
     * @return EventDispatcher
24
     */
25
    protected function dispatcher(bool $fresh = false): EventDispatcher
26
    {
27
        if ($fresh || ! isset($this->dispatcher)) {
28
            $this->dispatcher = new EventDispatcher();
29
        }
30
31
        return $this->dispatcher;
32
    }
33
34
}
35