ClosureEventHandler::invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
namespace Kir\FakePDO\EventHandlers;
3
4
class ClosureEventHandler implements EventHandler {
5
	/** @var callable */
6
	private $callback;
7
	/** @var callable|null */
8
	private $isResponsible;
9
10
	/**
11
	 * ClosureEventHandler constructor.
12
	 * @param callable $callback
13
	 * @param callable $isResponsible
14
	 */
15
	public function __construct(callable $callback, callable $isResponsible = null) {
16
		$this->callback = $callback;
17
		$this->isResponsible = $isResponsible;
18
	}
19
20
21
	/**
22
	 * @param string $eventName
23
	 * @param array $params
24
	 * @param object $callee
25
	 * @return mixed
26
	 */
27
	public function invoke($eventName, array $params, $callee) {
28
		return call_user_func($this->callback, $eventName, $params, $callee);
29
	}
30
31
	/**
32
	 * @param string $eventName
33
	 * @param array $params
34
	 * @param object $callee
35
	 * @return bool
36
	 */
37
	public function isResponsible($eventName, array $params, $callee) {
38
		if($this->isResponsible) {
39
			return call_user_func($this->isResponsible, $eventName, $params);
40
		}
41
		return true;
42
	}
43
}
44