Completed
Push — master ( 5bc292...02102e )
by Michael
03:27
created

EloquentMatchRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 2
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace GolfLeague\Storage\Match;
2
3
use \Match as Match;
4
use \Player as Player;
5
6
class EloquentMatchRepository implements MatchRepository
7
{
8
  /*Return Score collections that include:
9
   * Player Name
10
   * Date
11
   * Total
12
   * Course
13
   * Multideminsional Array of Hole Numbers and scores   *
14
   **/
15
	public function __construct(Match $match, Player $player)
16
    {
17
        $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...
18
		$this->player = $player;
0 ignored issues
show
Bug introduced by
The property player 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...
19
    }
20
21
    public function all()
22
    {
23
		return $this->match->all();
24
    }
25
26
	public function get($matchid)
27
	{
28
		 return Match::with('course', 'players', 'course.holes')->find($matchid);
29
	}
30
31
	public function getByDate($startDate, $endDate)
32
	{
33
		 //dd($startDate);
34
		 return Match::with('course')->where('date', '>=', $startDate)->where('date', '<=', $endDate)->get();
35
	}
36
37
	public function getYears()
38
	{
39
		$dates =  Match::orderBy('date', 'DESC')->get(['date']);
40
		//return $dates;
41
		$years = $dates->map(function($years){
42
			return substr($years->date, 0, 4);
43
		})->toArray();
44
45
		return array_unique($years);
46
	}
47
    //Find Scores by Player Id
48
    public function find($playerId)
49
    {
50
        //return Round::with('player', 'holescores')->where('player_id', '=', $playerId)->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
51
    }
52
53
    public function create($matchdata)
54
    {
55
		//enter match data to Matches table
56
		$this->match->date = $matchdata['date'];
57
		$this->match->course_id = $matchdata['course'];
58
		$this->match->purse = $matchdata['purse'];
59
		$this->match->skinsamoney = $matchdata['skinsamoney'];
60
		$this->match->skinsbmoney = $matchdata['skinsbmoney'];
61
		$this->match->grossmoney = $matchdata['grossmoney'];
62
		$this->match->netmoney = $matchdata['netmoney'];
63
64
		$this->match->save(); //save to match table
65
66
		foreach ($matchdata['player'] as $key => $player){
67
			$currentPlayer = $this->player->find($player['player_id']);
68
			$attributes = array(
69
				"level_id" => $player['level_id'],
70
				"group" => $player['group'],
71
				"handicap" => $player['handicap'],
72
				"winnings" => $player['winnings'],
73
			);
74
			$currentPlayer->matches()->save($this->match, $attributes); //save match_player pivot data
75
		}// End foreach
76
		return $this->match->id;
77
    }
78
79
	public function delete($matchId)
80
	{
81
		return 'deleted';
82
	}
83
84
}
85