HandlebarsProfileExtension::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
7
namespace JaySDe\HandlebarsBundle;
8
9
10
use Symfony\Component\Stopwatch\Stopwatch;
11
12
class HandlebarsProfileExtension
13
{
14
    private $actives = array();
15
    private $stopwatch;
16
    private $events;
17
18 4
    public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch = null)
19
    {
20 4
        $this->actives[] = $profile;
21
22 4
        $this->stopwatch = $stopwatch;
23 4
        $this->events = new \SplObjectStorage();
24 4
    }
25
26 3
    public function enter(\Twig_Profiler_Profile $profile)
27
    {
28 3
        if ($this->stopwatch && $profile->isTemplate()) {
29 1
            $this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
30
        }
31
32 3
        $this->actives[0]->addProfile($profile);
33 3
        array_unshift($this->actives, $profile);
34 3
    }
35
36 3
    public function leave(\Twig_Profiler_Profile $profile)
37
    {
38 3
        $profile->leave();
39 3
        array_shift($this->actives);
40
41 3
        if (1 === count($this->actives)) {
42 3
            $this->actives[0]->leave();
43
        }
44 3
        if ($this->stopwatch && $profile->isTemplate()) {
45 1
            $this->events[$profile]->stop();
46 1
            unset($this->events[$profile]);
47
        }
48 3
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function getName()
54
    {
55 1
        return 'profiler';
56
    }
57
}
58