Completed
Push — master ( 2abc3b...5aa123 )
by Alexis
16:40
created

MenuExtension::get()   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 2
1
<?php
2
3
namespace Alpixel\Bundle\MenuBundle\Twig;
4
5
use Alpixel\Bundle\MenuBundle\Builder\MenuBuilder;
6
use Twig_Environment;
7
use Twig_Extension;
8
use Twig_SimpleFunction;
9
use UnexpectedValueException;
10
11
class MenuExtension extends Twig_Extension
12
{
13
    protected $builder;
14
15
    function __construct(MenuBuilder $builder)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
    {
17
        $this->builder = $builder;
18
    }
19
20
    public function getFunctions()
21
    {
22
        return array(
23
            new Twig_SimpleFunction('alpixel_get_menu', array($this, 'get')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
            new Twig_SimpleFunction('alpixel_render_menu', array($this, 'render'), array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
25
                'is_safe' => array('html'),
26
                'needs_environment' => true,
27
            )),
28
        );
29
    }
30
31
    public function get($machineName, $locale = null)
32
    {
33
        return $this->builder->createKnpMenu($machineName, $locale);
34
    }
35
36
    public function render(Twig_Environment $twig, $machineName, $locale = null)
37
    {
38
        $menu = $this->get($machineName, $locale);
0 ignored issues
show
Unused Code introduced by
$menu is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
40
        return $twig->render();
0 ignored issues
show
Bug introduced by
The call to render() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
41
    }
42
43
    public function getName()
44
    {
45
        return 'alpixel_menu_bundle_twig_menu_extension';
46
    }
47
}
48