MatchHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 21
rs 9.3142
c 2
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace GolfLeague\Handlers;
4
5
use GolfLeague\Storage\Round\RoundRepository;
6
7
8
/**
9
 * MatchHandler Connection Class
10
 *
11
 * This class subscribes to events in related to match creation
12
 *
13
 * @author          Michael Schmidt
14
 */
15
class MatchHandler
16
{
17
    /**
18
     * Create a new instance of the MatchHandler
19
     *
20
     * @param  GolfLeague\Storage\Round\RoundRepository $roundRepo
21
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
22
     */
23
    public function __construct(RoundRepository $roundRepo)
24
    {
25
        $this->roundRepo= $roundRepo;
0 ignored issues
show
Bug introduced by
The property roundRepo 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...
26
    } // End of __construct
27
28
    /**
29
     * Create an initial round for each player after a new match is created
30
     *
31
     * @param  Match $match
32
     * @return void
33
     */
34
    public function handle($match)
35
    {
36
        //for each player create an initial round
37
        $input = array(
38
        'date' => $match['date'],
39
         'course_id' => $match['course'],
40
41
         'match_id' => $match['match_id'],
42
         'score' => 0,
43
         'esc' => 0
44
         );
45
         foreach($match['player'] as $player){
46
             $input['player_id'] = $player['player_id'];
47
             //If team match then add team id to $input array
48
             if(isset($player['team'])){
49
                 $input['team_id'] = $player['team'];
50
             }
51
             $this->roundRepo->create($input);
52
         }
53
54
    }
55
56
    /**
57
     * Register the listeners for the subscriber.
58
     *
59
     * @param  Illuminate\Events\Dispatcher $events
60
     * @return array
61
     */
62
    public function subscribe($events)
63
    {
64
        $events->listen('match.create', 'GolfLeague\Handlers\MatchHandler');
65
    }
66
}
67