PlayerStatisticsEloquent   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 92
Duplicated Lines 17.39 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 31
c 1
b 0
f 0
lcom 0
cbo 1
dl 16
loc 92
rs 9.8

26 Methods

Rating   Name   Duplication   Size   Complexity  
A matchesHandicap() 0 1 1
A scoringAverage() 16 16 2
A scoringAverageByYear() 0 22 2
A scoringAverageMatchesByYear() 0 1 1
A handicapRounds() 0 1 1
A scoringAverageCourse() 0 1 1
A scoringAverageCourseByYear() 0 1 1
A scoringAverageCourseMatchesByYear() 0 1 1
A totalEagles() 0 1 1
A eaglesByYear() 0 1 1
A eaglesMatchesByYear() 0 1 1
A totalBirdies() 0 1 1
A birdiesByYear() 0 17 4
A birdiesMatchesByYear() 0 1 1
A totalPars() 0 1 1
A parsByYear() 0 1 1
A parsMatchesByYear() 0 1 1
A totalbogeys() 0 1 1
A bogeysByYear() 0 1 1
A bogeysMatchesByYear() 0 1 1
A totalDoubles() 0 1 1
A doublesByYear() 0 1 1
A doublesMatchesByYear() 0 1 1
A totalOthers() 0 1 1
A othersByYear() 0 1 1
A othersMatchesByYear() 0 1 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace GolfLeague\Statistics\Player;
2
3
use Carbon\Carbon;
4
use \Round;
5
use \Player;
6
use \Skin;
7
use \Netwinner;
8
use \Holescore;
9
10
11
class PlayerStatisticsEloquent implements PlayerStatistics
12
{
13
    private $date1 = '-01-01';
0 ignored issues
show
Unused Code introduced by
The property $date1 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...
14
    private $date2 = '-12-31';
0 ignored issues
show
Unused Code introduced by
The property $date2 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
    public function matchesHandicap($playerId){}
17 View Code Duplication
    public function scoringAverage($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...
18
    {
19
        $today = Carbon::today()->toDateString();
20
        $rounds = Round::where('player_id', '=', $playerId)
21
            ->where('date', '<', $today)
22
            ->get();
23
        $scores = $rounds->map(function($round)
24
        {
25
            return $round->score;
26
        });
27
        if($rounds->count() > 0) {
28
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
29
        } else {
30
            return $rounds;
31
        }
32
    }
33
    public function scoringAverageByYear($playerId, $year)
34
    {
35
        $date1 = $year . '-01-01';
36
        $date2 = $year . '-12-31';
37
38
39
        $rounds = Round::where('player_id', '=', $playerId)
40
            ->where('date', '>=', $date1)
41
            ->where('date', '<=', $date2)
42
            ->get();
43
        $scores = $rounds->map(function($round)
44
        {
45
            return $round->score;
46
        });
47
        if($rounds->count() > 0) {
48
            return round(array_sum($scores->toArray())/($rounds->count()), 2);
49
        } else {
50
            return $rounds;
51
        }
52
53
54
    }
55
    public function scoringAverageMatchesByYear($year){}
56
    public function handicapRounds($playerId){}
57
58
    public function scoringAverageCourse($course){}
59
    public function scoringAverageCourseByYear($course, $year){}
60
    public function scoringAverageCourseMatchesByYear($course, $year){}
61
62
    public function totalEagles(){}
63
    public function eaglesByYear($year){}
64
    public function eaglesMatchesByYear($year){}
65
66
    public function totalBirdies($playerId){}
67
    public function birdiesByYear($playerId, $year)
68
    {
69
        $year = $year . '-01-01';
70
        $holescores = Holescore::with('round.player','hole')
71
            ->where('created_at', '>', $year)
72
            ->get();
73
        $allBirdies = array();
74
        foreach($holescores as $key => $holescore) {
75
            if($holescore['round']['match_id'] != null){
76
                if( ($holescore['hole']['par'] - $holescore['score']) === 1) {
77
                    $allBirdies[]= $holescore['round']['player']['id'];
78
                }
79
            }
80
        }
81
        return count(array_keys($allBirdies, $playerId));
82
83
    }
84
    public function birdiesMatchesByYear($year){}
85
86
    public function totalPars(){}
87
    public function parsByYear($year){}
88
    public function parsMatchesByYear($year){}
89
90
    public function totalbogeys(){}
91
    public function bogeysByYear($year){}
92
    public function bogeysMatchesByYear($year){}
93
94
    public function totalDoubles(){}
95
    public function doublesByYear($year){}
96
    public function doublesMatchesByYear($year){}
97
98
    public function totalOthers(){}
99
    public function othersByYear($year){}
100
    public function othersMatchesByYear($year){}
101
102
}