Completed
Pull Request — master (#11)
by Tomáš
04:15
created

ConverterManager::converter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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\Converter;
13
14
use Symplify\PHP7_Sculpin\Event\ConvertEvent;
15
use Symplify\PHP7_Sculpin\Event\SculpinEvents;
16
use Symplify\PHP7_Sculpin\Formatter\FormatterManager;
17
use Symplify\PHP7_Sculpin\MarkdownBundle\MarkdownConverter;
18
use Symplify\PHP7_Sculpin\Source\SourceInterface;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
21
final class ConverterManager
22
{
23
    /**
24
     * @var EventDispatcherInterface
25
     */
26
    private $eventDispatcher;
27
28
    /**
29
     * @var FormatterManager
30
     */
31
    private $formatterManager;
32
33
    /**
34
     * @var MarkdownConverter
35
     */
36
    private $markdownConverter;
37
38
    public function __construct(EventDispatcherInterface $eventDispatcher, FormatterManager $formatterManager, MarkdownConverter $markdownConverter)
39
    {
40
        $this->formatterManager = $formatterManager;
41
        $this->eventDispatcher = $eventDispatcher;
42
        $this->markdownConverter = $markdownConverter;
43
    }
44
45
//    public function registerConverter(string $name, ConverterInterface $converter)
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...
46
//    {
47
//        $this->converters[$name] = $converter;
48
//    }
49
50
//    private function converter(string $name) : ConverterInterface
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
51
//    {
52
//        return $this->converters[$name];
53
//    }
54
55
    public function convertSource(SourceInterface $source)
56
    {
57
        $converters = $source->data()->get('converters');
58
        if (!$converters || !is_array($converters)) {
59
            return;
60
        }
61
62
        foreach ($converters as $converter) {
63
            $this->eventDispatcher->dispatch(
64
                SculpinEvents::BEFORE_CONVERT,
65
                new ConvertEvent($source, $converter, $this->formatterManager->defaultFormatter())
66
            );
67
68
            $this->markdownConverter->convert(new SourceConverterContext($source));
69
70
            $this->eventDispatcher->dispatch(
71
                SculpinEvents::AFTER_CONVERT,
72
                new ConvertEvent($source, $converter, $this->formatterManager->defaultFormatter())
73
            );
74
        }
75
    }
76
}
77