RowCol   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 19
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collectRows() 0 3 1
A collectRowColDefs() 0 3 1
B parse() 0 20 7
A collectRowColRowGroups() 0 3 1
1
<?php
2
3
namespace dlindberg\BlobChunk\Parser;
4
5
final class RowCol extends BaseParser implements Parse
6
{
7
    public function parse(\DOMElement $node): array
8
    {
9
        $this->manager->setRowColParentNode($node);
10
        $thead = $this->manager->rowColHasHeaders() ?
11
            $this->stringifyList($this->collectRowColDefs($node->firstChild)) : [];
12
        $tbody = $this->manager->rowColHasHeaders() ?
13
            $this->collectRowColRowGroups($node->firstChild) : [];
14
        if (\method_exists($tbody, 'count')) {
15
            $tbody = 1 === $tbody->count() ?
16
                $this->stringifyList($this->collectRows($tbody->item(0)->firstChild)) : $this->stringifyList($tbody);
17
        }
18
        $tbody = 0 === \count($tbody) ? $this->stringifyList($this->collectRows($node->firstChild)) : $tbody;
19
        $thead = 0 === \count($thead) ? \array_shift($tbody) : $thead;
0 ignored issues
show
Bug introduced by
It seems like $tbody can also be of type DOMNodeList; however, parameter $array of array_shift() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        $thead = 0 === \count($thead) ? \array_shift(/** @scrutinizer ignore-type */ $tbody) : $thead;
Loading history...
20
21
        return \array_map(function ($row) use ($thead) {
22
            return [
23
                'thead' => $thead,
24
                'tr'    => $row,
25
            ];
26
        }, $tbody);
27
    }
28
29
    private function collectRowColDefs(\DOMNode $node): \DOMNodeList
30
    {
31
        return $this->collect([$this->manager, 'isRowColHeaderSectionNode'], $node, $this->containerDOM());
32
    }
33
34
    private function collectRowColRowGroups(\DOMNode $node): \DOMNodeList
35
    {
36
        return $this->collect([$this->manager, 'isRowColRowGroupNode'], $node, $this->containerDOM());
37
    }
38
39
    private function collectRows(\DOMNode $node): \DOMNodeList
40
    {
41
        return $this->collect([$this->manager, 'isRowColRowNode'], $node, $this->containerDOM());
42
    }
43
}
44