Completed
Push — master ( 56ab9a...ae2e93 )
by Michael
02:55
created

CourseStatisticsEloquent::averageScore()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php namespace GolfLeague\Statistics\Course;
2
3
use \Round;
4
5
class CourseStatisticsEloquent implements CourseStatistics
6
{
7
    private $date1 = '-01-01';
8
    private $date2 = '-12-31';
9
10 View Code Duplication
    public function averageScore($courseId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
        $rounds = Round::where('course_id', '=', $courseId)->get();
13
        $scores = $rounds->map(function($round)
14
        {
15
            return $round->score;
16
        });
17
        if($rounds->count() > 0) {
18
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
19
        } else {
20
            return $rounds;
21
        }
22
    }
23 View Code Duplication
    public function averageScoreByPlayer($courseId, $playerId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $rounds = Round::where('course_id', '=', $courseId)
26
            ->where('player_id', '=', $playerId)
27
            ->get();
28
        $scores = $rounds->map(function($round)
29
        {
30
            return $round->score;
31
        });
32
        if($rounds->count() > 0) {
33
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
34
        } else {
35
            return $rounds;
36
        }
37
    }
38 View Code Duplication
    public function averageScoreByYear($courseId, $year)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $rounds = Round::where('course_id', '=', $courseId)
41
            ->where('date', '>=', $year . $this->date1)
42
            ->where('date', '<=', $year . $this->date2)
43
            ->get();
44
        $scores = $rounds->map(function($round)
45
        {
46
            return $round->score;
47
        });
48
49
        if($rounds->count() > 0) {
50
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
51
        } else {
52
            return $rounds;
53
        }
54
    }
55 View Code Duplication
    public function averageScoreByPlayerAndYear($courseId, $playerId, $year)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $rounds = Round::where('course_id', '=', $courseId)
58
            ->where('player_id', '=', $playerId)
59
            ->where('date', '>=', $year . $this->date1)
60
            ->where('date', '<=', $year . $this->date2)
61
            ->get();
62
        $scores = $rounds->map(function($round)
63
        {
64
            return $round->score;
65
        });
66
67
        if($rounds->count() > 0) {
68
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
69
        } else {
70
            return $rounds;
71
        }
72
    }
73
74
}