Passed
Pull Request — main (#1074)
by
unknown
02:27
created

TableOfContentsWrapper::getInnerToc()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 22
ccs 7
cts 14
cp 0.5
crap 6
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\TableOfContents\Node;
15
16
use League\CommonMark\Exception\InvalidArgumentException;
17
use League\CommonMark\Node\Block\AbstractBlock;
18
19
final class TableOfContentsWrapper extends AbstractBlock
20
{
21 4
    public function getInnerToc(): TableOfContents
22
    {
23 4
        $children = $this->children();
24 4
        if (! \is_array($children)) {
0 ignored issues
show
introduced by
The condition is_array($children) is always true.
Loading history...
25
            /** @psalm-suppress NoValue */
26
            $children = \iterator_to_array($children);
27
        }
28
29 4
        if (\count($children) !== 2) {
30
            throw new InvalidArgumentException(
31
                'TableOfContentsWrapper nodes should have 2 children, found ' . \count($children)
32
            );
33
        }
34
35 4
        $inner = $children[1];
36 4
        if (! $inner instanceof TableOfContents) {
37
            throw new InvalidArgumentException(
38
                'TableOfContentsWrapper second node should be a TableOfContents, found ' . \get_class($inner)
39
            );
40
        }
41
42 4
        return $inner;
43
    }
44
}
45