DispatcherAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A dispatcher() 0 7 3
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