Passed
Pull Request — 2.5 (#1052)
by Alex
30:45
created

CommonMarkConverter::addExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 (https://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;
18
19
use League\CommonMark\Environment\Environment;
20
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
21
use League\CommonMark\Extension\ExtensionInterface;
22
23
/**
24
 * Converts CommonMark-compatible Markdown to HTML.
25
 */
26
final class CommonMarkConverter extends MarkdownConverter
27
{
28
    /**
29
     * Create a new Markdown converter pre-configured for CommonMark
30
     *
31
     * @param array<string, mixed> $config
32 1472
     */
33
    public function __construct(array $config = [])
34 1472
    {
35 1472
        $environment = new Environment($config);
36
        $environment->addExtension(new CommonMarkCoreExtension());
37 1472
38
        parent::__construct($environment);
39
    }
40 8
41
    public function getEnvironment(): Environment
42
    {
43
        \assert($this->environment instanceof Environment);
44 8
45
        return $this->environment;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->environment returns the type League\CommonMark\Environment\EnvironmentInterface which includes types incompatible with the type-hinted return League\CommonMark\Environment\Environment.
Loading history...
46
    }
47
48
    public function addExtension(ExtensionInterface $extension): void
49
    {
50
        $this->environment->addExtension($extension);
0 ignored issues
show
Bug introduced by
The method addExtension() does not exist on League\CommonMark\Environment\EnvironmentInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to League\CommonMark\Environment\EnvironmentInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $this->environment->/** @scrutinizer ignore-call */ 
51
                            addExtension($extension);
Loading history...
51
    }
52
}
53