Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 3 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | 1 | public function adjustScores(array $holeScores, $courseHandicap) |
|
23 | { |
||
24 | 1 | foreach($holeScores as $key => $holeScore){ |
|
25 | 1 | $maxHoleScore = $this->getMaxAllowableHoleScore($holeScore['par'],$courseHandicap); |
|
26 | |||
27 | 1 | if($holeScore['score'] >= $maxHoleScore ){ |
|
28 | 1 | $this->escResultArray[] = $maxHoleScore; |
|
29 | } else { |
||
30 | 1 | $this->escResultArray[] = $holeScore['score']; |
|
31 | } |
||
32 | } |
||
33 | |||
34 | 1 | return $this->escResultArray; |
|
35 | } |
||
36 | |||
64 |
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: