EloquentLeaderboardRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B get() 0 36 4
1
<?php namespace GolfLeague\Storage\Leaderboard;
2
3
use \Match as Match;
4
5
class EloquentLeaderboardRepository implements LeaderboardRepository
6
{
7
8
	public function __construct(Match $match)
9
    {
10
        $this->match = $match;
0 ignored issues
show
Bug introduced by
The property match does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
11
    }
12
13
    public function get($year)
14
    {
15
        //Get all match ids for a given year
16
		//get all player ids
17
		//for each player id get total winnings from pivot where (player id and match id)
18
		$year = $year . '-01-01';
19
		$matches = $this->match->with('players')->where('created_at', '>', $year)->get(); //get match eventually by year
20
21
		//filter out players from match
22
		$moneyList = array();
23
		$players = array();
0 ignored issues
show
Unused Code introduced by
$players is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
		foreach($matches as $key => $item){
25
			$players = $item->players;
26
			foreach($players as $playersKey => $player){
27
				if (array_key_exists($player->id, $moneyList)) {
28
					//add previois to new
29
					$moneyList[$player->id]['winnings'] = sprintf('%01.2f', ($moneyList[$player->id]['winnings'] + $player->pivot->winnings));
30
					$moneyList[$player->id]['entryfees'] += 5;
31
					$moneyList[$player->id]['entryfees'] = sprintf('%01.2f',$moneyList[$player->id]['entryfees']);
32
					$moneyList[$player->id]['net'] = $moneyList[$player->id]['winnings'] - $moneyList[$player->id]['entryfees'];
33
					$moneyList[$player->id]['net'] = sprintf('%01.2f',$moneyList[$player->id]['net']);
34
				}
35
				else {
36
					$moneyList[$player->id]['id'] = $player->id;
37
					$moneyList[$player->id]['name'] = $player->name;
38
					$moneyList[$player->id]['winnings'] = sprintf('%01.2f',$player->pivot->winnings);
39
					$moneyList[$player->id]['entryfees'] = 5;
40
					$moneyList[$player->id]['entryfees'] = sprintf('%01.2f',$moneyList[$player->id]['entryfees']);
41
					$moneyList[$player->id]['net'] = $moneyList[$player->id]['winnings'] - $moneyList[$player->id]['entryfees'];
42
					$moneyList[$player->id]['net'] = sprintf('%01.2f',$moneyList[$player->id]['net']);
43
				}
44
			}
45
		}
46
47
		return $moneyList;
48
    }
49
}
50