SmartPunctExtension::register()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 21
ccs 14
cts 14
cp 1
rs 9.7998
cc 1
nc 1
nop 1
crap 1
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
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace League\CommonMark\Extension\SmartPunct;
18
19
use League\CommonMark\Environment\EnvironmentBuilderInterface;
20
use League\CommonMark\Extension\ConfigurableExtensionInterface;
21
use League\CommonMark\Node\Block\Document;
22
use League\CommonMark\Node\Block\Paragraph;
23
use League\CommonMark\Node\Inline\Text;
24
use League\CommonMark\Renderer\Block as CoreBlockRenderer;
25
use League\CommonMark\Renderer\Inline as CoreInlineRenderer;
26
use League\Config\ConfigurationBuilderInterface;
27
use Nette\Schema\Expect;
28
29
final class SmartPunctExtension implements ConfigurableExtensionInterface
30
{
31 51
    public function configureSchema(ConfigurationBuilderInterface $builder): void
32
    {
33 51
        $builder->addSchema('smartpunct', Expect::structure([
34 51
            'double_quote_opener' => Expect::string(Quote::DOUBLE_QUOTE_OPENER),
35 51
            'double_quote_closer' => Expect::string(Quote::DOUBLE_QUOTE_CLOSER),
36 51
            'single_quote_opener' => Expect::string(Quote::SINGLE_QUOTE_OPENER),
37 51
            'single_quote_closer' => Expect::string(Quote::SINGLE_QUOTE_CLOSER),
38
        ]));
39 51
    }
40
41 51
    public function register(EnvironmentBuilderInterface $environment): void
42
    {
43
        $environment
44 51
            ->addInlineParser(new QuoteParser(), 10)
45 51
            ->addInlineParser(new DashParser(), 0)
46 51
            ->addInlineParser(new EllipsesParser(), 0)
47
48 51
            ->addDelimiterProcessor(QuoteProcessor::createDoubleQuoteProcessor(
49 51
                $environment->getConfiguration()->get('smartpunct/double_quote_opener'),
50 51
                $environment->getConfiguration()->get('smartpunct/double_quote_closer')
51
            ))
52 51
            ->addDelimiterProcessor(QuoteProcessor::createSingleQuoteProcessor(
53 51
                $environment->getConfiguration()->get('smartpunct/single_quote_opener'),
54 51
                $environment->getConfiguration()->get('smartpunct/single_quote_closer')
55
            ))
56
57 51
            ->addRenderer(Document::class, new CoreBlockRenderer\DocumentRenderer(), 0)
58 51
            ->addRenderer(Paragraph::class, new CoreBlockRenderer\ParagraphRenderer(), 0)
59
60 51
            ->addRenderer(Quote::class, new QuoteRenderer(), 100)
61 51
            ->addRenderer(Text::class, new CoreInlineRenderer\TextRenderer(), 0);
62 51
    }
63
}
64