| Conditions | 18 |
| Paths | 36 |
| Total Lines | 61 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 48 | public static function trigger($object, $event, array $parameters = []) |
||
| 49 | { |
||
| 50 | foreach (self::$eventStack as $className => $eventStack) { |
||
| 51 | if (self::className($object) == $className || |
||
| 52 | is_subclass_of(self::className($object), $className) |
||
|
|
|||
| 53 | ) { |
||
| 54 | if (isset($eventStack[$event])) { |
||
| 55 | foreach ($eventStack[$event] as $eventCallback) { |
||
| 56 | $retval = null; |
||
| 57 | $callback = null; |
||
| 58 | if (is_callable($eventCallback)) { |
||
| 59 | $callback = $eventCallback; |
||
| 60 | } elseif (is_string($eventCallback)) { |
||
| 61 | if (is_callable([$object, $eventCallback])) { |
||
| 62 | $callback = [$object, $eventCallback]; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | if (isset($callback)) { |
||
| 66 | $trace = debug_backtrace(); |
||
| 67 | $current = array_shift($trace); |
||
| 68 | $caller = array_shift($trace); |
||
| 69 | |||
| 70 | if (isset($caller['object'])) { |
||
| 71 | // http://www.php.net/manual/en/function.call-user-func.php |
||
| 72 | // Note: Note that the parameters for call_user_func() are not passed by reference. |
||
| 73 | $parameterArray = array_merge([&$caller['object']], $parameters); |
||
| 74 | $retval = call_user_func_array($callback, $parameterArray); |
||
| 75 | if (isset($retval)) { |
||
| 76 | // TODO: Aborts execution of cueue! |
||
| 77 | return $retval; |
||
| 78 | } |
||
| 79 | } elseif (isset($caller['class']) && isset($caller['function']) && $caller['type'] === '::') { |
||
| 80 | // triggered from static context |
||
| 81 | // TODO: update exception 90015 |
||
| 82 | $retval = call_user_func_array($callback, $parameters); |
||
| 83 | if (isset($retval)) { |
||
| 84 | // TODO: Aborts execution of cueue! |
||
| 85 | return $retval; |
||
| 86 | } |
||
| 87 | } elseif ($callback instanceof Closure) { |
||
| 88 | $retval = $callback(); |
||
| 89 | if (isset($retval)) { |
||
| 90 | // TODO: Aborts execution of cueue! |
||
| 91 | return $retval; |
||
| 92 | } |
||
| 93 | } else { |
||
| 94 | throw new Ajde_Exception('Event context needed to |
||
| 95 | fire, none detected', 90015); |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | // TODO: right now never fires in Object_Magic objects |
||
| 99 | // because of the __call magic function. Workaround |
||
| 100 | // could be something like in_array("bar",get_class_methods($f1) |
||
| 101 | // see: http://php.net/manual/en/function.method-exists.php |
||
| 102 | throw new Ajde_Exception('Callback is not valid', 90016); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 120 |