Completed
Push — master ( 70f3fa...318b0d )
by Michael
02:54
created

EquitableScoreControl   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 0
dl 0
loc 54
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A adjustScores() 0 14 3
C getMaxAllowableHoleScore() 0 22 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;
15
16
    /**
17
     *
18
     * @param array $holeScores
19
     * @param $courseHandicap
20
     * @return array
21
     */
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
37
    // Using a players course handicap which is a whole number
38
    /**
39
     * @param $par
40
     * @param $courseHandicap
41
     * @return int
42
     */
43 2
    public function getMaxAllowableHoleScore($par, $courseHandicap)
44
    {
45 2
        $maxScore = $par;
46
47
        switch(true) {
48 2
            case ($courseHandicap <= 9):
49 2
                $maxScore = $par + 2;
50 2
                break;
51 1
            case (($courseHandicap > 9) && ($courseHandicap < 20)): //10-19
52 1
                $maxScore = 7;
53 1
                break;
54 1
            case (($courseHandicap >= 20) && ($courseHandicap < 30))://20-29
55 1
                $maxScore = 8;
56 1
                break;
57 1
            case (($courseHandicap >= 30) && ($courseHandicap < 40))://30-39
58 1
                $maxScore = 9;
59 1
                break;
60 1
            case ($courseHandicap >= 40):
61 1
                $maxScore = 10;
62
        }
63 2
        return $maxScore;
64
    }
65
}
66