CarryOver::calculate()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.439
cc 5
eloc 16
nc 5
nop 0
1
<?php namespace GolfLeague\Services;
2
3
use \Match;
4
use \Skin;
5
use \Level;
6
7
class CarryOver
8
{
9
10
    public function calculate()
11
    {
12
        $levels = Level::all();
13
        $matches = Match::all();
14
        $carryOverMoney = array();
15
        foreach ($levels as $key => $level){
16
            $carryOverMoney[$level->id] = 0;
17
            foreach($matches as $matchesKey => $match) {
18
                //check skins table for level and match
19
                $skins = Skin::where('match_id', '=', $match->id)->where('level_id', '=', $level->id)->get();
20
                if($skins->count() === 0 ) {
21
                    if ($level->id === 1){
22
                        $carryOverMoney[$level->id] += $match->skinsamoney;
23
                    }
24
                    else {
25
                        $carryOverMoney[$level->id] += $match->skinsbmoney;
26
                    }
27
                }
28
                else {
29
                    $carryOverMoney[$level->id] = 0; //reset carryover money
30
                }
31
            }
32
        }// End foreach
33
        return $carryOverMoney;
34
    }
35
}