Completed
Push — master ( 8c5bee...33e30f )
by
unknown
06:57 queued 04:51
created

src/Sculpin/Bundle/TwigBundle/TemplateResetter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is a part of Sculpin.
7
 *
8
 * (c) Dragonfly Development Inc.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sculpin\Bundle\TwigBundle;
15
16
use Sculpin\Core\Event\SourceSetEvent;
17
use Sculpin\Core\Sculpin;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * @author Beau Simensen <[email protected]>
22
 */
23
final class TemplateResetter implements EventSubscriberInterface
24
{
25
    private $twig;
26
27
    public function __construct(Environment $twig)
28
    {
29
        $this->twig = $twig;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public static function getSubscribedEvents(): array
36
    {
37
        return [
38
            Sculpin::EVENT_BEFORE_RUN => 'beforeRun',
39
        ];
40
    }
41
42
    /**
43
     * Invalidate templates if any of the sources have been updated.
44
     *
45
     * @param SourceSetEvent $sourceSetEvent Source Set Event
46
     */
47
    public function beforeRun(SourceSetEvent $sourceSetEvent): void
48
    {
49
        $updated = $sourceSetEvent->updatedSources();
50
        if ($updated) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $updated of type Sculpin\Core\Source\SourceInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
51
            $this->twig->invalidateLoadedTemplates();
52
        }
53
    }
54
}
55