TournamentService::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace GolfLeague\Tournament;
4
5
use \Tournament as Tournament;
6
use \Tournamentdate as Tournamentdate;
7
use Match as Match;
8
9
class TournamentService
10
{
11
12
    public function create($input)
13
    {
14
        $tournament = new Tournament($input);
15
        $tournament->save();
16
17
        foreach ($input['dates'] as $date){
18
            $tournamentDate = new Tournamentdate(array('date' => $date));
19
            $tournament->dates()->save($tournamentDate);
20
        }
21
    }
22
23
    public function getByMatchId($id)
24
    {
25
        //Get Match date and check tournament table for a tournament on that date
26
        $match = Match::find($id);
27
        $date = $match->date;
28
        
29
        $tournamentDate = Tournamentdate::select('tournament_id')->where('date', '=', $date)->get();
30
        return $tournamentDate;
31
    }
32
33
    public function get($id)
34
    {
35
        $tournament = Tournament::find($id);
36
        return $tournament;
37
    }
38
39
}