Completed
Push — master ( d95d7a...9b093a )
by Andrea
52:34 queued 49:57
created

PermessiTwigExtension   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 62
ccs 8
cts 28
cp 0.2857
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getControllerName() 0 8 1
B singoloPermesso() 0 23 5
A getFunctions() 0 6 1
A getFilters() 0 6 1
1
<?php
2
3
namespace Fi\CoreBundle\Twig\Extension;
4
5
class PermessiTwigExtension extends \Twig_Extension
6
{
7
8
    protected $requeststack;
9
    protected $container;
10
11 17
    public function __construct($container, $request_stack)
12
    {
13 17
        $this->container = $container;
14 17
        $this->requeststack = $request_stack;
15 17
    }
16
17
    /**
18
     * Get current controller name.
19
     */
20
    public function getControllerName()
21
    {
22
        $pattern = "#Controller\\\([a-zA-Z]*)Controller#";
23
        $matches = array();
24
        preg_match($pattern, $this->requeststack->getCurrentRequest()->get('_controller'), $matches);
25
26
        return $matches[1];
27
    }
28
29 10
    public function getFunctions()
30
    {
31
        return array(
32
                //'permesso' => new \Twig_Function_Method($this, 'controllaPermesso'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33 10
        );
34
    }
35
36 10
    public function getFilters()
37
    {
38
        return array(
39 10
            new \Twig_SimpleFilter('permesso', array($this, 'singoloPermesso')),
40
        );
41
    }
42
43
    public function singoloPermesso($lettera)
44
    {
45
        $gestionepermessi = $this->container->get("ficorebundle.gestionepermessi");
46
47
        $parametri = array();
48
        $parametri['modulo'] = $this->getControllerName();
49
        switch ($lettera) {
50
            case 'c':
51
                return $gestionepermessi->creare($parametri);
52
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
53
            case 'r':
54
                return $gestionepermessi->leggere($parametri);
55
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
56
            case 'u':
57
                return $gestionepermessi->aggiornare($parametri);
58
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
59
            case 'd':
60
                return $gestionepermessi->cancellare($parametri);
61
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
62
            default:
63
                break;
64
        }
65
    }
66
}
67