Completed
Push — trunk ( c7e339...34029c )
by SuperNova.WS
04:10
created

Pimp::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 18.03.2018 16:27
4
 */
5
6
namespace Common\Hooker;
7
8
use Common\GlobalContainer;
9
10
/**
11
 * Class Pimp
12
 *
13
 * Pimp is a hooker manager
14
 *
15
 * @package Common\Hooker
16
 */
17
class Pimp {
18
  const ORDER_REPLACE = -PHP_INT_MAX + 1; // Replaces current callback (?)
19
  const ORDER_FIRST = self::ORDER_REPLACE + 1;
20
  const ORDER_AS_IS = 0;
21
  const ORDER_LAST = PHP_INT_MAX;
22
23
  /**
24
   * @var GlobalContainer $gc
25
   */
26
  protected $gc;
27
28
  /**
29
   * @var Hooker[] $hookers
30
   */
31
  protected $hookers = [];
32
33
  /**
34
   * Pimp constructor.
35
   *
36
   * @param GlobalContainer $gc
37
   */
38 1
  public function __construct($gc) {
39 1
    $this->gc = $gc;
40 1
  }
41
42
  /**
43
   * @param string $hookName
44
   * @param        $callable
45
   * @param int    $order
46
   */
47 1
  public function register($hookName, $callable, $order = Pimp::ORDER_AS_IS) {
48 1
    if (empty($this->hookers[$hookName])) {
49 1
      $this->hookers[$hookName] = new Hooker($this);
50 1
    }
51
52 1
    $this->hookers[$hookName]->addClient($callable, $order);
53 1
  }
54
55
  /**
56
   * @param $name
57
   * @param $arguments
58
   *
59
   * @return mixed|null
60
   */
61 1
  public function __call($name, $arguments) {
62
    return
63 1
      !empty($this->hookers[$name])
64 1
        ? $this->hookers[$name]->serve($arguments)
65 1
        : null;
66
  }
67
68
}
69