Conditions | 30 |
Paths | 154 |
Total Lines | 133 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 14 | ||
Bugs | 0 | Features | 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 |
||
93 | public function mixedToUl($mixed): string |
||
94 | { |
||
95 | if ($this->isSafe()) { |
||
96 | if (false === $mixed) { |
||
97 | return '<span style="color: grey">[NO]</span>'; |
||
98 | } |
||
99 | |||
100 | if (true === $mixed) { |
||
101 | return '<span style="color: grey">[YES]</span>'; |
||
102 | } |
||
103 | |||
104 | if (null === $mixed) { |
||
105 | return '<span style="color: grey">[NULL]</span>'; |
||
106 | } |
||
107 | |||
108 | if (0 === $mixed) { |
||
109 | return '<span style="color: green">[ZERO]</span>'; |
||
110 | } |
||
111 | |||
112 | if (1 === $mixed) { |
||
113 | return '<span style="color: green">[ONE]</span>'; |
||
114 | } |
||
115 | |||
116 | if (is_int($mixed)) { |
||
117 | return '<span style="color: green">' . $mixed . '</span>'; |
||
118 | } |
||
119 | |||
120 | if (is_float($mixed)) { |
||
121 | return '<span style="color: green">' . $mixed . '</span>'; |
||
122 | } |
||
123 | |||
124 | if ('' === $mixed) { |
||
125 | return '<span style="color: grey">[EMPTY STRING]</span>'; |
||
126 | } |
||
127 | |||
128 | if (is_array($mixed) && [] === $mixed) { |
||
129 | return '<span style="color: grey">[EMPTY ARRAY]</span>'; |
||
130 | } |
||
131 | |||
132 | if (is_object($mixed)) { |
||
133 | if ($mixed instanceof ArrayData) { |
||
134 | return $this->mixedToUl($mixed->toMap()); |
||
135 | } |
||
136 | |||
137 | if ($mixed instanceof ArrayList) { |
||
138 | return $this->mixedToUl($mixed->toArray()); |
||
139 | } |
||
140 | |||
141 | if ($mixed instanceof DataList || $mixed instanceof PaginatedList) { |
||
142 | $parameters = null; |
||
143 | $sql = $mixed->sql($parameters); |
||
144 | $sql = DB::inline_parameters($sql, $parameters); |
||
145 | $sql = str_replace('"', '`', $sql); |
||
146 | |||
147 | return |
||
148 | $this->mixedToUl($sql) . '<hr />' . |
||
149 | $this->mixedToUl($mixed->map('ID', 'Title')->toArray()); |
||
150 | } |
||
151 | |||
152 | if ($mixed instanceof DataObject) { |
||
153 | return $mixed->i18n_singular_name() . ': ' . $mixed->getTitle() . |
||
154 | ' (' . $mixed->ClassName . ', ' . $mixed->ID . ')'; |
||
155 | } |
||
156 | |||
157 | return '<span style="color: red">' . substr(Debug::text($mixed), 0, 500) . '</span>'; |
||
158 | } |
||
159 | |||
160 | if (is_array($mixed)) { |
||
161 | $html = ''; |
||
162 | $isAssoc = $this->isAssoc($mixed); |
||
163 | $count = count($mixed); |
||
164 | $isLarge = false; |
||
165 | if ($count > 1) { |
||
166 | $html .= '' . count($mixed) . ' entries ... '; |
||
167 | $isLarge = count($mixed) > 20; |
||
168 | } |
||
169 | |||
170 | $after = ''; |
||
171 | $style = ''; |
||
172 | $keyString = ''; |
||
173 | if ($isLarge) { |
||
174 | $style = 'display: inline;'; |
||
175 | $after = ', '; |
||
176 | } |
||
177 | |||
178 | $itemHTML = '<ol>'; |
||
|
|||
179 | $count = 0; |
||
180 | $itemHTML = ''; |
||
181 | $flatArray = true; |
||
182 | foreach ($mixed as $key => $item) { |
||
183 | if (is_array($item) || is_object($item)) { |
||
184 | $flatArray = false; |
||
185 | } |
||
186 | |||
187 | ++$count; |
||
188 | if ($isAssoc) { |
||
189 | $keyString = '<strong>' . $key . '</strong>: '; |
||
190 | } |
||
191 | |||
192 | if ($count > 20) { |
||
193 | $data = '.'; |
||
194 | $keyString = ''; |
||
195 | } |
||
196 | |||
197 | if (!$flatArray) { |
||
198 | $mixed[$key] = $this->mixedToUl($item); |
||
199 | } |
||
200 | |||
201 | $itemHTML .= '<li style="' . $style . '">' . $keyString . $mixed[$key] . $after . '</li>'; |
||
202 | } |
||
203 | |||
204 | if ($flatArray) { |
||
205 | $itemHTML = ArrayToTable::convert($mixed, 10, 100); |
||
206 | } else { |
||
207 | $itemHTML .= '</ol>'; |
||
208 | } |
||
209 | |||
210 | return $html . $itemHTML; |
||
211 | } |
||
212 | |||
213 | if (is_string($mixed)) { |
||
214 | $isSql = ''; |
||
215 | if ($this->isSql($mixed)) { |
||
216 | $mixed = $this->stringToSqlExplainer($isSql . $mixed); |
||
217 | } |
||
218 | |||
219 | return '<span style="color: green">' . substr((string) $mixed, 0, 10000) . '</span>'; |
||
220 | } |
||
221 | |||
222 | return '<span style="color: red">' . substr(Debug::text($mixed), 0, 500) . '</span>'; |
||
223 | } |
||
224 | |||
225 | return '<span style="color: red">ERROR: please turn on SS_VARDUMP_DEBUG_ALLOWED to see data.</span>'; |
||
226 | } |
||
294 |