This foreach statement is empty and can be removed.
This check looks for foreach loops that have no statements or where all statements
have been commented out. This may be the result of changes for debugging or the code
may simply be obsolete.
Consider removing the loop.
Loading history...
21
22
}
23
}
24
25
// Using a players course handicap which is a whole number
26
1
public function getMaxAllowableHoleScore($par, $courseHandicap)
27
{
28
switch(true) {
29
1
case ($courseHandicap <= 9):
30
1
$maxScore = $par + 2;
31
1
break;
32
1
case (($courseHandicap > 9) && ($courseHandicap < 20)): //10-19
33
1
$maxScore = 7;
34
1
break;
35
1
case (($courseHandicap >= 20) && ($courseHandicap < 30))://20-29
36
1
$maxScore = 8;
37
1
break;
38
1
case (($courseHandicap >= 30) && ($courseHandicap < 40))://30-39
The variable $maxScore 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:
functionmyFunction($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
Check for existence of the variable explicitly:
functionmyFunction($a){switch($a){case'foo':$x=1;break;case'bar':$x=2;break;}if(isset($x)){// Make sure it's always set.echo$x;}}
Define a default value for the variable:
functionmyFunction($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;}
Add a value for the missing path:
functionmyFunction($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;}
This check marks private properties in classes that are never used. Those properties can be removed.