Conditions | 15 |
Paths | 47 |
Total Lines | 50 |
Code Lines | 39 |
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 |
||
63 | public function export(array $messages): void |
||
64 | { |
||
65 | foreach ($messages as $module => $message) { |
||
66 | foreach ($message as $msg) { |
||
67 | if (is_string($msg)) { |
||
68 | switch (ini_get('seaslog.appender')) { |
||
69 | case '2': |
||
70 | case '3': |
||
71 | $msg = trim(substr($msg, $this->str_n_pos($msg, ' ', 6))); |
||
72 | break; |
||
73 | case '1': |
||
74 | default: |
||
75 | $fileName = basename($module); |
||
76 | $module = substr($fileName, 0, strrpos($fileName, '_')); |
||
77 | } |
||
78 | $msg = explode($this->split, trim($msg)); |
||
79 | } else { |
||
80 | ArrayHelper::remove($msg, '%c'); |
||
81 | } |
||
82 | if (!empty($this->levelList) && !in_array(strtolower($msg[$this->levelIndex]), $this->levelList)) { |
||
83 | continue; |
||
84 | } |
||
85 | $log = [ |
||
86 | 'appname' => $module, |
||
87 | ]; |
||
88 | $i = 0; |
||
89 | foreach ($msg as $index => $msgValue) { |
||
90 | if ($this->template[$index] === '%A') { |
||
91 | switch ($this->customerType) { |
||
92 | case AbstractConfig::TYPE_JSON: |
||
93 | $msgValue = json_decode($msgValue, true); |
||
94 | break; |
||
95 | case AbstractConfig::TYPE_FIELD: |
||
96 | default: |
||
97 | $msgValue = explode($this->split, $msgValue); |
||
98 | } |
||
99 | foreach ($this->customerTmp as $tmpIndex => [$name, $type]) { |
||
100 | $this->makeLog($log, $name, $type, isset($msgValue[$tmpIndex]) ? $msgValue[$tmpIndex] : ''); |
||
101 | } |
||
102 | } else { |
||
103 | [$name, $type] = $this->fieldTemplate[$i]; |
||
104 | $this->makeLog($log, $name, $type, $msgValue); |
||
105 | $i++; |
||
106 | } |
||
107 | } |
||
108 | $this->client->send([ |
||
109 | [ |
||
110 | 'topic' => $this->topic, |
||
111 | 'value' => json_encode($log), |
||
112 | 'key' => '' |
||
113 | ] |
||
141 | } |