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

getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 Sculpin\Bundle\MarkdownBundle\EventSubscriber;
13
14
use Sculpin\Bundle\MarkdownBundle\SculpinMarkdownBundle;
15
use Sculpin\Core\Event\SourceSetEvent;
16
use Sculpin\Core\Sculpin;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
final class ConvertToMarkdownBeforeRunEventSubscriber implements EventSubscriberInterface
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $extensions = ['md', 'markdown'];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public static function getSubscribedEvents() : array
30
    {
31
        return [
32
            Sculpin::EVENT_BEFORE_RUN => 'beforeRun',
33
        ];
34
    }
35
36
    public function beforeRun(SourceSetEvent $sourceSetEvent)
37
    {
38
        foreach ($sourceSetEvent->updatedSources() as $source) {
39
            foreach ($this->extensions as $extension) {
40
                if (fnmatch("*.{$extension}", $source->filename())) {
41
                    $source->data()->append('converters', SculpinMarkdownBundle::CONVERTER_NAME);
42
                    break;
43
                }
44
            }
45
        }
46
    }
47
}
48