ConsecutiveDescriptionListMerger   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 5
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
use League\CommonMark\Node\NodeIterator;
19
20
final class ConsecutiveDescriptionListMerger
21
{
22
    public function __invoke(DocumentParsedEvent $event): void
23
    {
24
        foreach ($event->getDocument()->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) {
25
            if (! $node instanceof DescriptionList) {
26
                continue;
27
            }
28
29
            if (! ($prev = $node->previous()) instanceof DescriptionList) {
30
                continue;
31
            }
32
33
            // There's another description list behind this one; merge the current one into that
34
            foreach ($node->children() as $child) {
35
                $prev->appendChild($child);
36
            }
37
38
            $node->detach();
39
        }
40
    }
41
}
42