Conditions | 14 |
Paths | 240 |
Total Lines | 75 |
Code Lines | 41 |
Lines | 0 |
Ratio | 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 |
||
98 | public function drawParam($name, $description, $values = '') { |
||
99 | $paramw = round($this->columns / 3); |
||
100 | |||
101 | echo "\n"; |
||
102 | |||
103 | $leftcolumn = []; |
||
104 | |||
105 | $valstr = is_array($values) ? implode('|', array_keys($values)) : $values; |
||
106 | |||
107 | if ('' !== $valstr) { |
||
108 | $valstr = '=[' . $valstr . ']'; |
||
109 | } |
||
110 | |||
111 | $paramstr = " \033[1m--" . $name . $valstr . "\033[0m"; |
||
112 | |||
113 | $pl =mb_orig_strlen$paramstr); |
||
|
|||
114 | if ($pl + 2 >= $paramw) { |
||
115 | $paramw = $pl + 3; |
||
116 | } |
||
117 | |||
118 | $descw = $this->columns - $paramw; |
||
119 | |||
120 | $leftcolumn[] = $paramstr; |
||
121 | |||
122 | if (is_array($values)) { |
||
123 | foreach ($values as $key => $value) { |
||
124 | $leftcolumn[] = ' ' . $key . ' - ' . $value; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | if (strlen($description) <= $descw) { |
||
129 | $rightcolumn[] = $description; |
||
130 | } |
||
131 | else { |
||
132 | $m = explode(' ', $description); |
||
133 | |||
134 | $descstr = ''; |
||
135 | |||
136 | while (sizeof($m) > 0) { |
||
137 | $el = array_shift($m); |
||
138 | |||
139 | if (strlen($descstr) +mb_orig_strlen$el) >= $descw) { |
||
140 | $rightcolumn[] = $descstr; |
||
141 | $descstr = ''; |
||
142 | } |
||
143 | else { |
||
144 | $descstr .= ' '; |
||
145 | } |
||
146 | |||
147 | $descstr .= $el; |
||
148 | } |
||
149 | |||
150 | if ('' !== $descstr) { |
||
151 | $rightcolumn[] = $descstr; |
||
152 | } |
||
153 | } |
||
154 | |||
155 | while ( |
||
156 | sizeof($leftcolumn) > 0 |
||
157 | || sizeof($rightcolumn) > 0 |
||
158 | ) { |
||
159 | if ($l = array_shift($leftcolumn)) { |
||
160 | echo str_pad($l, $paramw, ' '); |
||
161 | } |
||
162 | else { |
||
163 | echo str_repeat(' ', $paramw - 7); |
||
164 | } |
||
165 | |||
166 | if ($r = array_shift($rightcolumn)) { |
||
167 | echo $r; |
||
168 | } |
||
169 | |||
170 | echo "\n"; |
||
171 | } |
||
172 | } |
||
173 | |||
228 |