Completed
Branch V3 (ec4077)
by PastisD
11:29 queued 09:28
created

DefaultController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 121
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
D indexAction() 0 115 12
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Symfony\Component\Routing\Annotation\Route;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Request;
8
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
9
10
class DefaultController extends Controller
11
{
12
    /**
13
     * @Route("/", name="homepage")
14
     */
15
    public function indexAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
    {
17
        $pfc_test = null;
0 ignored issues
show
Unused Code introduced by
$pfc_test 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...
18
19
        $cache = $this->get('phpfastcache')->get('filecache');
20
        $cache2 = $this->get('phpfastcache')->get('memcachecache');
21
        $cache3 = $this->get('phpfastcache')->get('ssdbcache');
22
        $cache4 = $this->get('phpfastcache')->get('sqlitecache');
23
        $cache5 = $this->get('phpfastcache')->get('rediscache');
24
        $cache6 = $this->get('phpfastcache')->get('mongodbcache');
25
        $cache7 = $this->get('phpfastcache')->get('couchbasecache');
26
        $cache8 = $this->get('phpfastcache')->get('leveldbcache');
27
28
        /**
29
         * Xcache and APC cannot coexists
30
         */
31
        try{
32
            $cache9 = $this->get('phpfastcache')->get('apccache');
33
            $cache10 = $this->get('phpfastcache')->get('apcucache');
34
        }catch(PhpfastcacheDriverCheckException $e){
35
            $cache11 = $this->get('phpfastcache')->get('xcachecache');
36
        }
37
38
        $cache12 = $this->get('phpfastcache')->get('devnullcache');
39
40
41
        $item = $cache->getItem('test');
42
        $item1 = $cache->getItem('test2');
43
        $item2 = $cache2->getItem('test');
44
        $item3 = $cache3->getItem('test');
45
        $item4 = $cache4->getItem('test');
46
        $item5 = $cache5->getItem('test');
47
        $item6 = $cache6->getItem('test');
48
        $item7 = $cache7->getItem('test');
49
        $item8 = $cache7->getItem('test2');
50
        $item9 = $cache8->getItem('test2');
51
52
        if(isset($cache9) && isset($cache10))
53
        {
54
            $item10 = $cache9->getItem('test2');
55
            $item11 = $cache10->getItem('test2');
56
        }
57
58
        if(isset($cache11))
59
        {
60
            $item12 = $cache11->getItem('test2');
61
        }
62
63
        $item13 = $cache12->getItem('test2');
64
65
66
67
        if ($item->isHit()) {
68
            $pfc_test = $item->get();
69
        } else {
70
71
            $item->set('Loaded from cache')->expiresAfter(10);
72
            $item1->set('Loaded from cache2')->expiresAfter(10);
73
            $item2->set('Loaded from cache +' . str_repeat('*', rand(1000, 5000)))->expiresAfter(10);
74
            $item3->set('Loaded from cache +' . str_repeat('+', rand(1000, 5000)))->expiresAfter(10);
75
            $item4->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
76
            $item5->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
77
            $item6->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
78
            $item7->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
79
            $item8->set('Loaded from cache2')->expiresAfter(10);
80
            $item9->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
81
82
            if(isset($item10) && isset($item11))
83
            {
84
                $item10->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
85
                $item11->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
86
            }
87
88
            if(isset($item12))
89
            {
90
                $item12->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
91
            }
92
93
            $item13->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10);
94
95
96
            $cache->save($item);
97
            $cache->save($item1);
98
            $cache2->save($item2);
99
            $cache3->save($item3);
100
            $cache4->save($item4);
101
            $cache5->save($item5);
102
            $cache6->save($item6);
103
            $cache7->save($item7);
104
            $cache7->save($item8);
105
            $cache8->save($item9);
106
107
            if(isset($cache9) && isset($cache10))
108
            {
109
                $cache9->save($item10);
0 ignored issues
show
Bug introduced by
The variable $item10 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
110
                $cache10->save($item11);
0 ignored issues
show
Bug introduced by
The variable $item11 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
111
            }
112
113
            if(isset($cache11))
114
            {
115
                $cache11->save($item12);
0 ignored issues
show
Bug introduced by
The variable $item12 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
116
            }
117
118
            $cache12->save($item13);
119
120
121
            $pfc_test = 'Not loaded from cache';
122
        }
123
124
        // replace this example code with whatever you need
125
        return $this->render('default/index.html.twig', [
126
          'pfc_test' => $pfc_test,
127
          'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
128
        ]);
129
    }
130
}