Completed
Push — master ( 20de55...87a0a5 )
by Tomas Norre
05:25
created

ScoreService::calculateScoreToPar()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
ccs 8
cts 8
cp 1
cc 3
eloc 8
nc 3
nop 2
crap 3
1
<?php
2
namespace TNM\GolfCourses\Service;
3
4
/**
5
 * Class ScoreService
6
 *
7
 * @package TNM\GolfCourses\Service
8
 */
9
class ScoreService
10
{
11
12
    /**
13
     * @return int
14
     */
15 3
    public function calculateScoreToPar($coursePar, $strokes)
16
    {
17 3
        if ($coursePar === $strokes) {
18 1
            return 'par';
19
        }
20
21 2
        $prefix = '';
22 2
        $score = $strokes - $coursePar;
23
24 2
        if ($score > 0) {
25 1
            $prefix = '+';
26
        }
27 2
        return $prefix . $score;
28
    }
29
30
}