Passed
Push — latest ( b70f10...da8ccb )
by Colin
24:45 queued 22:45
created

src/CommonMarkConverter.php (1 issue)

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\Environment\EnvironmentInterface;
21
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
22
23
/**
24
 * Converts CommonMark-compatible Markdown to HTML.
25
 */
26
final class CommonMarkConverter extends MarkdownConverter
27
{
28
    /**
29
     * Create a new commonmark converter instance.
30
     *
31
     * @param array<string, mixed>      $config
32
     * @param EnvironmentInterface|null $environment DEPRECATED - Instantiate a MarkdownConverter instead
33
     */
34 2094
    public function __construct(array $config = [], ?EnvironmentInterface $environment = null)
35
    {
36
        // Passing in an $environment is deprecated
37 2094
        if ($environment !== null) {
38 6
            @\trigger_error('Passing an $environment into the CommonMarkConverter constructor is deprecated in league/commonmark v2.0 and will be removed in v3.0; use MarkdownConverter instead of CommonMarkConverter', \E_USER_DEPRECATED);
39 6
            if ($config !== []) {
40 6
                if (! ($environment instanceof Environment)) {
41 3
                    throw new \RuntimeException('Unable to configure the environment as only ' . Environment::class . ' can be configured after instantiation');
42
                }
43
44 3
                @\trigger_error('Configuring custom environments via the constructor is deprecated in league/commonmark v2.0 and will be removed in v3.0; configure it beforehand and create MarkdownConverter with it instead', \E_USER_DEPRECATED);
45 3
                $environment->mergeConfig($config);
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Enviro...ironment::mergeConfig() has been deprecated: Environment::mergeConfig() is deprecated since league/commonmark v2.0 and will be removed in v3.0. Configuration should be set when instantiating the environment instead. ( Ignorable by Annotation )

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

45
                /** @scrutinizer ignore-deprecated */ $environment->mergeConfig($config);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
46
            }
47
48 3
            parent::__construct($environment);
49
50 3
            return;
51
        }
52
53 2088
        $environment = new Environment($config);
54 2088
        $environment->addExtension(new CommonMarkCoreExtension());
55
56 2088
        parent::__construct($environment);
57 2088
    }
58
}
59