Completed
Pull Request — master (#11)
by Tomáš
04:45 queued 25s
created

MarkdownConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 51
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A convert() 0 8 1
A convertSource() 0 18 2
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symplify\PHP7_Sculpin\Markdown;
13
14
use Michelf\MarkdownExtra;
15
use Symplify\PHP7_Sculpin\Converter\SourceConverterContext;
16
use Symplify\PHP7_Sculpin\Event\ConvertEvent;
17
use Symplify\PHP7_Sculpin\Event\SculpinEvents;
18
use Symplify\PHP7_Sculpin\Source\SourceInterface;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
use Symplify\PHP7_Sculpin\TwigBundle\SculpinTwigBundle;
21
22
final class MarkdownConverter
23
{
24
    /**
25
     * @var string
26
     */
27
    const NAME = 'markdown';
28
29
    /**
30
     * @var EventDispatcherInterface
31
     */
32
    private $eventDispatcher;
33
34
    /**
35
     * @var MarkdownExtra
36
     */
37
    private $markdown;
38
39
    public function __construct(EventDispatcherInterface $eventDispatcher, MarkdownExtra $markdown)
40
    {
41
        $this->eventDispatcher = $eventDispatcher;
42
        $this->markdown = $markdown;
43
    }
44
45
    public function convert(SourceConverterContext $converterContext)
46
    {
47
        $converterContext->setContent(
48
            $this->markdown->transform(
49
                $converterContext->content()
50
            )
51
        );
52
    }
53
54
    public function convertSource(SourceInterface $source)
55
    {
56
        if (!fnmatch("*.md", $source->filename())) {
57
            return;
58
        }
59
60
        $this->eventDispatcher->dispatch(
61
            SculpinEvents::BEFORE_CONVERT,
62
            new ConvertEvent($source, MarkdownConverter::NAME, SculpinTwigBundle::FORMATTER_NAME)
63
        );
64
65
        $this->convert(new SourceConverterContext($source));
66
67
        $this->eventDispatcher->dispatch(
68
            SculpinEvents::AFTER_CONVERT,
69
            new ConvertEvent($source, MarkdownConverter::NAME, SculpinTwigBundle::FORMATTER_NAME)
70
        );
71
    }
72
}
73