Completed
Push — latest ( 6c0640...3af091 )
by Colin
16s queued 11s
created

ConsecutiveDescriptionListMerger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 28
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 26 6
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\DescriptionList\Event;
15
16
use League\CommonMark\Event\DocumentParsedEvent;
17
use League\CommonMark\Extension\DescriptionList\Node\DescriptionList;
18
19
final class ConsecutiveDescriptionListMerger
20
{
21 42
    public function __invoke(DocumentParsedEvent $event): void
22
    {
23 42
        $walker = $event->getDocument()->walker();
24 42
        while ($e = $walker->next()) {
25
            // Wait until we're exiting a description list node
26 42
            if ($e->isEntering()) {
27 42
                continue;
28
            }
29
30 42
            $node = $e->getNode();
31 42
            if (! $node instanceof DescriptionList) {
32 42
                continue;
33
            }
34
35 33
            if (! ($next = $node->next()) instanceof DescriptionList) {
36 33
                continue;
37
            }
38
39
            // There's another description list next; merge it into the current one
40 33
            foreach ($next->children() as $child) {
41 33
                $node->appendChild($child);
42
            }
43
44 33
            $next->detach();
45
46 33
            $walker->resumeAt($node, false);
47
        }
48 42
    }
49
}
50