| Conditions | 12 |
| Paths | 5 |
| Total Lines | 75 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 7 | public static function convert(array $array, $maxCols = 20, $maxRows = 20): string |
||
|
|
|||
| 8 | { |
||
| 9 | $maxRows = 9999999999; |
||
| 10 | $html = ''; |
||
| 11 | $rowCount = 0; |
||
| 12 | if ([] !== $array) { |
||
| 13 | $html = ' |
||
| 14 | <style> |
||
| 15 | .vardump-data-table { |
||
| 16 | width: 100%; |
||
| 17 | } |
||
| 18 | .vardump-data-table td, |
||
| 19 | .vardump-data-table th { |
||
| 20 | padding: 2px; |
||
| 21 | font-size: 10px; |
||
| 22 | text-align: left; |
||
| 23 | } |
||
| 24 | </style> |
||
| 25 | <table class="vardump-data-table" border="1"> |
||
| 26 | '; |
||
| 27 | if (self::isMultiDimensionalArray($array)) { |
||
| 28 | $header = $array[0] ?? $array; |
||
| 29 | $html .= '<tr>'; |
||
| 30 | $colCount = 0; |
||
| 31 | foreach ($header as $key => $value) { |
||
| 32 | ++$colCount; |
||
| 33 | if ($colCount < $maxCols) { |
||
| 34 | $html .= '<th>' . htmlspecialchars($key) . '</th>'; |
||
| 35 | } else { |
||
| 36 | $html .= '<th>...</th>'; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | $html .= '</tr>'; |
||
| 41 | // data rows |
||
| 42 | |||
| 43 | foreach ($array as $key => $value) { |
||
| 44 | if ($rowCount < $maxRows) { |
||
| 45 | ++$rowCount; |
||
| 46 | $colCount = 0; |
||
| 47 | $html .= '<tr>'; |
||
| 48 | foreach ($value as $key2 => $value2) { |
||
| 49 | ++$colCount; |
||
| 50 | if ($colCount < $maxCols) { |
||
| 51 | $html .= '<td>' . strip_tags( (string) $value2) . '</td>'; |
||
| 52 | } else { |
||
| 53 | $html .= '<td>...</td>'; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | $html .= '</tr>'; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } else { |
||
| 61 | foreach ($array as $key => $value) { |
||
| 62 | if ($rowCount < $maxRows) { |
||
| 63 | ++$rowCount; |
||
| 64 | $html .= ' |
||
| 65 | <tr> |
||
| 66 | <th>' . $key . '</th> |
||
| 67 | <td>' . strip_tags( (string) $value) . '</td> |
||
| 68 | </tr>'; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $html .= '</table>'; |
||
| 74 | if ($rowCount === $maxRows) { |
||
| 75 | $html .= '<p>not all rows shown</p>'; |
||
| 76 | } |
||
| 77 | } else { |
||
| 78 | $html .= '<p>no data available</p>'; |
||
| 79 | } |
||
| 80 | |||
| 81 | return $html; |
||
| 82 | } |
||
| 89 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.