| Conditions | 10 |
| Paths | 20 |
| Total Lines | 30 |
| Code Lines | 22 |
| 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 |
||
| 34 | public function export(array $messages): void |
||
| 35 | { |
||
| 36 | $connection = $this->clientPool->getConnection(); |
||
| 37 | foreach ($messages as $module => $message) { |
||
| 38 | foreach ($message as $msg) { |
||
| 39 | if (is_string($msg)) { |
||
| 40 | switch (ini_get('seaslog.appender')) { |
||
| 41 | case '2': |
||
| 42 | case '3': |
||
| 43 | $msg = trim(substr($msg, $this->str_n_pos($msg, ' ', 6))); |
||
| 44 | break; |
||
| 45 | case '1': |
||
| 46 | default: |
||
| 47 | $fileName = basename($module); |
||
| 48 | $module = substr($fileName, 0, strpos($fileName, '_', -1)); |
||
| 49 | } |
||
| 50 | $msg = explode($this->split, trim($msg)); |
||
| 51 | if (($diff = count($msg) - count($this->template)) > 0) { |
||
| 52 | array_splice($msg, -($diff + 1), $diff, [array_slice($msg, -($diff + 1), $diff)]); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | if (!empty($this->levelList) && !in_array(strtolower($msg[$this->levelIndex]), $this->levelList)) { |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | ArrayHelper::remove($msg, '%c'); |
||
| 59 | $msg = $module . '@' . str_replace(PHP_EOL, '', implode($this->split, $msg)) . PHP_EOL; |
||
| 60 | $connection->send($msg); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $this->clientPool->release($connection); |
||
| 64 | } |
||
| 65 | } |