Completed
Push — wip-platform ( 03cba6...2999ab )
by
unknown
05:53 queued 02:49
created

FakeHook   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 33
rs 10
c 1
b 1
f 0

3 Methods

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