Completed
Push — master ( 187d75...242b2a )
by Michael
01:34
created

TableNode   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setRowSpans() 0 3 1
A __construct() 0 6 2
A toSyntax() 0 8 2
A getRowSpans() 0 3 1
A getNumTableCols() 0 2 1
A countColNum() 0 2 1
1
<?php
2
3
namespace dokuwiki\plugin\prosemirror\parser;
4
5
class TableNode extends Node
6
{
7
8
    /** @var TableRowNode[] */
9
    protected $tableRows = [];
10
    protected $rowSpans = [];
11
    protected $numCols;
12
13
    public function __construct($data)
14
    {
15
        foreach ($data['content'] as $row) {
16
            $this->tableRows[] = new TableRowNode($row, $this);
17
        }
18
        $this->countColNum();
19
    }
20
21
    /**
22
     * Count the total number of columns in the table
23
     *
24
     * This method calculates the number of columns in the first row, by adding the colspan of each cell.
25
     * This produces the correct number columns, since the first row cannot have ommited cells due to a
26
     * rowspan, as every other row could have.
27
     *
28
     */
29
    protected function countColNum() {
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
        return $this->numCols;
40
    }
41
42
    public function toSyntax()
43
    {
44
        $doc = '';
45
        foreach ($this->tableRows as $row) {
46
            $doc .= $row->toSyntax() . "\n";
47
        }
48
49
        return $doc;
50
    }
51
52
    public function getRowSpans()
53
    {
54
        return $this->rowSpans;
55
    }
56
57
    public function setRowSpans(array $rowSpans)
58
    {
59
        $this->rowSpans = $rowSpans;
60
    }
61
}
62