Conditions | 10 |
Paths | 10 |
Total Lines | 43 |
Code Lines | 20 |
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 namespace UnderstandMonolog\Encoder; |
||
112 | protected function stackTraceArgsToArray(array $trace) |
||
113 | { |
||
114 | $params = []; |
||
115 | |||
116 | if (! isset($trace['args'])) |
||
117 | { |
||
118 | return $params; |
||
119 | } |
||
120 | |||
121 | foreach ($trace['args'] as $arg) |
||
122 | { |
||
123 | if (is_array($arg)) |
||
124 | { |
||
125 | $params[] = 'array(' . count($arg) . ')'; |
||
126 | } |
||
127 | else if (is_object($arg)) |
||
128 | { |
||
129 | $params[] = get_class($arg); |
||
130 | } |
||
131 | else if (is_string($arg)) |
||
132 | { |
||
133 | $params[] = 'string(' . $arg . ')'; |
||
134 | } |
||
135 | else if (is_int($arg)) |
||
136 | { |
||
137 | $params[] = 'int(' . $arg . ')'; |
||
138 | } |
||
139 | else if (is_float($arg)) |
||
140 | { |
||
141 | $params[] = 'float(' . $arg . ')'; |
||
142 | } |
||
143 | else if (is_bool($arg)) |
||
144 | { |
||
145 | $params[] = 'bool(' . ($arg ? 'true' : 'false') . ')'; |
||
146 | } |
||
147 | else |
||
148 | { |
||
149 | $params[] = (string) $arg; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | return $params; |
||
154 | } |
||
155 | } |
||
156 |