Completed
Push — 1.5 ( 93aa3f...fe2226 )
by Colin
01:05
created

setConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
crap 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
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark\Extension\TableOfContents;
13
14
use League\CommonMark\Block\Parser\BlockParserInterface;
15
use League\CommonMark\ContextInterface;
16
use League\CommonMark\Cursor;
17
use League\CommonMark\Extension\TableOfContents\Node\TableOfContentsPlaceholder;
18
use League\CommonMark\Util\ConfigurationAwareInterface;
19
use League\CommonMark\Util\ConfigurationInterface;
20
21
final class TableOfContentsPlaceholderParser implements BlockParserInterface, ConfigurationAwareInterface
22
{
23
    /** @var ConfigurationInterface */
24
    private $config;
25
26 3
    public function parse(ContextInterface $context, Cursor $cursor): bool
27
    {
28 3
        $placeholder = $this->config->get('table_of_contents/placeholder');
29 3
        if ($placeholder === null) {
30
            return false;
31
        }
32
33
        // The placeholder must be the only thing on the line
34 3
        if ($cursor->match('/^' . \preg_quote($placeholder, '/') . '$/') === null) {
35 3
            return false;
36
        }
37
38 3
        $context->addBlock(new TableOfContentsPlaceholder());
39
40 3
        return true;
41
    }
42
43 3
    public function setConfiguration(ConfigurationInterface $configuration)
44
    {
45 3
        $this->config = $configuration;
46 3
    }
47
}
48