Table   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 1
dl 0
loc 62
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0

9 Methods

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