| Conditions | 18 |
| Paths | 246 |
| Total Lines | 51 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 54 | public function export(array $messages): void |
||
| 55 | { |
||
| 56 | foreach ($messages as $message) { |
||
| 57 | foreach ($message as $msg) { |
||
| 58 | if (is_string($msg)) { |
||
| 59 | switch (ini_get('seaslog.appender')) { |
||
| 60 | case '2': |
||
| 61 | case '3': |
||
| 62 | $msg = trim(substr($msg, $this->str_n_pos($msg, ' ', 6))); |
||
| 63 | break; |
||
| 64 | } |
||
| 65 | $msg = explode($this->split, trim($msg)); |
||
| 66 | $ranColor = $this->default; |
||
| 67 | } else { |
||
| 68 | $ranColor = ArrayHelper::remove($msg, '%c'); |
||
| 69 | } |
||
| 70 | if (!empty($this->levelList) && !in_array(strtolower($msg[$this->levelIndex]), $this->levelList)) { |
||
| 71 | continue; |
||
| 72 | } |
||
| 73 | if (empty($ranColor)) { |
||
| 74 | $ranColor = $this->default; |
||
| 75 | } elseif (is_array($ranColor) && isset($ranColor['console'])) { |
||
| 76 | $ranColor = $ranColor['console']; |
||
| 77 | } else { |
||
| 78 | $ranColor = $this->default; |
||
| 79 | } |
||
| 80 | $context = []; |
||
| 81 | foreach ($msg as $index => $msgValue) { |
||
| 82 | $level = $this->getLevelColor(trim($msg[$this->levelIndex])); |
||
| 83 | if (isset($this->colorTemplate[$index])) { |
||
| 84 | $color = $this->colorTemplate[$index]; |
||
| 85 | $msgValue = is_string($msgValue) ? trim($msgValue) : (string)$msgValue; |
||
| 86 | switch ($color) { |
||
| 87 | case self::COLOR_LEVEL: |
||
| 88 | $context[] = $this->color->apply($level, $msgValue); |
||
| 89 | break; |
||
| 90 | case self::COLOR_DEFAULT: |
||
| 91 | $context[] = $this->color->apply($this->default, $msgValue); |
||
| 92 | break; |
||
| 93 | case self::COLOR_RANDOM: |
||
| 94 | $context[] = $this->color->apply($ranColor, $msgValue); |
||
| 95 | break; |
||
| 96 | default: |
||
| 97 | $context[] = $this->color->apply($color, $msgValue); |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | $context[] = $this->color->apply($level, $msgValue); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | if (isset($context)) { |
||
| 104 | echo implode(' ' . $this->color->apply($this->splitColor, '|') . ' ', $context) . PHP_EOL; |
||
| 105 | } |
||
| 130 | } |