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

TableOfContentsWrapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
ccs 7
cts 14
cp 0.5
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getInnerToc() 0 21 4
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 InvalidArgumentException;
17
use League\CommonMark\Node\Block\AbstractBlock;
18
19
final class TableOfContentsWrapper extends AbstractBlock
20
{
21
    /**
22
     * @throws InvalidArgumentException
23
     */
24 4
    public function getInnerToc(): TableOfContents
25
    {
26 4
        $children = $this->children();
27 4
        if (! \is_array($children)) {
0 ignored issues
show
introduced by
The condition is_array($children) is always true.
Loading history...
28
            $children = \iterator_to_array($children);
29
        }
30
31 4
        if (\count($children) !== 2) {
32
            throw new InvalidArgumentException(
33
                'TableOfContentsWrapper nodes should have 2 children, found ' . \count($children)
34
            );
35
        }
36
37 4
        $inner = $children[1];
38 4
        if (! $inner instanceof TableOfContents) {
39
            throw new InvalidArgumentException(
40
                'TableOfContentsWrapper second node should be a TableOfContents, found ' . \get_class($inner)
41
            );
42
        }
43
44 4
        return $inner;
45
    }
46
}
47