MarkdownDecorator::decorateFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\Markdown;
11
12
use Michelf\MarkdownExtra;
13
use Symplify\PHP7_Sculpin\Contract\Renderable\DecoratorInterface;
14
use Symplify\PHP7_Sculpin\Renderable\File\AbstractFile;
15
16
final class MarkdownDecorator implements DecoratorInterface
17
{
18
    /**
19
     * @var MarkdownExtra
20
     */
21
    private $markdownExtra;
22
23 8
    public function __construct(MarkdownExtra $markdown)
24
    {
25 8
        $this->markdownExtra = $markdown;
26 8
    }
27
28 5
    public function decorateFile(AbstractFile $file)
29
    {
30
        // skip due to HTML content incompatibility
31 5
        if ($file->getExtension() !== 'md') {
32 2
            return;
33
        }
34
35 3
        $htmlContent = $this->markdownExtra->transform($file->getContent());
36 3
        $file->changeContent($htmlContent);
37 3
    }
38
}
39