TableNode::getRowSpans()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace dokuwiki\plugin\prosemirror\parser;
4
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)
59
    {
60
        $this->rowSpans = $rowSpans;
61
    }
62
}
63