Conditions | 9 |
Paths | 48 |
Total Lines | 59 |
Code Lines | 41 |
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 |
||
123 | protected function formatMessageAttachment($message) |
||
124 | { |
||
125 | list($text, $level, $category, $timestamp) = $message; |
||
126 | $attachment = [ |
||
127 | 'fallback' => static::encodeMessage($this->formatMessage($message)), |
||
128 | 'title' => ucwords(Logger::getLevelName($level)), |
||
129 | 'fields' => [ |
||
130 | [ |
||
131 | 'title' => 'Level', |
||
132 | 'value' => Logger::getLevelName($level), |
||
133 | 'short' => true |
||
134 | ], |
||
135 | [ |
||
136 | 'title' => 'Category', |
||
137 | 'value' => '`' . static::encodeMessage($category) . '`', |
||
138 | 'short' => true |
||
139 | ] |
||
140 | ], |
||
141 | 'footer' => static::class, |
||
142 | 'ts' => (integer) round($timestamp), |
||
143 | 'mrkdwn_in' => [ |
||
144 | 'fields', |
||
145 | 'text' |
||
146 | ] |
||
147 | ]; |
||
148 | if (isset($this->prefix)) { |
||
149 | $attachment['fields'][] = [ |
||
150 | 'title' => 'Prefix', |
||
151 | 'value' => '`' . static::encodeMessage(call_user_func($this->prefix, $message)) . '`', |
||
152 | 'short' => true, |
||
153 | ]; |
||
154 | } |
||
155 | $this->applyApplicationFormatToAttachment($attachment); |
||
156 | if (isset($this->colors[$level])) { |
||
157 | $attachment['color'] = $this->colors[$level]; |
||
158 | } |
||
159 | if (!is_string($text)) { |
||
160 | if ($text instanceof \Throwable || $text instanceof \Exception) { |
||
161 | $text = (string) $text; |
||
162 | } else { |
||
163 | $text = VarDumper::export($text); |
||
164 | } |
||
165 | } |
||
166 | $attachment['text'] = "```\n" . static::encodeMessage($text) . "\n```"; |
||
167 | $traces = []; |
||
168 | if (isset($message[4])) { |
||
169 | foreach ($message[4] as $trace) { |
||
170 | $traces[] = "in {$trace['file']}:{$trace['line']}"; |
||
171 | } |
||
172 | } |
||
173 | if (!empty($traces)) { |
||
174 | $attachment['fields'][] = [ |
||
175 | 'title' => 'Stack Trace', |
||
176 | 'value' => "```\n" . static::encodeMessage(implode("\n", $traces)) . "\n```", |
||
177 | 'short' => false, |
||
178 | ]; |
||
179 | } |
||
180 | return $attachment; |
||
181 | } |
||
182 | |||
242 |