EventHandlerTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventHandler() 0 3 1
A setEventHandler() 0 4 1
A invokeEventHandler() 0 10 4
1
<?php
2
namespace Kir\FakePDO\EventHandlers;
3
4
trait EventHandlerTrait {
5
	/** @var EventHandler|null */
6
	private $eventHandler;
7
8
	/**
9
	 * @return EventHandler|null
10
	 */
11
	protected function getEventHandler() {
12
		return $this->eventHandler;
13
	}
14
15
	/**
16
	 * @param EventHandler|null $eventHandler
17
	 * @return $this
18
	 */
19
	protected function setEventHandler($eventHandler) {
20
		$this->eventHandler = $eventHandler;
21
		return $this;
22
	}
23
24
	/**
25
	 * @param string $eventName
26
	 * @param array $params
27
	 * @param callable $defaultCallback
28
	 * @return mixed
29
	 */
30
	protected function invokeEventHandler($eventName, array $params = array(), $defaultCallback = null) {
31
		$eventHandler = $this->eventHandler;
32
		if($eventHandler !== null && $eventHandler->isResponsible($eventName, $params, $this)) {
33
			return $eventHandler->invoke($eventName, $params, $this);
34
		}
35
		if($defaultCallback !== null) {
36
			return call_user_func_array($defaultCallback, $params);
37
		}
38
		return null;
39
	}
40
}
41