Passed
Push — master ( 670c76...614a5f )
by Gabor
06:21
created

WebHemiTwigExtension::getStat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Adapter\Renderer\Twig;
15
16
use Twig_Extension;
17
use Twig_SimpleFunction;
18
19
/**
20
 * Class WebHemiTwigExtension
21
 */
22
class WebHemiTwigExtension extends Twig_Extension
23
{
24
    /** @var string */
25
    private $viewPath;
26
27
    /**
28
     * WebHemiTwigExtension constructor.
29
     *
30
     * @param string $viewPath
31
     */
32 6
    public function __construct(string $viewPath)
33
    {
34 6
        $this->viewPath = $viewPath;
35 6
    }
36
37
    /**
38
     * Returns extension functions.
39
     *
40
     * @return array<Twig_SimpleFunction)
0 ignored issues
show
Documentation introduced by
The doc-type array<Twig_SimpleFunction) could not be parsed: Expected ">" at position 3, but found ")". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
41
     */
42 1
    public function getFunctions() : array
43
    {
44
        return [
45 1
            new Twig_SimpleFunction('defined', array($this, 'isDefined')),
46 1
            new Twig_SimpleFunction('getStat', array($this, 'getStat')),
47
        ];
48
    }
49
50
    /**
51
     * Checks if a file exists on the view path.
52
     *
53
     * @param string $fileName
54
     * @return bool
55
     */
56
    public function isDefined(string $fileName) : bool
57
    {
58
        $fileName = str_replace('@Theme', $this->viewPath, $fileName);
59
        return file_exists($fileName);
60
    }
61
62
    /**
63
     * Returns render statistics.
64
     *
65
     * @return array
66
     */
67
    public function getStat() : array
68
    {
69
        return render_stat();
70
    }
71
}
72