| Conditions | 2 |
| Paths | 2 |
| Total Lines | 13 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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); |
||
|
|
|||
| 47 | } |
||
| 48 | |||
| 54 |
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:
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
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: