Completed
Pull Request — master (#9)
by Tomáš
07:14 queued 04:10
created

CleanCacheBeforeRunSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A beforeRun() 0 6 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\TwigBundle\EventSubscriber;
13
14
use Symplify\PHP7_Sculpin\Bundle\TwigBundle\Twig\FlexibleExtensionFilesystemLoader;
15
use Symplify\PHP7_Sculpin\Core\Event\SculpinEvents;
16
use Symplify\PHP7_Sculpin\Core\Event\SourceSetEvent;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
final class CleanCacheBeforeRunSubscriber implements EventSubscriberInterface
20
{
21
    /**
22
     * @var FlexibleExtensionFilesystemLoader
23
     */
24
    private $flexibleExtensionFilesystemLoader;
25
26
    public function __construct(FlexibleExtensionFilesystemLoader $flexibleExtensionFilesystemLoader)
27
    {
28
        $this->flexibleExtensionFilesystemLoader = $flexibleExtensionFilesystemLoader;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public static function getSubscribedEvents() : array
35
    {
36
        return [
37
            SculpinEvents::EVENT_BEFORE_RUN => 'beforeRun',
38
        ];
39
    }
40
41
    public function beforeRun(SourceSetEvent $sourceSetEvent)
42
    {
43
        if ($sourceSetEvent->sourceSet()->newSources()) {
44
            $this->flexibleExtensionFilesystemLoader->clean();
45
        }
46
    }
47
}
48