| Conditions | 10 |
| Paths | 39 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 68 | public function toHTML(?string $url_column = null): string { |
||
| 69 | // Generate a HTML table from the DataFrame |
||
| 70 | $html = '<div style="overflow-x: auto; white-space: nowrap;">'; |
||
| 71 | $html .= '<table class="df-table">'; |
||
| 72 | // Add table headers |
||
| 73 | $html .= '<tr class="df-row">'; |
||
| 74 | foreach ($this->columns as $column) { |
||
| 75 | if ($url_column === $column) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | $html .= '<th class="df-header">' . htmlspecialchars($column) . '</th>'; |
||
| 79 | } |
||
| 80 | $html .= '</tr>'; |
||
| 81 | // Add table rows |
||
| 82 | foreach ($this->rows as $row) { |
||
| 83 | $url_value = $url_column ? $row->get($url_column) : null; |
||
| 84 | $html .= '<tr class="df-row">'; |
||
| 85 | foreach ($this->columns as $index => $column) { |
||
| 86 | if ($url_column === $column) { |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | $raw_cell_value = $row->get($column); |
||
| 90 | $cell_value = htmlspecialchars((string) $raw_cell_value); |
||
| 91 | $data_classes = ['df-data']; |
||
| 92 | if (is_numeric($raw_cell_value)) { |
||
| 93 | $data_classes[] = 'df-data--number'; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($url_value && $index === 0) { |
||
| 97 | // wrap first value in url |
||
| 98 | $cell_value = '<a href="' . $url_value . '">' . $cell_value . '</a>'; |
||
| 99 | } |
||
| 100 | $html .= '<td class="' . implode(' ', $data_classes) . '">' . $cell_value . '</td>'; |
||
| 101 | } |
||
| 102 | $html .= '</tr>'; |
||
| 103 | } |
||
| 104 | $html .= '</table>'; |
||
| 105 | $html .= '</div>'; |
||
| 106 | return $html; |
||
| 107 | } |
||
| 109 |