BigBad /
golfleague
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace GolfLeague\Services; |
||
| 2 | |||
| 3 | use GolfLeague\Storage\Match\MatchRepository; |
||
| 4 | use GolfLeague\Storage\MatchRound\MatchRoundRepository; |
||
| 5 | use GolfLeague\PrizeMoney; |
||
| 6 | use GolfLeague\Handicap; |
||
| 7 | use \Player; |
||
| 8 | use \Match; |
||
| 9 | use \GolfLeague\Storage\Ctp\CtpRepository; |
||
| 10 | use \Grosswinner; |
||
| 11 | use \Netwinner; |
||
| 12 | use \Skin; |
||
| 13 | use GolfLeague\Services\CarryOver; |
||
| 14 | use Illuminate\Events\Dispatcher; |
||
| 15 | use \Teammatch; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Our MatchService, containing all useful methods for business logic around Matches |
||
| 19 | */ |
||
| 20 | class MatchService |
||
| 21 | { |
||
| 22 | // Containing our matchRepository to make all our database calls to |
||
| 23 | protected $matchRepo; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Loads our $matchRepo |
||
| 27 | * |
||
| 28 | * @param MatchRepository $matchRepo |
||
| 29 | * @return MatchService |
||
|
0 ignored issues
–
show
|
|||
| 30 | */ |
||
| 31 | public function __construct(MatchRoundRepository $matchRoundRepo, |
||
| 32 | MatchRepository $matchRepo, |
||
| 33 | PrizeMoney $prizeMoney, |
||
| 34 | Player $player, |
||
| 35 | Match $match, |
||
| 36 | CtpRepository $ctp, |
||
| 37 | Teammatch $teammatch, |
||
| 38 | Dispatcher $events) |
||
| 39 | { |
||
| 40 | $this->matchRoundRepo = $matchRoundRepo; |
||
|
0 ignored issues
–
show
The property
matchRoundRepo 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...
|
|||
| 41 | $this->matchRepo = $matchRepo; |
||
| 42 | $this->prizeMoney = $prizeMoney; |
||
|
0 ignored issues
–
show
The property
prizeMoney 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...
|
|||
| 43 | $this->player = $player; |
||
|
0 ignored issues
–
show
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...
|
|||
| 44 | $this->match = $match; |
||
|
0 ignored issues
–
show
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...
|
|||
| 45 | $this->ctp = $ctp; |
||
|
0 ignored issues
–
show
The property
ctp 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...
|
|||
| 46 | $this->teammatch = $teammatch; |
||
|
0 ignored issues
–
show
The property
teammatch 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...
|
|||
| 47 | $this->events = $events; |
||
|
0 ignored issues
–
show
The property
events 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...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Method to create match from input Match data |
||
| 52 | * |
||
| 53 | * @param mixed $matchdata |
||
| 54 | * @return |
||
| 55 | */ |
||
| 56 | public function create($matchdata) |
||
| 57 | { |
||
| 58 | $this->prizeMoney->setPurse($matchdata['purse']); |
||
| 59 | |||
| 60 | $matchdata['purse'] = number_format($matchdata['purse'], 2); |
||
| 61 | $matchdata['grossmoney'] = $this->prizeMoney->getlowScore(); |
||
| 62 | $matchdata['netmoney'] = $this->prizeMoney->getlowScore(); |
||
| 63 | |||
| 64 | //How many A and B players |
||
| 65 | $totalPlayers = 0; |
||
| 66 | |||
| 67 | $aPlayerCount = 0; |
||
| 68 | |||
| 69 | $bPlayerCount = 0; |
||
| 70 | foreach($matchdata['player'] as $player){ |
||
| 71 | if ($player['level_id'] == '1'){ |
||
| 72 | $aPlayerCount++; |
||
| 73 | } |
||
| 74 | else { |
||
| 75 | $bPlayerCount++; |
||
| 76 | } |
||
| 77 | $totalPlayers++; |
||
| 78 | } |
||
| 79 | |||
| 80 | //Calculate Skins money based on how many players in each group |
||
| 81 | |||
| 82 | $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount); |
||
| 83 | $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount); |
||
| 84 | //check for carry over money and if there is add it to skins money |
||
| 85 | $carryOver = new CarryOver; |
||
| 86 | $carryOverMoney = $carryOver->calculate(); |
||
| 87 | $matchdata['skinsamoney'] += $carryOverMoney[1]; |
||
| 88 | $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
||
| 89 | |||
| 90 | //append current handicap and set winnings to 0 for each player |
||
| 91 | foreach ($matchdata['player'] as $key=>$player) { |
||
| 92 | //get each player's current handicap |
||
| 93 | $currentPlayer = $this->player->find($player['player_id']); |
||
| 94 | $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap; |
||
| 95 | $matchdata['player'][$key]['winnings'] = 0; |
||
| 96 | }// End foreach |
||
| 97 | |||
| 98 | $matchid = $this->matchRepo->create($matchdata); |
||
| 99 | $matchdata['match_id'] = $matchid; |
||
| 100 | $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
||
| 101 | |||
| 102 | // Run for team Matches |
||
| 103 | if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
||
| 104 | |||
| 105 | foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
||
| 106 | $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$matchUp1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $matchUp1 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 107 | } |
||
| 108 | |||
| 109 | //Save matchUp 1 |
||
| 110 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$match1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $match1 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 111 | $match1['team_id'] = $matchUp1[0][0]['team']; |
||
|
0 ignored issues
–
show
The variable
$matchUp1 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
Loading history...
|
|||
| 112 | $match1['player1'] = $matchUp1[0][0]['player_id']; |
||
| 113 | View Code Duplication | if(isset($matchUp1[0][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 114 | $match1['player2'] = $matchUp1[0][1]['player_id']; |
||
| 115 | } |
||
| 116 | $match1['opponent'] = $matchUp1[1][0]['team']; |
||
| 117 | $this->teammatch->create($match1); //save to match table |
||
| 118 | |||
| 119 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
| 120 | $match1['team_id'] = $matchUp1[1][0]['team']; |
||
| 121 | $match1['player1'] = $matchUp1[1][0]['player_id']; |
||
| 122 | View Code Duplication | if(isset($matchUp1[1][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 123 | $match1['player2'] = $matchUp1[1][1]['player_id']; |
||
| 124 | } |
||
| 125 | $match1['opponent'] = $matchUp1[0][0]['team']; |
||
| 126 | $this->teammatch->create($match1); //save to match table |
||
| 127 | |||
| 128 | |||
| 129 | foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
||
| 130 | $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$matchUp2 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $matchUp2 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 131 | } |
||
| 132 | |||
| 133 | //Save matchUp 2 |
||
| 134 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$match2 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $match2 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 135 | $match2['team_id'] = $matchUp2[0][0]['team']; |
||
|
0 ignored issues
–
show
The variable
$matchUp2 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
Loading history...
|
|||
| 136 | $match2['player1'] = $matchUp2[0][0]['player_id']; |
||
| 137 | View Code Duplication | if(isset($matchUp2[0][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 138 | $match2['player2'] = $matchUp2[0][1]['player_id']; |
||
| 139 | } |
||
| 140 | $match2['opponent'] = $matchUp2[1][0]['team']; |
||
| 141 | $this->teammatch->create($match2); //save to match table |
||
| 142 | |||
| 143 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
| 144 | $match2['team_id'] = $matchUp2[1][0]['team']; |
||
| 145 | $match2['player1'] = $matchUp2[1][0]['player_id']; |
||
| 146 | View Code Duplication | if(isset($matchUp2[1][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 147 | $match2['player2'] = $matchUp2[1][1]['player_id']; |
||
| 148 | } |
||
| 149 | $match2['opponent'] = $matchUp2[0][0]['team']; |
||
| 150 | $this->teammatch->create($match2); //save to match table |
||
| 151 | |||
| 152 | |||
| 153 | foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
||
| 154 | $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$matchUp3 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $matchUp3 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 155 | } |
||
| 156 | |||
| 157 | //Save matchUp 3 |
||
| 158 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$match3 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $match3 = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 159 | $match3['team_id'] = $matchUp3[0][0]['team']; |
||
|
0 ignored issues
–
show
The variable
$matchUp3 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
Loading history...
|
|||
| 160 | $match3['player1'] = $matchUp3[0][0]['player_id']; |
||
| 161 | View Code Duplication | if(isset($matchUp3[0][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 162 | $match3['player2'] = $matchUp3[0][1]['player_id']; |
||
| 163 | } |
||
| 164 | |||
| 165 | $match3['opponent'] = $matchUp3[1][0]['team']; |
||
| 166 | $this->teammatch->create($match3); //save to match table |
||
| 167 | |||
| 168 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
| 169 | $match3['team_id'] = $matchUp3[1][0]['team']; |
||
| 170 | $match3['player1'] = $matchUp3[1][0]['player_id']; |
||
| 171 | View Code Duplication | if(isset($matchUp3[1][1]['player_id'])){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 172 | $match3['player2'] = $matchUp3[1][1]['player_id']; |
||
| 173 | } |
||
| 174 | $match3['opponent'] = $matchUp3[0][0]['team']; |
||
| 175 | $this->teammatch->create($match3); //save to match table |
||
| 176 | |||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | public function finalize($matchdata) |
||
| 181 | { |
||
| 182 | // post CTP1 and CTP2 |
||
| 183 | $ctp1 = array( |
||
| 184 | 'match_id' => $matchdata['match'], |
||
| 185 | 'player_id' => $matchdata['ctp1'], |
||
| 186 | 'hole_id' => $matchdata['ctp1hole'], |
||
| 187 | 'money' => $this->prizeMoney->getCtp() |
||
| 188 | ); |
||
| 189 | $this->ctp->create($ctp1); |
||
| 190 | $ctp2 = array( |
||
| 191 | 'match_id' => $matchdata['match'], |
||
| 192 | 'player_id' => $matchdata['ctp2'], |
||
| 193 | 'hole_id' => $matchdata['ctp2hole'], |
||
| 194 | 'money' => $this->prizeMoney->getCtp() |
||
| 195 | ); |
||
| 196 | $this->ctp->create($ctp2); |
||
| 197 | |||
| 198 | //calculate Gross winner and post to grossWinnersTable |
||
| 199 | |||
| 200 | $matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']); |
||
| 201 | |||
| 202 | |||
| 203 | $lowGross = array(); |
||
| 204 | foreach ($matchRound as $key => $match){ |
||
| 205 | $lowGross[$match['player']->id] = $match['score']; |
||
| 206 | } |
||
| 207 | $arrayLowGross = array_keys($lowGross, min($lowGross)); |
||
| 208 | View Code Duplication | foreach($arrayLowGross as $key => $lowgrossPlayer) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 209 | $grossWinner = new Grosswinner; |
||
| 210 | $grossWinner->player_id = $lowgrossPlayer; |
||
| 211 | $grossWinner->match_id = $matchdata['match']; |
||
| 212 | $grossWinner->score = $lowGross[$lowgrossPlayer]; |
||
| 213 | $grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross); |
||
| 214 | $grossWinner->save(); |
||
| 215 | } |
||
| 216 | |||
| 217 | //Calculate NET winner |
||
| 218 | $lowNet = array(); |
||
| 219 | $scores =array(); |
||
|
0 ignored issues
–
show
$scores 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 Loading history...
|
|||
| 220 | foreach ($matchRound as $key => $match){ |
||
| 221 | $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score |
||
| 222 | $lowNet[$match['player']->id] = $netScore; |
||
| 223 | } |
||
| 224 | $arrayLowNet = array_keys($lowNet, min($lowNet)); |
||
| 225 | |||
| 226 | View Code Duplication | foreach($arrayLowNet as $key => $lownetPlayer) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 227 | $netWinner = new Netwinner; |
||
| 228 | $netWinner->player_id = $lownetPlayer; |
||
| 229 | $netWinner->match_id = $matchdata['match']; |
||
| 230 | $netWinner->score = $lowNet[$lownetPlayer]; |
||
| 231 | $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet); |
||
| 232 | $netWinner->save(); |
||
| 233 | } |
||
| 234 | |||
| 235 | //Calculate Skins |
||
| 236 | |||
| 237 | //determine A and B players |
||
| 238 | //using pivot table match_player |
||
| 239 | $match = $this->match->find($matchdata['match']); |
||
| 240 | $aPlayers = array(); |
||
| 241 | $bPlayers = array(); |
||
| 242 | foreach($match->players as $player) |
||
| 243 | { |
||
| 244 | if($player->pivot->level_id == 1){ |
||
| 245 | $aPlayers[] = $player->pivot->player_id; |
||
| 246 | |||
| 247 | } |
||
| 248 | if($player->pivot->level_id == 2){ |
||
| 249 | $bPlayers[] = $player->pivot->player_id; |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | //Create Skins arrays |
||
| 254 | //player_id, 'holescores' |
||
| 255 | foreach($matchRound as $key => $round) { |
||
| 256 | View Code Duplication | if (in_array($round->player_id,$aPlayers)){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 257 | $aPlayersSkins[$key]['player_id'] = $round->player_id; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aPlayersSkins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aPlayersSkins = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 258 | $aPlayersSkins[$key]['holescores'] = $round->holescores; |
||
|
0 ignored issues
–
show
The variable
$aPlayersSkins 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
Loading history...
|
|||
| 259 | } |
||
| 260 | View Code Duplication | if (in_array($round->player_id,$bPlayers)){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 261 | $bPlayersSkins[$key]['player_id'] = $round->player_id; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$bPlayersSkins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $bPlayersSkins = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 262 | $bPlayersSkins[$key]['holescores'] = $round->holescores; |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | //Run A Skins analysis |
||
| 267 | $scores = array(); |
||
| 268 | View Code Duplication | foreach($aPlayersSkins as $key => $playerSkin){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 269 | foreach($playerSkin['holescores'] as $hole => $holescore){ |
||
| 270 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | View Code Duplication | foreach($scores as $hole_id => $hole) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 275 | $minScore = min($hole); |
||
|
0 ignored issues
–
show
$minScore 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 Loading history...
|
|||
| 276 | $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$winners was never initialized. Although not strictly required by PHP, it is generally a good practice to add $winners = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 277 | } |
||
| 278 | $aSkinsWon = 0; |
||
| 279 | View Code Duplication | foreach($winners as $key => $winner) { |
|
|
0 ignored issues
–
show
The variable
$winners 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
Loading history...
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 280 | if(count($winner) === 1) { |
||
| 281 | //post to DB |
||
| 282 | $skinWinner = new Skin; |
||
| 283 | $skinWinner->player_id = $winner[0]; |
||
| 284 | $skinWinner->level_id = 1; |
||
| 285 | $skinWinner->match_id = intval($matchdata['match']); |
||
| 286 | $skinWinner->hole_id = $key; |
||
| 287 | $skinWinner->save(); |
||
| 288 | $aSkinsWon++; |
||
| 289 | } |
||
| 290 | } |
||
| 291 | |||
| 292 | //Run B Skins analysis |
||
| 293 | $scores = array(); |
||
| 294 | View Code Duplication | foreach($bPlayersSkins as $key => $playerSkin){ |
|
|
0 ignored issues
–
show
The variable
$bPlayersSkins 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
Loading history...
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 295 | foreach($playerSkin['holescores'] as $hole => $holescore){ |
||
| 296 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | |||
| 300 | View Code Duplication | foreach($scores as $hole_id => $hole) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 301 | $minScore = min($hole); |
||
|
0 ignored issues
–
show
$minScore 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 Loading history...
|
|||
| 302 | $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
||
| 303 | } |
||
| 304 | $bSkinsWon = 0; |
||
| 305 | View Code Duplication | foreach($winners as $key => $winner) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 306 | if(count($winner) === 1) { |
||
| 307 | //post to DB |
||
| 308 | $skinWinner = new Skin; |
||
| 309 | $skinWinner->player_id = $winner[0]; |
||
| 310 | $skinWinner->level_id = 2; |
||
| 311 | $skinWinner->match_id = intval($matchdata['match']); |
||
| 312 | $skinWinner->hole_id = $key; |
||
| 313 | $skinWinner->save(); |
||
| 314 | $bSkinsWon++; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | $match = Match::find($matchdata['match']); |
||
| 319 | |||
| 320 | //Need to add Carry over money if there no skins are won |
||
| 321 | //check for carry over money |
||
| 322 | $skinsamoney = $match->skinsamoney; // + carryover A money if any |
||
| 323 | $skinsbmoney = $match->skinsbmoney; // + carryover B money if any |
||
| 324 | |||
| 325 | View Code Duplication | if($aSkinsWon > 0) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 326 | $moneyperskinA = $skinsamoney / $aSkinsWon; |
||
| 327 | |||
| 328 | $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get(); |
||
| 329 | foreach ($aSkins as $askin){ |
||
| 330 | $askin->money = $moneyperskinA; |
||
| 331 | $askin->save(); |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | View Code Duplication | if($bSkinsWon > 0) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 336 | $moneyperskinB = $skinsbmoney / $bSkinsWon; |
||
| 337 | |||
| 338 | $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get(); |
||
| 339 | foreach ($bSkins as $bskin){ |
||
| 340 | $bskin->money = $moneyperskinB; |
||
| 341 | $bskin->save(); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | //foreach player in pivot table create player and run handicap analysis |
||
| 345 | foreach($match->players as $matchplayer) |
||
| 346 | { |
||
| 347 | $player = Player::find($matchplayer->pivot->player_id); |
||
| 348 | $handicap = new Handicap($player); |
||
| 349 | $player->handicap = $handicap->calculate(); |
||
| 350 | $player->save(); |
||
| 351 | } |
||
| 352 | |||
| 353 | //Fire event to calculate money won and add to pivot table match_player |
||
| 354 | $this->events->fire('match.finalize', $match); |
||
| 355 | |||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Method to get match from input Match data |
||
| 360 | * |
||
| 361 | * @param mixed $matchdata |
||
|
0 ignored issues
–
show
There is no parameter named
$matchdata. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 362 | * @return JSON object |
||
| 363 | */ |
||
| 364 | public function get($matchid) |
||
| 365 | { |
||
| 366 | $matchdata = $this->matchRepo->get($matchid); |
||
| 367 | return $matchdata; |
||
| 368 | } |
||
| 369 | |||
| 370 | |||
| 371 | |||
| 372 | private function search($array, $key, $value) |
||
| 373 | { |
||
| 374 | $results = array(); |
||
| 375 | if (is_array($array)) { |
||
| 376 | if (isset($array[$key]) && $array[$key] == $value) { |
||
| 377 | $results[] = $array; |
||
| 378 | } |
||
| 379 | foreach ($array as $subarray) { |
||
| 380 | $results = array_merge($results, $this->search($subarray, $key, $value)); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | return $results; |
||
| 384 | } |
||
| 385 | } |
||
| 386 |
Adding a
@returnannotation 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.