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

src/GithubFlavoredMarkdownConverter.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
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark;
15
16
use League\CommonMark\Environment\Environment;
17
use League\CommonMark\Environment\EnvironmentInterface;
18
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
19
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
20
21
/**
22
 * Converts GitHub Flavored Markdown to HTML.
23
 */
24
final class GithubFlavoredMarkdownConverter extends MarkdownConverter
25
{
26
    /**
27
     * Create a new commonmark converter instance.
28
     *
29
     * @param array<string, mixed>      $config
30
     * @param EnvironmentInterface|null $environment DEPRECATED - Instantiate a MarkdownConverter instead
31
     */
32 81
    public function __construct(array $config = [], ?EnvironmentInterface $environment = null)
33
    {
34
        // Passing in an $environment is deprecated
35 81
        if ($environment !== null) {
36
            @\trigger_error('Passing an $environment into the GithubFlavoredMarkdownConverter constructor is deprecated in league/commonmark v2.0 and will be removed in v3.0; use MarkdownConverter instead of CommonMarkConverter', \E_USER_DEPRECATED);
37
            if ($config !== []) {
38
                if (! ($environment instanceof Environment)) {
39
                    throw new \RuntimeException('Unable to configure the environment as only ' . Environment::class . ' can be configured after instantiation');
40
                }
41
42
                @\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);
43
                $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

43
                /** @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...
44
            }
45
46
            parent::__construct($environment);
47
48
            return;
49
        }
50
51 81
        $environment = new Environment($config);
52 81
        $environment->addExtension(new CommonMarkCoreExtension());
53 81
        $environment->addExtension(new GithubFlavoredMarkdownExtension());
54
55 81
        parent::__construct($environment);
56 81
    }
57
}
58