Completed
Pull Request — master (#33)
by Pavel
03:21
created

AppExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Twig\Extension;
4
5
use AppBundle\Entity\PassModule;
6
use Symfony\Bridge\Doctrine\RegistryInterface;
7
8
/**
9
 * Class AppExtension
10
 * @package AppBundle\Twig\Extension
11
 */
12
class AppExtension extends \Twig_Extension
13
{
14
    /**
15
     * @var RegistryInterface
16
     */
17
    protected $doctrine;
18
19
    /**
20
     * @param RegistryInterface $doctrine
21
     */
22
    public function __construct(RegistryInterface $doctrine)
23
    {
24
        $this->doctrine = $doctrine;
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function getFunctions()
31
    {
32
        return array(
33
            new \Twig_SimpleFunction('showTime',
34
                array($this, 'getTime')
35
            )
36
        );
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getTime($start, $finish)
43
    {
44
        if ($finish === null) {
45
46
            return 'The time is up';
47
        }
48
49
        $diff = date_diff($finish, $start, true);
50
51
        return $diff->format('%I:%S');
52
    }
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName()
57
    {
58
        return 'app.twig.extension';
59
    }
60
}
61