| Conditions | 6 |
| Paths | 7 |
| Total Lines | 47 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 6.1666 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | 13 | public static function create(Signal $signals, $signal, $fqn, $injection) |
|
| 28 | { |
||
| 29 | // Clone signal, as it might be modified by slot |
||
| 30 | 13 | $cloned = clone $signal; |
|
| 31 | |||
| 32 | // Constructor injection |
||
| 33 | 13 | if (true === $injection) |
|
| 34 | { |
||
| 35 | 1 | $slot = new $fqn($cloned); |
|
| 36 | |||
| 37 | // Slot aware call |
||
| 38 | 1 | if ($cloned instanceof SlotAwareInterface) |
|
| 39 | { |
||
| 40 | $cloned->setSlot($slot); |
||
| 41 | } |
||
| 42 | 1 | return $cloned; |
|
| 43 | } |
||
| 44 | |||
| 45 | // Check if class exists and log if doesn't |
||
| 46 | 12 | 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 | 12 | $slot = new $fqn; |
|
| 54 | |||
| 55 | // Slot aware call |
||
| 56 | 12 | if ($cloned instanceof SlotAwareInterface) |
|
| 57 | { |
||
| 58 | 1 | $cloned->setSlot($slot); |
|
| 59 | } |
||
| 60 | |||
| 61 | 12 | if (strstr($injection, '()')) |
|
| 62 | { |
||
| 63 | // Method injection |
||
| 64 | 9 | $methodName = str_replace('()', '', $injection); |
|
| 65 | 9 | $slot->$methodName($cloned); |
|
| 66 | } |
||
| 67 | else |
||
| 68 | { |
||
| 69 | // field injection |
||
| 70 | 3 | $slot->$injection = $cloned; |
|
| 71 | } |
||
| 72 | 12 | return $cloned; |
|
| 73 | } |
||
| 74 | |||
| 76 |