| Total Complexity | 11 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class EmitterImpl implements Emitter |
||
| 18 | { |
||
| 19 | /** @var bool */ |
||
| 20 | private $enabled = true; |
||
| 21 | |||
| 22 | /** @var \SplObjectStorage[] */ |
||
| 23 | private $bindings = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param bool $enabled |
||
| 27 | */ |
||
| 28 | 1 | public function enable($enabled = true) |
|
| 31 | 1 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | 5 | public function bind($eventName, $handler) |
|
| 37 | { |
||
| 38 | 5 | if (! self::isListener($handler)) { |
|
| 39 | 1 | throw new \LogicException('Invalid listener'); |
|
| 40 | } |
||
| 41 | |||
| 42 | 4 | if (false === array_key_exists($eventName, $this->bindings)) { |
|
| 43 | 4 | $this->bindings[$eventName] = new \SplObjectStorage(); |
|
| 44 | } |
||
| 45 | |||
| 46 | 4 | $listeners = $this->bindings[$eventName]; |
|
| 47 | |||
| 48 | 4 | if (! $listeners->offsetExists($handler)) { |
|
| 49 | 4 | $listeners->offsetSet($handler); |
|
| 50 | } |
||
| 51 | |||
| 52 | 4 | return $this; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | 4 | public function emit(Event $event) |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param Listener|UnaryFunction|callable $listener |
||
| 76 | * |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | 5 | public static function isListener($listener) |
|
| 84 | } |
||
| 85 | } |
||
| 86 |