| Conditions | 21 |
| Paths | 9 |
| Total Lines | 95 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 84 | public function fixTables() |
||
| 85 | { |
||
| 86 | $tables = $this->getBoxesByType('TableWrapperBox'); |
||
| 87 | foreach ($tables as $tableWrapperBox) { |
||
| 88 | $tableBox = $tableWrapperBox->getFirstChild(); |
||
| 89 | $rowGroups = $tableBox->getChildren(); |
||
| 90 | foreach ($rowGroups as $rowGroup) { |
||
| 91 | // wrap rows with row groups |
||
| 92 | if ($rowGroup instanceof TableRowBox) { |
||
| 93 | if (!isset($wrapRowGroup)) { |
||
| 94 | $wrapRowGroup = $tableBox->removeChild($tableBox->createRowGroupBox()); |
||
| 95 | $tableBox->insertBefore($wrapRowGroup, $rowGroup); |
||
| 96 | } |
||
| 97 | $wrapRowGroup->appendChild($tableBox->removeChild($rowGroup)); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | unset($wrapRowGroup); |
||
| 101 | $rowGroups = $tableBox->getChildren(); |
||
| 102 | if (empty($rowGroups)) { |
||
| 103 | $rowGroup = $tableBox->createRowGroupBox(); |
||
| 104 | $row = $rowGroup->createRowBox(); |
||
| 105 | $column = $row->createColumnBox(); |
||
| 106 | $column->createCellBox(); |
||
| 107 | } else { |
||
| 108 | $columnsCount = 0; |
||
| 109 | foreach ($rowGroups as $rowGroup) { |
||
| 110 | if (!$rowGroup->hasChildren()) { |
||
| 111 | $row = $rowGroup->createRowBox(); |
||
| 112 | $column = $row->createColumnBox(); |
||
| 113 | $column->createCellBox(); |
||
| 114 | } |
||
| 115 | foreach ($rowGroup->getChildren() as $rowIndex => $row) { |
||
| 116 | $columns = $row->getChildren(); |
||
| 117 | $columnsCount = max($columnsCount, \count($columns)); |
||
| 118 | foreach ($columns as $columnIndex => $column) { |
||
| 119 | if ($column->getRowSpan() > 1) { |
||
| 120 | $rowSpans = $column->getRowSpan(); |
||
| 121 | for ($i = 1; $i < $rowSpans; ++$i) { |
||
| 122 | $nextRow = $rowGroup->getChildren()[$rowIndex + $i]; |
||
| 123 | $rowChildren = $nextRow->getChildren(); |
||
| 124 | $insertColumn = $nextRow->removeChild($nextRow->createColumnBox()); |
||
| 125 | if (isset($rowChildren[$columnIndex])) { |
||
| 126 | $before = $rowChildren[$columnIndex]; |
||
| 127 | $nextRow->insertBefore($insertColumn, $before); |
||
| 128 | } else { |
||
| 129 | $nextRow->appendChild($insertColumn); |
||
| 130 | } |
||
| 131 | $insertColumn->setStyle(clone $column->getStyle()); |
||
| 132 | $insertColumn->getStyle()->setBox($insertColumn); |
||
| 133 | $insertCell = $insertColumn->createCellBox(); |
||
| 134 | $insertCell->setStyle(clone $column->getFirstChild()->getStyle()); |
||
| 135 | $insertCell->getStyle()->setBox($insertCell); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | foreach ($rowGroup->getChildren() as $row) { |
||
| 141 | $columns = $row->getChildren(); |
||
| 142 | $missing = $columnsCount - \count($columns); |
||
| 143 | for ($i = 0; $i < $missing; ++$i) { |
||
| 144 | $column = $row->createColumnBox(); |
||
| 145 | $column->createCellBox(); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | // fix row spans |
||
| 149 | $rowSpans = []; |
||
| 150 | $rowSpansUp = []; |
||
| 151 | foreach ($rowGroup->getChildren() as $row) { |
||
| 152 | foreach ($row->getChildren() as $columnIndex => $column) { |
||
| 153 | if ($column->getRowSpan() > 1) { |
||
| 154 | $rowSpans[$columnIndex] = $column->getRowSpan(); |
||
| 155 | $rowSpansUp[$columnIndex] = 0; |
||
| 156 | $column->setRowSpanUp(0); |
||
| 157 | $row->setRowSpanUp(max($row->getRowSpanUp(), 0)); |
||
| 158 | $row->setRowSpan(max($row->getRowSpan(), $column->getRowSpan())); |
||
| 159 | } else { |
||
| 160 | if (isset($rowSpans[$columnIndex]) && $rowSpans[$columnIndex] > 1) { |
||
| 161 | if ($rowSpansUp[$columnIndex] < $rowSpans[$columnIndex]) { |
||
| 162 | ++$rowSpansUp[$columnIndex]; |
||
| 163 | $column->setRowSpanUp($rowSpansUp[$columnIndex]); |
||
| 164 | $row->setRowSpanUp(max($row->getRowSpanUp(), $rowSpansUp[$columnIndex])); |
||
| 165 | $row->setRowSpan(max($row->getRowSpan(), $column->getRowSpan())); |
||
| 166 | } else { |
||
| 167 | $rowSpansUp[$columnIndex] = 0; |
||
| 168 | $rowSpans[$columnIndex] = 1; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | return $this; |
||
| 179 | } |
||
| 295 |