| Conditions | 11 |
| Paths | 4 |
| Total Lines | 47 |
| Code Lines | 26 |
| 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 |
||
| 37 | public function __invoke(array $record) |
||
| 38 | { |
||
| 39 | // return if the level is not high enough |
||
| 40 | if ($record['level'] < $this->level) { |
||
| 41 | return $record; |
||
| 42 | } |
||
| 43 | |||
| 44 | $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
||
| 45 | |||
| 46 | // skip first since it's always the current method |
||
| 47 | array_shift($trace); |
||
| 48 | // the call_user_func call is also skipped |
||
| 49 | array_shift($trace); |
||
| 50 | |||
| 51 | $i = 0; |
||
| 52 | |||
| 53 | while ($this->isTraceClassOrSkippedFunction($trace, $i)) { |
||
| 54 | if (isset($trace[$i]['class'])) { |
||
| 55 | foreach ($this->skipClassesPartials as $part) { |
||
| 56 | if (strpos($trace[$i]['class'], $part) !== false) { |
||
| 57 | $i++; |
||
| 58 | continue 2; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } elseif (in_array($trace[$i]['function'], $this->skipFunctions)) { |
||
| 62 | $i++; |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | |||
| 66 | break; |
||
| 67 | } |
||
| 68 | |||
| 69 | $i += $this->skipStackFramesCount; |
||
| 70 | |||
| 71 | // we should have the call source now |
||
| 72 | $record['extra'] = array_merge( |
||
| 73 | $record['extra'], |
||
| 74 | array( |
||
| 75 | 'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null, |
||
| 76 | 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, |
||
| 77 | 'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, |
||
| 78 | 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, |
||
| 79 | ) |
||
| 80 | ); |
||
| 81 | |||
| 82 | return $record; |
||
| 83 | } |
||
| 84 | |||
| 94 |