Issues (24)

src/Models/SingleEliminationFight.php (1 issue)

1
<?php
2
3
namespace Xoco70\LaravelTournaments\Models;
4
5
class SingleEliminationFight extends Fight
6
{
7
    public function __construct(Fight $fight = null)
8
    {
9
        parent::__construct();
10
        if ($fight != null) {
11
            $this->id = $fight->id;
12
            $this->short_id = $fight->short_id;
13
            $this->fighters_group_id = $fight->fighters_group_id;
14
            $this->c1 = $fight->c1;
15
            $this->c2 = $fight->c2;
16
        }
17
    }
18
19
    /**
20
     * @param Championship $championship
21
     */
22
    public static function saveFights(Championship $championship, $fromRound = 1)
23
    {
24
//        dd("generating fights");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
25
        $round = [];
26
        $groupsFromRound = $championship->groupsFromRound($fromRound)->get();
27
        foreach ($groupsFromRound as $group) {
28
            $fighters = parent::getFightersWithByes($group);
29
            $away = $fighters->splice(count($fighters) / 2); // 2
30
            $home = $fighters; // 1
31
32
            $countHome = count($home);
33
            $countAway = count($away);
34
            for ($i = 0; $i < $countHome + $countAway - 1; $i++) {
35
                for ($j = 0; $j < $countHome; $j++) {
36
                    $round[$i][$j]['Home'] = $home[$j];
37
                    $round[$i][$j]['Away'] = $away[$j];
38
                    $fight = new Fight();
39
                    $fight->fighters_group_id = $group->id;
40
                    $fight->c1 = $round[$i][$j]['Home']->id;
41
                    $fight->c2 = $round[$i][$j]['Away']->id;
42
                    $fight->area = $group->area;
43
                    $fight->save();
44
                }
45
                if ($countHome + $countAway - 1 > 2) {
46
                    $away->prepend($home->splice(1, 1)->shift());
47
                    $home->push($away->pop());
48
                }
49
            }
50
        }
51
    }
52
}
53