Completed
Push — master ( 91bd08...d24b22 )
by Tomáš
11s
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 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