Passed
Push — master ( 3b69a6...ebea0a )
by Caen
05:44 queued 02:49
created

mergeMarkdownConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Hyde\Framework\Concerns\Internal;
4
5
use Hyde\Framework\Modules\Markdown\BladeDownProcessor;
6
use Hyde\Framework\Modules\Markdown\CodeblockFilepathProcessor;
7
use Hyde\Framework\Modules\Markdown\ShortcodeProcessor;
8
use Torchlight\Commonmark\V2\TorchlightExtension;
9
10
/**
11
 * @internal Sets up the Markdown converter for the Markdown service.
12
 *
13
 * @see \Hyde\Framework\Services\MarkdownService
14
 */
15
trait SetsUpMarkdownConverter
16
{
17
    protected function enableDynamicExtensions(): void
18
    {
19
        if ($this->canEnablePermalinks()) {
0 ignored issues
show
Bug introduced by
It seems like canEnablePermalinks() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

19
        if ($this->/** @scrutinizer ignore-call */ canEnablePermalinks()) {
Loading history...
20
            $this->configurePermalinksExtension();
0 ignored issues
show
Bug introduced by
It seems like configurePermalinksExtension() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

20
            $this->/** @scrutinizer ignore-call */ 
21
                   configurePermalinksExtension();
Loading history...
21
        }
22
23
        if ($this->canEnableTorchlight()) {
0 ignored issues
show
Bug introduced by
It seems like canEnableTorchlight() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        if ($this->/** @scrutinizer ignore-call */ canEnableTorchlight()) {
Loading history...
24
            $this->addExtension(TorchlightExtension::class);
0 ignored issues
show
Bug introduced by
It seems like addExtension() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
            $this->/** @scrutinizer ignore-call */ 
25
                   addExtension(TorchlightExtension::class);
Loading history...
25
        }
26
27
        if (config('markdown.allow_html', false)) {
28
            $this->enableAllHtmlElements();
0 ignored issues
show
Bug introduced by
It seems like enableAllHtmlElements() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
            $this->/** @scrutinizer ignore-call */ 
29
                   enableAllHtmlElements();
Loading history...
29
        }
30
    }
31
32
    protected function enableConfigDefinedExtensions(): void
33
    {
34
        foreach (config('markdown.extensions', []) as $extensionClassName) {
35
            $this->addExtension($extensionClassName);
36
        }
37
    }
38
39
    protected function mergeMarkdownConfiguration(): void
40
    {
41
        $this->config = array_merge(config('markdown.config', []), $this->config);
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
    }
43
44
    public function initializeExtension(string $extensionClassName): void
45
    {
46
        $this->converter->getEnvironment()->addExtension(new $extensionClassName());
47
    }
48
49
    protected function registerPreProcessors(): void
50
    {
51
        $this->registerPreProcessor(BladeDownProcessor::class, config('markdown.enable_blade', false));
52
53
        $this->registerPreProcessor(ShortcodeProcessor::class);
54
        $this->registerPreProcessor(CodeblockFilepathProcessor::class);
55
    }
56
57
    protected function registerPostProcessors(): void
58
    {
59
        $this->registerPostProcessor(BladeDownProcessor::class,
60
            config('markdown.enable_blade', false));
61
62
        $this->registerPostProcessor(CodeblockFilepathProcessor::class,
63
            config('markdown.features.codeblock_filepaths', true));
64
    }
65
66
    protected function registerPreProcessor(string $class, bool $when = true): void
67
    {
68
        if (! in_array($class, $this->preprocessors) && $when) {
69
            $this->preprocessors[] = $class;
0 ignored issues
show
Bug Best Practice introduced by
The property preprocessors does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
70
        }
71
    }
72
73
    protected function registerPostProcessor(string $class, bool $when = true): void
74
    {
75
        if (! in_array($class, $this->postprocessors) && $when) {
76
            $this->postprocessors[] = $class;
0 ignored issues
show
Bug Best Practice introduced by
The property postprocessors does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
        }
78
    }
79
}
80