Conditions | 6 |
Paths | 7 |
Total Lines | 47 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
1 | <?php |
||
27 | public static function create(Signal $signals, $signal, $fqn, $injection) |
||
28 | { |
||
29 | // Clone signal, as it might be modified by slot |
||
30 | $cloned = clone $signal; |
||
31 | |||
32 | // Constructor injection |
||
33 | if (true === $injection) |
||
34 | { |
||
35 | $slot = new $fqn($cloned); |
||
36 | |||
37 | // Slot aware call |
||
38 | if ($cloned instanceof SlotAwareInterface) |
||
39 | { |
||
40 | $cloned->setSlot($slot); |
||
41 | } |
||
42 | return $cloned; |
||
43 | } |
||
44 | |||
45 | // Check if class exists and log if doesn't |
||
46 | if (!ClassChecker::exists($fqn)) |
||
47 | { |
||
48 | $signals->getLogger()->debug(sprintf("Class `%s` not found while emiting signal `%s`", $fqn, get_class($signal))); |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | // Other type injection |
||
53 | $slot = new $fqn; |
||
54 | |||
55 | // Slot aware call |
||
56 | if ($cloned instanceof SlotAwareInterface) |
||
57 | { |
||
58 | $cloned->setSlot($slot); |
||
59 | } |
||
60 | |||
61 | if (strstr($injection, '()')) |
||
62 | { |
||
63 | // Method injection |
||
64 | $methodName = str_replace('()', '', $injection); |
||
65 | $slot->$methodName($cloned); |
||
66 | } |
||
67 | else |
||
68 | { |
||
69 | // field injection |
||
70 | $slot->$injection = $cloned; |
||
71 | } |
||
72 | return $cloned; |
||
73 | } |
||
74 | |||
76 |