Table::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the league/commonmark-ext-table package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
10
 * (c) Colin O'Dell <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace League\CommonMark\Ext\Table;
17
18
use League\CommonMark\Block\Element\AbstractBlock;
19
use League\CommonMark\Block\Element\AbstractStringContainerBlock;
20
use League\CommonMark\Block\Element\InlineContainerInterface;
21
use League\CommonMark\ContextInterface;
22
use League\CommonMark\Cursor;
23
24
class Table extends AbstractStringContainerBlock implements InlineContainerInterface
25
{
26
    private $caption;
27
    private $head;
28
    private $body;
29
    private $parser;
30
31 34
    public function __construct(\Closure $parser)
32
    {
33 34
        parent::__construct();
34 34
        $this->appendChild($this->head = new TableSection(TableSection::TYPE_HEAD));
35 34
        $this->appendChild($this->body = new TableSection(TableSection::TYPE_BODY));
36 34
        $this->parser = $parser;
37 34
    }
38
39
    public function canContain(AbstractBlock $block): bool
40
    {
41
        return $block instanceof TableSection || $block instanceof TableCaption;
42
    }
43
44 34
    public function isCode(): bool
45
    {
46 34
        return false;
47
    }
48
49 4
    public function setCaption(TableCaption $caption = null): void
50
    {
51 4
        $node = $this->getCaption();
52 4
        if ($node instanceof TableCaption) {
53
            $node->detach();
54
        }
55
56 4
        $this->caption = $caption;
57 4
        if (null !== $caption) {
58 4
            $this->prependChild($caption);
59
        }
60 4
    }
61
62 12
    public function getCaption(): ?TableCaption
63
    {
64 12
        return $this->caption;
65
    }
66
67 34
    public function getHead(): TableSection
68
    {
69 34
        return $this->head;
70
    }
71
72 34
    public function getBody(): TableSection
73
    {
74 34
        return $this->body;
75
    }
76
77 34
    public function matchesNextLine(Cursor $cursor): bool
78
    {
79 34
        return call_user_func($this->parser, $cursor, $this);
80
    }
81
82 34
    public function handleRemainingContents(ContextInterface $context, Cursor $cursor): void
83
    {
84 34
    }
85
}
86