| Conditions | 12 |
| Paths | 4 |
| Total Lines | 47 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 108 | private static function printException(Exception $e, $messageIntro = '') { |
||
| 109 | $p = function ($format = "\n") { |
||
| 110 | $fp = fopen('php://stderr', 'w'); |
||
| 111 | fwrite($fp, vsprintf($format, array_slice(func_get_args(), 1))); |
||
| 112 | fclose($fp); |
||
| 113 | }; |
||
| 114 | |||
| 115 | $p("%s%s\n", $messageIntro, $e->getMessage()); |
||
| 116 | |||
| 117 | $formatStation = function ($idx, $station) use ($p) { |
||
| 118 | $defaults = [ |
||
| 119 | 'file' => null, |
||
| 120 | 'line' => null, |
||
| 121 | 'class' => null, |
||
| 122 | 'function' => null, |
||
| 123 | 'type' => null, |
||
| 124 | 'args' => [], |
||
| 125 | ]; |
||
| 126 | $station = array_merge($defaults, $station); |
||
| 127 | $p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']); |
||
| 128 | if($station['class'] !== null || $station['function'] !== null) { |
||
| 129 | $params = []; |
||
| 130 | foreach(is_array($station['args']) ? $station['args'] : [] as $argument) { |
||
| 131 | if(is_array($argument)) { |
||
| 132 | $params[] = sprintf('array%d', count($argument)); |
||
| 133 | } elseif(is_object($argument)) { |
||
| 134 | $params[] = sprintf('%s', get_class($argument)); |
||
| 135 | } else { |
||
| 136 | $params[] = gettype($argument); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | if(strpos($station['function'], '{closure}') !== false && $station['class'] !== null) { |
||
| 140 | $station['function'] = '{closure}'; |
||
| 141 | } |
||
| 142 | $p(" %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")"); |
||
| 143 | } |
||
| 144 | }; |
||
| 145 | |||
| 146 | foreach($e->getTrace() as $idx => $station) { |
||
| 147 | $formatStation($idx, $station); |
||
| 148 | } |
||
| 149 | |||
| 150 | if($e->getPrevious() instanceof Exception) { |
||
| 151 | $p(); |
||
| 152 | self::printException($e->getPrevious(), 'Previous: '); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
It seems like you are assigning to a variable which was imported through a
usestatement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope