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

Pimp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A __call() 0 5 2
A register() 0 6 2
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