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

AppExtension::getTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 11
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
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