FakeHook   A
last analyzed

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
 * 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