Completed
Push — master ( 5214c7...d85020 )
by Julien
02:34
created

DirectEliminationFight::saveFights()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
cc 5
eloc 21
nc 6
nop 1
1
<?php
2
3
namespace Xoco70\KendoTournaments\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Collection;
7
8
class DirectEliminationFight extends Fight
9
{
10
11
    /**
12
     * @param Championship $championship
13
     */
14
    public static function saveFights(Championship $championship)
15
    {
16
//        $order = 1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
17
        $round = [];
18
        foreach ($championship->fightersGroups()->get() as $group) {
19
            $fighters = parent::getActorsToFights($group);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getActorsToFights() instead of saveFights()). Are you sure this is correct? If so, you might want to change this to $this->getActorsToFights().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
20
            $away = $fighters->splice(count($fighters) / 2); // 2
21
            $home = $fighters; // 1
22
23
            $countHome = count($home);
24
            $countAway = count($away);
25
            for ($i = 0; $i < $countHome + $countAway - 1; $i++) {
26
                for ($j = 0; $j < $countHome; $j++) {
27
                    $round[$i][$j]['Home'] = $home[$j];
28
                    $round[$i][$j]['Away'] = $away[$j];
29
                    $fight = new Fight();
30
                    $fight->fighters_group_id = $group->id;
31
                    $fight->c1 = $round[$i][$j]['Home']->id;
32
                    $fight->c2 = $round[$i][$j]['Away']->id;
33
                    $fight->area = $group->area;
34
                    $fight->save();
35
36
                }
37
                if ($countHome + $countAway - 1 > 2) {
38
                    $away->prepend($home->splice(1, 1)->shift());
39
                    $home->push($away->pop());
40
//                    $order++;
41
                }
42
            }
43
        }
44
    }
45
}