| Conditions | 20 |
| Paths | 21 |
| Total Lines | 63 |
| Code Lines | 42 |
| 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 |
||
| 144 | private function processLogRecord($array, $key, $value, $count) |
||
| 145 | { |
||
| 146 | switch ($key) { |
||
| 147 | case 'message': |
||
| 148 | $array['@m'] = $value; |
||
| 149 | if (!(strpos($value, '{') === false)) { |
||
| 150 | $array['@mt'] = $value; |
||
| 151 | } |
||
| 152 | break; |
||
| 153 | |||
| 154 | case 'datetime': |
||
| 155 | if ($value instanceof \DateTime) { |
||
| 156 | $value = $value->format(DateTime::ISO8601); |
||
| 157 | } |
||
| 158 | $array['@t'] = $value; |
||
| 159 | break; |
||
| 160 | |||
| 161 | case 'level': |
||
| 162 | $array['@l'] = $this->logLevelMap[$value]; |
||
| 163 | $array['LogLevelCode'] = $value; |
||
| 164 | break; |
||
| 165 | case 'level_name': |
||
| 166 | break; |
||
| 167 | |||
| 168 | case 'extra': |
||
| 169 | if (is_array($value) && $normalizedArray = $this->normalize($value) && is_array($normalizedArray)) { |
||
| 170 | if ($this->extractExtras) { |
||
| 171 | $array = array_merge($normalizedArray, $array); |
||
| 172 | } else { |
||
| 173 | $array['Extra'] = $normalizedArray; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | break; |
||
| 177 | |||
| 178 | case 'context': |
||
| 179 | if (is_array($value)) { |
||
| 180 | $exception = $this->extractException($value); |
||
| 181 | $normalizedArray = $this->normalize($value); |
||
| 182 | |||
| 183 | if (is_array($normalizedArray)) { |
||
| 184 | if ($this->extractContext) { |
||
| 185 | $array = array_merge($normalizedArray, $array); |
||
| 186 | } else { |
||
| 187 | $array['Context'] = $normalizedArray; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | if ($exception !== null) { |
||
| 192 | if (($exception instanceof \Exception || $exception instanceof \Throwable)) { |
||
| 193 | $exception = $this->normalizeException($exception); |
||
| 194 | } |
||
| 195 | |||
| 196 | $array['@x'] = $exception; |
||
| 197 | } |
||
| 198 | } |
||
| 199 | break; |
||
| 200 | |||
| 201 | default: |
||
| 202 | $array[is_int($key) ? $key : SeqCompactJsonFormatter::ConvertSnakeCaseToPascalCase($key)] = $this->normalize($value); |
||
| 203 | break; |
||
| 204 | } |
||
| 205 | |||
| 206 | return $array; |
||
| 207 | } |
||
| 208 | } |