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
|
|||
51 | $this->twig->invalidateLoadedTemplates(); |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 |
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.