Completed
Push — master ( 6d332f...fd24cd )
by Mikhail
04:15
created

TimedTwigDecorator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * @author Mikhail Dolgov <[email protected]>
4
 * @date   09.03.2016 15:28
5
 */
6
7
namespace SilexPinbaProvider\Twig;
8
9
10
use Intaro\PinbaBundle\Stopwatch\Stopwatch;
11
12
class TimedTwigDecorator extends \Twig_Environment{
13
    /**
14
     * @var \Twig_Environment
15
     */
16
    private $environment;
17
    /**
18
     * @var Stopwatch
19
     */
20
    private $stopwatch;
21
22
    /**
23
     * @param \Twig_Environment $environment
24
     * @param Stopwatch         $stopwatch
25
     */
26
    public function __construct(\Twig_Environment $environment, Stopwatch $stopwatch)
27
    {
28
        $this->environment = $environment;
29
        $this->stopwatch   = $stopwatch;
30
    }
31
32
    /**
33
     * Renders a template.
34
     *
35
     * @param string $name    The template name
36
     * @param array  $context An array of parameters to pass to the template
37
     *
38
     * @return string The rendered template
39
     *
40
     * @throws \Twig_Error_Loader  When the template cannot be found
41
     * @throws \Twig_Error_Syntax  When an error occurred during compilation
42
     * @throws \Twig_Error_Runtime When an error occurred during rendering
43
     */
44
    public function render($name, array $context = array())
45
    {
46
        $e = $this->stopwatch->start(array(
47
            'server'        => 'localhost',
48
            'group'         => 'twig::render',
49
            'twig_template' => (string)$name,
50
        ));
51
52
        $ret = $this->environment->render($name, $context);
53
54
        $e->stop();
55
56
        return $ret;
57
58
    }
59
60
    /**
61
     * is triggered when invoking inaccessible methods in an object context.
62
     *
63
     * @param $name      string
64
     * @param $arguments array
65
     * @return mixed
66
     * @link http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
67
     */
68
    function __call($name, $arguments)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
69
    {
70
        return $this->environment->$name($arguments);
71
    }
72
73
74
}