UnmatchedBlockCloser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 59
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setLastMatchedContainer() 0 4 1
A closeUnmatchedBlocks() 0 10 2
A resetTip() 0 4 1
A areAllClosed() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
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 League\CommonMark;
16
17
use League\CommonMark\Block\Element\AbstractBlock;
18
19
class UnmatchedBlockCloser
20
{
21
    /**
22
     * @var ContextInterface
23
     */
24
    private $context;
25
26
    /**
27
     * @var AbstractBlock
28
     */
29
    private $oldTip;
30
31
    /**
32
     * @var AbstractBlock
33
     */
34
    private $lastMatchedContainer;
35
36
    /**
37
     * @param ContextInterface $context
38
     */
39 1950
    public function __construct(ContextInterface $context)
40
    {
41 1950
        $this->context = $context;
42
43 1950
        $this->resetTip();
44 1950
    }
45
46
    /**
47
     * @param AbstractBlock $block
48
     */
49 1938
    public function setLastMatchedContainer(AbstractBlock $block)
50
    {
51 1938
        $this->lastMatchedContainer = $block;
52 1938
    }
53
54 1938
    public function closeUnmatchedBlocks()
55
    {
56 1938
        $endLine = $this->context->getLineNumber() - 1;
57
58 1938
        while ($this->oldTip !== $this->lastMatchedContainer) {
59 666
            $oldTip = $this->oldTip->parent();
60 666
            $this->oldTip->finalize($this->context, $endLine);
61 666
            $this->oldTip = $oldTip;
62 222
        }
63 1938
    }
64
65 1950
    public function resetTip()
66
    {
67 1950
        $this->oldTip = $this->context->getTip();
68 1950
    }
69
70
    /**
71
     * @return bool
72
     */
73 639
    public function areAllClosed()
74
    {
75 639
        return $this->context->getTip() === $this->lastMatchedContainer;
76
    }
77
}
78