Completed
Push — master ( 91bd08...d24b22 )
by Tomáš
11s
created

ConvertToMarkdownBeforeRunEventSubscriber   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 29
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A beforeRun() 0 11 4
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\Bundle\MarkdownBundle\EventSubscriber;
13
14
use Symplify\PHP7_Sculpin\Bundle\MarkdownBundle\SculpinMarkdownBundle;
15
use Symplify\PHP7_Sculpin\Core\Event\SculpinEvents;
16
use Symplify\PHP7_Sculpin\Core\Event\SourceSetEvent;
17
use Symplify\PHP7_Sculpin\Core\Sculpin;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
final class ConvertToMarkdownBeforeRunEventSubscriber implements EventSubscriberInterface
21
{
22
    /**
23
     * @var string[]
24
     */
25
    private $extensions = ['md', 'markdown'];
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public static function getSubscribedEvents() : array
31
    {
32
        return [
33
            SculpinEvents::EVENT_BEFORE_RUN => 'beforeRun',
34
        ];
35
    }
36
37
    public function beforeRun(SourceSetEvent $sourceSetEvent)
38
    {
39
        foreach ($sourceSetEvent->updatedSources() as $source) {
40
            foreach ($this->extensions as $extension) {
41
                if (fnmatch("*.{$extension}", $source->filename())) {
42
                    $source->data()->append('converters', SculpinMarkdownBundle::CONVERTER_NAME);
43
                    break;
44
                }
45
            }
46
        }
47
    }
48
}
49