Completed
Push — upgrade ( c4e463 )
by Kamil
22:47
created

NotificationWidgetExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

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)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $areNotificationsEnabled exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
34
    {
35
        $this->areNotificationsEnabled = $areNotificationsEnabled;
36
        $this->checkFrequency = $checkFrequency;
37
    }
38
39
    /**
40
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Twig_SimpleFunction[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
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