Completed
Pull Request — master (#11)
by Tomáš
03:09
created

MarkdownConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 8 1
A convertSource() 0 18 2
A __construct() 0 5 1
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\Event\ConvertEvent;
16
use Symplify\PHP7_Sculpin\Event\SculpinEvents;
17
use Symplify\PHP7_Sculpin\Source\SourceInterface;
18
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19
use Symplify\PHP7_Sculpin\TwigBundle\SculpinTwigBundle;
20
21
final class MarkdownConverter
22
{
23
    /**
24
     * @var string
25
     */
26
    const NAME = 'markdown';
27
28
    /**
29
     * @var EventDispatcherInterface
30
     */
31
    private $eventDispatcher;
32
33
    /**
34
     * @var MarkdownExtra
35
     */
36
    private $markdown;
37
38
    public function __construct(EventDispatcherInterface $eventDispatcher, MarkdownExtra $markdown)
39
    {
40
        $this->eventDispatcher = $eventDispatcher;
41
        $this->markdown = $markdown;
42
    }
43
44
//    public function convert(SourceConverterContext $converterContext)
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
    public function convert(SourceInterface $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($source);
66
67
        $this->eventDispatcher->dispatch(
68
            SculpinEvents::AFTER_CONVERT,
69
            new ConvertEvent($source, MarkdownConverter::NAME, SculpinTwigBundle::FORMATTER_NAME)
70
        );
71
    }
72
}
73