Completed
Push — master ( e64d7a...236403 )
by Michael
03:31
created

EquitableScoreControl   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 84.21%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 35
ccs 16
cts 19
cp 0.8421
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A adjustScores() 0 6 2
B getMaxAllowableHoleScore() 0 20 9
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: michaelschmidt
5
 * Date: 8/17/16
6
 * Time: 9:44 PM
7
 */
8
9
namespace GLsoftware\Golf;
10
11
12
class EquitableScoreControl
13
{
14
    private $escResultArray;
0 ignored issues
show
Unused Code introduced by
The property $escResultArray is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
16
    // expecting an object or array GrossScore
17
    // with par and score for 18 or 9 holes
18
    public function adjustScores(array $scores, $courseHandicap)
0 ignored issues
show
Unused Code introduced by
The parameter $courseHandicap 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...
19
    {
20
        foreach($scores as $score){
0 ignored issues
show
Unused Code introduced by
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
39 1
                $maxScore = 9;
40 1
                break;
41 1
            case ($courseHandicap >= 40):
42 1
                $maxScore = 10;
43
        }
44 1
        return $maxScore;
0 ignored issues
show
Bug introduced by
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:

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...
45
    }
46
}
47