| Conditions | 11 |
| Paths | 270 |
| Total Lines | 45 |
| Code Lines | 23 |
| 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 |
||
| 66 | public function format(array $record) |
||
| 67 | { |
||
| 68 | $vars = parent::format($record); |
||
| 69 | |||
| 70 | $output = $this->format; |
||
| 71 | |||
| 72 | foreach ($vars['extra'] as $var => $val) { |
||
| 73 | if (false !== strpos($output, '%extra.'.$var.'%')) { |
||
| 74 | $output = str_replace('%extra.'.$var.'%', $this->stringify($val), $output); |
||
| 75 | unset($vars['extra'][$var]); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | foreach ($vars['context'] as $var => $val) { |
||
| 81 | if (false !== strpos($output, '%context.'.$var.'%')) { |
||
| 82 | $output = str_replace('%context.'.$var.'%', $this->stringify($val), $output); |
||
| 83 | unset($vars['context'][$var]); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($this->ignoreEmptyContextAndExtra) { |
||
| 88 | if (empty($vars['context'])) { |
||
| 89 | unset($vars['context']); |
||
| 90 | $output = str_replace('%context%', '', $output); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (empty($vars['extra'])) { |
||
| 94 | unset($vars['extra']); |
||
| 95 | $output = str_replace('%extra%', '', $output); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | foreach ($vars as $var => $val) { |
||
| 100 | if (false !== strpos($output, '%'.$var.'%')) { |
||
| 101 | $output = str_replace('%'.$var.'%', $this->stringify($val), $output); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | // remove leftover %extra.xxx% and %context.xxx% if any |
||
| 106 | if (false !== strpos($output, '%')) { |
||
| 107 | $output = preg_replace('/%(?:extra|context)\..+?%/', '', $output); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $output; |
||
| 111 | } |
||
| 180 |