LeagueStatisticsEloquent   C
last analyzed

Complexity

Total Complexity 78

Size/Duplication

Total Lines 495
Duplicated Lines 72.73 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 78
c 2
b 1
f 0
lcom 2
cbo 2
dl 360
loc 495
rs 5.4563

27 Methods

Rating   Name   Duplication   Size   Complexity  
A topFiveLowestScores() 0 4 1
A topFiveLowestScoresByYear() 0 14 1
B topFiveScoringAverageByYear() 0 32 4
A mostSkinsByYear() 0 20 3
B totalEagles() 25 25 5
B netScoresByPlayer() 22 37 4
A netScoresByPlayerTop() 0 5 1
B netScoresByPlayerYear() 22 44 4
A netScoresByPlayerTopYear() 0 5 1
A netScoresLeague() 12 12 2
A netScoresLeagueTop() 15 15 3
A netScoresLeagueYear() 11 11 2
A netScoresLeagueTopYear() 15 15 3
A netCumulative() 11 11 2
A netCumulativeTop() 15 15 3
A netCumulativeByPlayer() 16 16 2
A netCumulativeByPlayerTop() 16 16 2
A netCumulativeYear() 11 11 2
A netCumulativeTopYear() 15 15 3
A netCumulativeByPlayerYear() 16 16 2
A netCumulativeByPlayerTopYear() 16 16 2
A topFiveNetScoresByYear() 0 10 1
B totalBirdies() 26 26 5
B totalPars() 24 24 5
B totalBogeys() 24 24 5
B totalDoubles() 24 24 5
B totalOthers() 24 24 5

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like LeagueStatisticsEloquent often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LeagueStatisticsEloquent, and based on these observations, apply Extract Interface, too.

1
<?php namespace GolfLeague\Statistics\League;
2
3
use Illuminate\Support\Collection;
4
use \Round;
5
use \Player;
6
use \Skin;
7
use \Netwinner;
8
use \Holescore;
9
use \Match;
10
use Carbon\Carbon;
11
12
class LeagueStatisticsEloquent implements LeagueStatistics
13
{
14
    public function topFiveLowestScores()
15
    {
16
        return Round::with('player','course')->orderBy('score')->take(5)->get();
17
    }
18
    public function topFiveLowestScoresByYear($year)
19
    {
20
		$today = Carbon::today()->toDateString();
21
		$date1 = $year . '-01-01';
22
        $date2 = $year . '-12-31';
23
        return Round::with('player', 'course')
24
            ->where('match_id', '>', '0')
25
            ->where('date', '>=', $date1)
26
            ->where('date', '<=', $date2)
27
			->where('date', '<=', $today)
28
            ->orderBy('score')
29
            ->take(5)
30
            ->get();
31
    }
32
    public function topFiveScoringAverageByYear($year)
33
    {
34
        //Get players
35
        //For each player where match > 0 select scores and average them
36
        //Store in players array
37
        $date1 = $year . '-01-01';
38
        $date2 = $year . '-12-31';
39
        $players = Player::all();
40
        $average = array();
41
        $i = 0;
42
        foreach($players as $key => $player) {
43
            $rounds = Round::where('match_id', '>', '0')
44
                ->where('player_id', '=', $player->id)
45
				->where('score', '>', '30')
46
                ->where('date', '>=', $date1)
47
                ->where('date', '<=', $date2)
48
                ->get();
49
            $scores = array();
50
			foreach($rounds as $round) {
51
				$scores[] = $round->score;
52
			}
53
            if(count($scores) > 0) {
54
                $average[$i]['average'] = round((array_sum($scores) / count($scores)) ,2);
55
                $average[$i]['player_id'] = $player->id;
56
                $average[$i]['name'] = $player->name;
57
                $average[$i]['rounds'] = count($scores);
58
                $i++;
59
            }
60
        }
61
        array_multisort($average);
62
        return $average;
63
    }
64
    public function topFiveNetScoresByYear($year)
65
    {
66
		$date1 = $year . '-01-01';
67
		$date2 = $year . '-12-31';
68
69
		return Netwinner::with('player','match','match.course')
70
				->where('created_at', '>=', $date1)
71
				->where('created_at', '<=', $date2)
72
				->orderBy('score')->take(5)->get();
73
    }
74
    public function mostSkinsByYear($year)
75
    {
76
        $year = $year . '-01-01';
77
        $players = Player::all();
78
        $i = 0;
79
        $skinsCount = array();
80
        foreach($players as $key => $player) {
81
            $skins = Skin::with('player','level')
82
                ->where('player_id', '=', $player->id)
83
                ->where('created_at', '>', $year)
84
                ->get();
85
            if(count($skins) > 0) {
86
                $skinsCount[$i]['skins'] = $skins->count();
87
                $skinsCount[$i]['name'] = $player->name;
88
                $i++;
89
            }
90
        }
91
        array_multisort($skinsCount, SORT_DESC);
92
        return $skinsCount;
93
    }
94 View Code Duplication
    public function totalEagles($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...
95
		$date1 = $year . '-01-01';
96
		$date2 = $year . '-12-31';
97
		$holescores = Holescore::with('round.player','hole')
98
			->where('created_at', '>=', $date1)
99
			->where('created_at', '<=', $date2)
100
			->get();
101
		$allEagles = array();
102
		foreach($holescores as $key => $holescore) {
103
			if($holescore['round']['match_id'] != null){
104
				if( ($holescore['hole']['par'] - $holescore['score']) === 2) {
105
					$allEagles[]= $holescore['round']['player']['name'];
106
				}
107
			}
108
		}
109
		$i =0;
110
		$newArray = array_count_values($allEagles);
111
		$eagles = array();
112
		foreach ($newArray as $key => $value) {
113
			$eagles[$i]['name'] = $key;
114
			$eagles[$i]['eagles'] =$value;
115
			$i++;
116
		}
117
		return $eagles;
118
	}
119 View Code Duplication
    public function totalBirdies($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...
120
	{
121
		$date1 = $year . '-01-01';
122
		$date2 = $year . '-12-31';
123
		$holescores = Holescore::with('round.player','hole')
124
			->where('created_at', '>=', $date1)
125
			->where('created_at', '<=', $date2)
126
			->get();
127
		$allBirdies = array();
128
		foreach($holescores as $key => $holescore) {
129
			if($holescore['round']['match_id'] != null){
130
				if( ($holescore['hole']['par'] - $holescore['score']) === 1) {
131
						$allBirdies[]= $holescore['round']['player']['name'];
132
				}
133
			}
134
		}
135
		$i =0;
136
		$newArray = array_count_values($allBirdies);
137
			$birds = array();
138
			foreach ($newArray as $key => $value) {
139
				$birds[$i]['name'] = $key;
140
				$birds[$i]['birds'] =$value;
141
				$i++;
142
			}
143
			return $birds;
144
	}
145 View Code Duplication
    public function totalPars($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...
146
	{
147
		$year = $year . '-01-01';
148
		$holescores = Holescore::with('round.player','hole')
149
			->where('created_at', '>', $year)
150
			->get();
151
		$allPars = array();
152
		foreach($holescores as $key => $holescore) {
153
			if($holescore['round']['match_id'] != null){
154
				if( ($holescore['hole']['par'] - $holescore['score']) === 0) {
155
						$allPars[]= $holescore['round']['player']['name'];
156
				}
157
			}
158
		}
159
		$i =0;
160
		$newArray = array_count_values($allPars);
161
			$pars = array();
162
			foreach ($newArray as $key => $value) {
163
				$pars[$i]['name'] = $key;
164
				$pars[$i]['pars'] =$value;
165
				$i++;
166
			}
167
			return $pars;
168
	}
169 View Code Duplication
    public function totalBogeys($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...
170
	{
171
		$year = $year . '-01-01';
172
		$holescores = Holescore::with('round.player','hole')
173
			->where('created_at', '>', $year)
174
			->get();
175
		$allBogeys = array();
176
		foreach($holescores as $key => $holescore) {
177
			if($holescore['round']['match_id'] != null){
178
				if( ($holescore['score'] - $holescore['hole']['par']) === 1) {
179
						$allBogeys[]= $holescore['round']['player']['name'];
180
				}
181
			}
182
		}
183
		$i = 0;
184
		$newArray = array_count_values($allBogeys);
185
		$bogeys = array();
186
			foreach ($newArray as $key => $value) {
187
				$bogeys[$i]['name'] = $key;
188
				$bogeys[$i]['bogeys'] =$value;
189
				$i++;
190
			}
191
		return $bogeys;
192
	}
193 View Code Duplication
    public function totalDoubles($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...
194
	{
195
		$year = $year . '-01-01';
196
		$holescores = Holescore::with('round.player','hole')
197
			->where('created_at', '>', $year)
198
			->get();
199
		$allDoubles = array();
200
		foreach($holescores as $key => $holescore) {
201
			if($holescore['round']['match_id'] != null){
202
				if( ($holescore['score'] - $holescore['hole']['par']) === 2) {
203
						$allDoubles[]= $holescore['round']['player']['name'];
204
				}
205
			}
206
		}
207
		$i = 0;
208
		$newArray = array_count_values($allDoubles);
209
			$doubles = array();
210
			foreach ($newArray as $key => $value) {
211
				$doubles[$i]['name'] = $key;
212
				$doubles[$i]['doubles'] =$value;
213
				$i++;
214
			}
215
		return $doubles;
216
	}
217 View Code Duplication
    public function totalOthers($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...
218
	{
219
		$year = $year . '-01-01';
220
		$holescores = Holescore::with('round.player','hole')
221
			->where('created_at', '>', $year)
222
			->get();
223
		$allOthers = array();
224
		foreach($holescores as $key => $holescore) {
225
			if($holescore['round']['match_id'] != null){
226
				if( ($holescore['score'] - $holescore['hole']['par']) > 2) {
227
					$allOthers[]= $holescore['round']['player']['name'];
228
				}
229
			}
230
		}
231
		$i = 0;
232
		$newArray = array_count_values($allOthers);
233
		$others = array();
234
			foreach ($newArray as $key => $value) {
235
				$others[$i]['name'] = $key;
236
				$others[$i]['others'] =$value;
237
				$i++;
238
			}
239
		return $others;
240
	}
241
242
	public function netScoresByPlayer($playerId)
243
	{
244
		// Get players match scores
245
		$rounds = Round::with('player')
246
			->where('player_id', '=', $playerId)
247
			->whereNotNull('match_id')->get();
248
249
		//for each round get match handicap
250 View Code Duplication
		$rounds->map(function($round)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
251
		{
252
			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id','=', $round->match_id)->get();
253
			foreach($playerMatch as $player){
254
				$handicap = $player['pivot']['handicap'];
255
				$round->handicap = $handicap;
256
			}
257
		});
258
		//Calculate net score using match handicap
259 View Code Duplication
		$rounds->map(function($round)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
260
		{
261
			$net = ($round->score - round($round->handicap));
262
			return $round->netScore = ($net - $round->course->par);
263
		});
264
265
		// Sort by netScore
266 View Code Duplication
		$rounds->sort(function($a, $b)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
267
		{
268
			$a = $a->netScore;
269
			$b = $b->netScore;
270
			if ($a === $b) {
271
				return 0;
272
			}
273
			return ($a > $b) ? 1 : -1;
274
		});
275
276
		return $rounds;
277
278
	}
279
	public function netScoresByPlayerTop($playerId,$top)
280
	{
281
		$netScores = $this->netScoresByPlayer($playerId);
282
		return $netScores->take($top);
283
	}
284
	public function netScoresByPlayerYear($playerId, $year)
285
	{
286
		$date1 = $year . '-12-31';
287
		$date2 = $year . '-01-01';
288
		//$date2 = $date1 - 1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
289
		//$date2 .= '-01-01';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
291
292
		// Get players match scores
293
		$rounds = Round::with('player')
294
			->where('player_id', '=', $playerId)
295
			->where('date', '<', $date1)
296
			->where('date','>', $date2)
297
			->whereNotNull('match_id')->get();
298
299
		//for each round get match handicap
300 View Code Duplication
		$rounds->map(function($round)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
301
		{
302
			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id','=', $round->match_id)->get();
303
			foreach($playerMatch as $player){
304
				$handicap = $player['pivot']['handicap'];
305
				$round->handicap = $handicap;
306
			}
307
		});
308
		//Calculate net score using match handicap
309 View Code Duplication
		$rounds->map(function($round)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
310
		{
311
			$net = ($round->score - round($round->handicap));
312
			return $round->netScore = ($net - $round->course->par);
313
		});
314
315
		// Sort by netScore
316 View Code Duplication
		$rounds->sort(function($a, $b)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
317
		{
318
			$a = $a->netScore;
319
			$b = $b->netScore;
320
			if ($a === $b) {
321
				return 0;
322
			}
323
			return ($a > $b) ? 1 : -1;
324
		});
325
326
		return $rounds;
327
	}
328
	public function netScoresByPlayerTopYear($playerId,$top, $year)
329
	{
330
		$netScores = $this->netScoresByPlayerYear($playerId, $year);
331
		return $netScores->take($top);
332
	}
333
334 View Code Duplication
	public function netScoresLeague()
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...
335
	{
336
		//get players
337
		$players = Player::all();
338
339
		$netScores = new \Illuminate\Support\Collection();
340
		foreach($players as $player){
341
			$netScores->push($this->netScoresByPlayer($player->id));
342
		}
343
		return $netScores;
344
345
	}
346 View Code Duplication
	public function netScoresLeagueTop($number)
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...
347
	{
348
		//get players
349
		$players = Player::all();
350
351
		$netScores = new \Illuminate\Support\Collection();
352
		foreach($players as $player){
353
			$netScore = $this->netScoresByPlayerTop($player->id, $number);
354
			if(!$netScore->isEmpty()){
355
				$netScores->push($netScore);
356
			}
357
		}
358
359
		return $netScores;
360
	}
361 View Code Duplication
	public function netScoresLeagueYear($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...
362
	{
363
		//get players
364
		$players = Player::all();
365
366
		$netScores = new \Illuminate\Support\Collection();
367
		foreach($players as $player){
368
			$netScores->push($this->netScoresByPlayerYear($player->id,$year));
369
		}
370
		return $netScores;
371
	}
372 View Code Duplication
	public function netScoresLeagueTopYear($top,$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...
373
	{
374
		//get players
375
		$players = Player::all();
376
377
		$netScores = new \Illuminate\Support\Collection();
378
		foreach($players as $player){
379
			$netScore = $this->netScoresByPlayerTopYear($player->id, $top, $year);
380
			if(!$netScore->isEmpty()){
381
				$netScores->push($netScore);
382
			}
383
		}
384
385
		return $netScores;
386
	}
387
388 View Code Duplication
	public function netCumulative()
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...
389
	{
390
		//get players
391
		$players = Player::all();
392
393
		$cumulativeNetScores = new \Illuminate\Support\Collection();
394
		foreach($players as $player){
395
			$cumulativeNetScores->push($this->netCumulativeByPlayer($player->id));
396
		}
397
		return $cumulativeNetScores;
398
	}
399 View Code Duplication
	public function netCumulativeTop($top)
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...
400
	{
401
		//get players
402
		$players = Player::all();
403
404
		$cumulativeNetScores = new \Illuminate\Support\Collection();
405
		foreach($players as $player){
406
			$netScore = $this->netCumulativeByPlayerTop($player->id, $top);
407
			if($netScore->isEmpty() == false){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
408
				$cumulativeNetScores->push($netScore);
409
			}
410
		}
411
412
		return $cumulativeNetScores;
413
	}
414 View Code Duplication
	public function netCumulativeByPlayer($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...
415
	{
416
		$netScores = $this->netScoresByPlayer($playerId);
417
		$cumulativeNet= new \Illuminate\Support\Collection();
418
419
		if($netScores->count() > 0){
420
			$netScore = $netScores->first();
421
422
			$totalNetScore = $netScores->sum('netScore');
423
			$cumulativeNet->put('player', $netScore->player->name);
424
			$cumulativeNet->put('score', $totalNetScore);
425
			$cumulativeNet->put('rounds', $netScores->count());
426
		}
427
428
		return $cumulativeNet;
429
	}
430 View Code Duplication
	public function netCumulativeByPlayerTop($playerId, $top)
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...
431
	{
432
		$netScores = $this->netScoresByPlayerTop($playerId, $top);
433
		$cumulativeNet= new \Illuminate\Support\Collection();
434
435
		if($netScores->count() > 0){
436
			$netScore = $netScores->first();
437
438
			$totalNetScore = $netScores->sum('netScore');
439
			$cumulativeNet->put('player', $netScore->player->name);
440
			$cumulativeNet->put('score', $totalNetScore);
441
			$cumulativeNet->put('rounds', $netScores->count());
442
		}
443
444
		return $cumulativeNet;
445
	}
446 View Code Duplication
	public function netCumulativeYear($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...
447
	{
448
		//get players
449
		$players = Player::all();
450
451
		$cumulativeNetScores = new \Illuminate\Support\Collection();
452
		foreach($players as $player){
453
			$cumulativeNetScores->push($this->netCumulativeByPlayerYear($player->id,$year));
454
		}
455
		return $cumulativeNetScores;
456
	}
457 View Code Duplication
	public function netCumulativeTopYear($top,$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...
458
	{
459
		//get players
460
		$players = Player::all();
461
462
		$cumulativeNetScores = new \Illuminate\Support\Collection();
463
		foreach($players as $player){
464
			$netScore = $this->netCumulativeByPlayerTopYear($player->id, $top, $year);
465
			if($netScore->isEmpty() == false){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
466
				$cumulativeNetScores->push($netScore);
467
			}
468
		}
469
470
		return $cumulativeNetScores;
471
	}
472 View Code Duplication
	public function netCumulativeByPlayerYear($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...
473
	{
474
		$netScores = $this->netScoresByPlayerYear($playerId, $year);
475
		$cumulativeNet= new \Illuminate\Support\Collection();
476
477
		if($netScores->count() > 0){
478
			$netScore = $netScores->first();
479
480
			$totalNetScore = $netScores->sum('netScore');
481
			$cumulativeNet->put('player', $netScore->player->name);
482
			$cumulativeNet->put('score', $totalNetScore);
483
			$cumulativeNet->put('rounds', $netScores->count());
484
		}
485
486
		return $cumulativeNet;
487
	}
488 View Code Duplication
	public function netCumulativeByPlayerTopYear($playerId,$top,$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...
489
	{
490
		$netScores = $this->netScoresByPlayerTopYear($playerId, $top, $year);
491
		$cumulativeNet= new \Illuminate\Support\Collection();
492
493
		if($netScores->count() > 0){
494
			$netScore = $netScores->first();
495
496
			$totalNetScore = $netScores->sum('netScore');
497
			$cumulativeNet->put('player', $netScore->player->name);
498
			$cumulativeNet->put('score', $totalNetScore);
499
			$cumulativeNet->put('rounds', $netScores->count());
500
		}
501
502
		return $cumulativeNet;
503
	}
504
505
506
}
507