| Total Complexity | 8 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 5 | class TableNode extends Node |
||
| 6 | { |
||
| 7 | /** @var TableRowNode[] */ |
||
| 8 | protected $tableRows = []; |
||
| 9 | protected $rowSpans = []; |
||
| 10 | protected $numCols; |
||
| 11 | |||
| 12 | public function __construct($data, Node $parent = null) |
||
| 13 | { |
||
| 14 | foreach ($data['content'] as $row) { |
||
| 15 | $this->tableRows[] = new TableRowNode($row, $this); |
||
| 16 | } |
||
| 17 | $this->countColNum(); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Count the total number of columns in the table |
||
| 22 | * |
||
| 23 | * This method calculates the number of columns in the first row, by adding the colspan of each cell. |
||
| 24 | * This produces the correct number columns, since the first row cannot have ommited cells due to a |
||
| 25 | * rowspan, as every other row could have. |
||
| 26 | * |
||
| 27 | */ |
||
| 28 | protected function countColNum() |
||
| 29 | { |
||
| 30 | $this->numCols = $this->tableRows[0]->countCols(); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Get the total number of columns for this table |
||
| 35 | * |
||
| 36 | * @return int |
||
| 37 | */ |
||
| 38 | public function getNumTableCols() |
||
| 39 | { |
||
| 40 | return $this->numCols; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function toSyntax() |
||
| 44 | { |
||
| 45 | $doc = ''; |
||
| 46 | foreach ($this->tableRows as $row) { |
||
| 47 | $doc .= $row->toSyntax() . "\n"; |
||
| 48 | } |
||
| 49 | |||
| 50 | return $doc; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getRowSpans() |
||
| 54 | { |
||
| 55 | return $this->rowSpans; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function setRowSpans(array $rowSpans) |
||
| 61 | } |
||
| 62 | } |
||
| 63 |