| Conditions | 11 | 
| Paths | 60 | 
| Total Lines | 46 | 
| Code Lines | 17 | 
| 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 namespace Anomaly\Streams\Platform\Traits; | ||
| 72 | public function fire($trigger, array $parameters = []) | ||
| 73 |     { | ||
| 74 | |||
| 75 | /* | ||
| 76 | * First, fire global listeners. | ||
| 77 | */ | ||
| 78 | $classes = array_merge(class_parents($this), [get_class($this) => get_class($this)]); | ||
| 79 | |||
| 80 | 	    foreach (array_keys($classes) as $caller) { | ||
| 81 | 		    foreach (array_get(self::$listeners, $caller . '::' . $trigger, []) as $callback) { | ||
| 82 | 			    if (is_string($callback) || $callback instanceof \Closure) { | ||
| 83 | app()->call($callback, $parameters); | ||
| 84 | } | ||
| 85 | |||
| 86 | 			    if (method_exists($callback, 'handle')) { | ||
| 87 | app()->call([$callback, 'handle'], $parameters); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | /* | ||
| 93 | * Next, check if the method | ||
| 94 | * exists and run it if it does. | ||
| 95 | */ | ||
| 96 |         $method = camel_case('on_' . $trigger); | ||
| 97 | |||
| 98 |         if (method_exists($this, $method)) { | ||
| 99 | app()->call([$this, $method], $parameters); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * Finally, run through all of | ||
| 104 | * the registered callbacks. | ||
| 105 | */ | ||
| 106 |         foreach (array_get($this->callbacks, $trigger, []) as $callback) { | ||
| 107 |             if (is_string($callback) || $callback instanceof \Closure) { | ||
| 108 | app()->call($callback, $parameters); | ||
| 109 | } | ||
| 110 | |||
| 111 |             if (method_exists($callback, 'handle')) { | ||
| 112 | app()->call([$callback, 'handle'], $parameters); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | return $this; | ||
| 117 | } | ||
| 118 | |||
| 141 |