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

AppExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 5
c 3
b 0
f 2
lcom 0
cbo 2
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 8 1
A getTime() 0 11 2
A getName() 0 4 1
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