Conditions | 11 |
Paths | 41 |
Total Lines | 41 |
Code Lines | 25 |
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 |
||
45 | public function export() |
||
46 | { |
||
47 | foreach ($this->messages as $message) { |
||
48 | $context = []; |
||
49 | if (isset($message[4])) { |
||
50 | $context['trace'] = $message[4]; |
||
51 | } |
||
52 | |||
53 | if (isset($message[5])) { |
||
54 | $context['memory'] = $message[5]; |
||
55 | } |
||
56 | |||
57 | if (isset($message[2])) { |
||
58 | $context['category'] = $message[2]; |
||
59 | } |
||
60 | |||
61 | $text = $message[0]; |
||
62 | |||
63 | if (!is_string($text)) { |
||
64 | // exceptions may not be serializable if in the call stack somewhere is a Closure |
||
65 | if ($text instanceof \Throwable || $text instanceof \Exception) { |
||
66 | $text = (string)$text; |
||
67 | } else if (\is_array($text)) { |
||
68 | $ctx = $text; |
||
69 | if (isset($ctx['message'])) { |
||
70 | $text = $ctx['message']; |
||
71 | unset($ctx['message']); |
||
72 | foreach ($ctx as $k => $v) { |
||
73 | $context[$k] = $v; |
||
74 | } |
||
75 | } else { |
||
76 | $text = VarDumper::export($text); |
||
77 | } |
||
78 | } else { |
||
79 | $text = VarDumper::export($text); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | $this->getLogger()->log($this->_psrLevels[$message[1]], $text, $context); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 |