Completed
Push — master ( a4551f...f2d5c9 )
by Paweł
19:10 queued 05:45
created

NotificationWidgetExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFunctions() 0 13 1
A renderWidget() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\AdminBundle\Twig;
13
14
/**
15
 * @author Jan Góralski <[email protected]>
16
 */
17
final class NotificationWidgetExtension extends \Twig_Extension
18
{
19
    /**
20
     * @var bool
21
     */
22
    private $areNotificationsEnabled;
23
24
    /**
25
     * @var int
26
     */
27
    private $checkFrequency;
28
29
    /**
30
     * @param bool $areNotificationsEnabled
31
     * @param int $checkFrequency
32
     */
33
    public function __construct($areNotificationsEnabled, $checkFrequency)
34
    {
35
        $this->areNotificationsEnabled = $areNotificationsEnabled;
36
        $this->checkFrequency = $checkFrequency;
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getFunctions()
43
    {
44
        return [
45
            new \Twig_SimpleFunction(
46
                'sylius_render_notifications_widget',
47
                [$this, 'renderWidget'],
48
                [
49
                    'needs_environment' => true,
50
                    'is_safe' => ['html'],
51
                ]
52
            ),
53
        ];
54
    }
55
56
    /**
57
     * @param \Twig_Environment $environment
58
     *
59
     * @return string
60
     */
61
    public function renderWidget(\Twig_Environment $environment)
62
    {
63
        if (!$this->areNotificationsEnabled) {
64
            return '';
65
        }
66
67
        return $environment->render('@SyliusAdmin/_notification.html.twig', [
68
            'frequency' => $this->checkFrequency,
69
        ]);
70
    }
71
}
72