FakeHook::getFunctions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\CoreBundle\Twig;
14
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
17
class FakeHook extends \Twig_Extension
18
{
19
    /**
20
     * @var bool
21
     */
22
    private $hookAlreadyRegistred = null;
23
24
    /**
25
     * @var string
26
     */
27
    private $env;
28
29
    public function __construct(ContainerInterface $container, string $env)
30
    {
31
        $this->hookAlreadyRegistred = $container->get('twig')->hasExtension('blast_hook');
32
        $this->env = $env;
33
    }
34
35
    public function getFunctions()
36
    {
37
        $functions = [];
38
        if ($this->hookAlreadyRegistred === false) {
39
            $functions[] = new \Twig_SimpleFunction('blast_hook', array($this, 'displayFakeHook'), ['is_safe' => ['html']]);
40
        }
41
42
        return $functions;
43
    }
44
45
    public function displayFakeHook()
46
    {
47
        return $this->env !== 'prod' ? '<!-- Blast hook -->' : '';
48
    }
49
}
50