EloquentMatchRoundRepository::getMatchData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace GolfLeague\Storage\MatchRound;
2
3
use \Match as Match;
4
use \Round as Round;
5
use \Player as Player;
6
7
class EloquentMatchRoundRepository implements MatchRoundRepository
8
{
9
  /*Return Score collections that include:
10
   * Player Name
11
   * Date
12
   * Total
13
   * Course
14
   * Multideminsional Array of Hole Numbers and scores
15
   **/
16
17
   //Retrieve all rounds associated with a match with holescores
18
    public function all()
19
    {
20
        return Round::with('player', 'holescores')->whereNotNull('match_id')->get();
21
    }
22
23
    // Retrieve Rounds of a match with holescores
24
    // Return data is sorted by the order of the holes of the round
25
    public function getByMatch($matchid)
26
    {
27
		return Round::with('player', 'holescores')->where('match_id', '=', $matchid)->get();
28
    }
29
30
    public function create($matchdata)
31
    {
32
33
    }
34
35
	public function matchGroup($matchid, $group)
36
	{
37
        $players = Match::find($matchid)->players()->where('match_player.group','=',$group)->get();
38
		foreach($players as $key => $player) {
39
			$rounds = Round::with('holescores', 'course.holes')->where('player_id', '=', $player->id)->where('match_id', '=', $matchid)->get();
40
            $players[$key]['round'] = $rounds;
41
		}
42
		return $players;
43
	}
44
45
    public function getMatchData($matchid)
46
    {
47
        $match = Match::find($matchid)->players()->where('match_player.match_id','=', $matchid)->get();
48
		return $match;
49
    }
50
51
	public function getMatchPlayerHandicap($matchid, $playerId)
52
	{
53
		$players = Player::find($playerId)->matches()->where('match_player.match_id','=', $matchid)->get();
54
		foreach($players as $player){
55
			$handicap = $player['pivot']['handicap'];
56
		}
57
		return $handicap;
0 ignored issues
show
Bug introduced by
The variable $handicap does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
58
	}
59
}
60