Completed
Push — Recipes ( 98dbcc...cc19df )
by Laurent
02:38
created

LoadGroupData::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * LoadGroupData Données Group de l'application GLSR.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: <git_id>
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\DataFixtures\ORM;
16
17
use Doctrine\Common\DataFixtures\AbstractFixture;
18
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use AppBundle\Entity\Staff\Group;
21
22
/**
23
 * LoadGroup Data.
24
 *
25
 * @category DataFixtures
26
 */
27
class LoadGroupData extends AbstractFixture implements OrderedFixtureInterface
28
{
29
    private $datas = [
30
        ['admin', 'ROLE_SUPER_ADMIN'],
31
        ['assistant','ROLE_ADMIN'],
32
        ['user', 'ROLE_USER']
33
    ];
34
35
    public function load(ObjectManager $manager)
36
    {
37
        foreach ($this->datas as $data) {
38
            $groupAdmin = new Group($data[0], [$data[1]]);
39
            $groupAdmin->setName($data[0]);
40
            $groupAdmin->setRoles([$data[1]]);
41
42
            $manager->persist($groupAdmin);
43
        }
44
        $manager->flush();
45
46
        $this->addReference('admin-group', $groupAdmin);
0 ignored issues
show
Bug introduced by
The variable $groupAdmin 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...
47
    }
48
49
    public function getOrder()
50
    {
51
        return 1;
52
    }
53
}
54