Completed
Push — master ( f65102...332511 )
by Julien
02:46
created

PlayOffTreeGen::generateNextRoundsFights()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Xoco70\KendoTournaments\TreeGen;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Facades\App;
7
use Xoco70\KendoTournaments\Models\Championship;
8
use Xoco70\KendoTournaments\Models\Fight;
9
use Xoco70\KendoTournaments\Models\PreliminaryFight;
10
11
class PlayOffTreeGen extends TreeGen
12
{
13
14
15
    /**
16
     * Calculate the Byes need to fill the Championship Tree.
17
     * @param Championship $championship
18
     * @param $fighters
19
     * @return Collection
20
     */
21
    protected function getByeGroup(Championship $championship, $fighters)
22
    {
23
        $fighterCount = $fighters->count();
24
        $preliminaryGroupSize = $championship->getSettings()->preliminaryGroupSize;
25
        $treeSize = $this->getTreeSize($fighterCount, $preliminaryGroupSize);
26
        $byeCount = $treeSize - $fighterCount;
27
28
        return $this->createNullsGroup($byeCount);
29
    }
30
31
32
    /**
33
     * Create empty groups for direct Elimination Tree
34
     * @param $numFighters
35
     */
36
    public function pushEmptyGroupsToTree($numFighters)
37
    {
38
        $numFightersElim = $numFighters / $this->championship->getSettings()->preliminaryGroupSize * 2;
39
        // We calculate how much rounds we will have
40
        $numRounds = intval(log($numFightersElim, 2));
41
        $this->pushGroups($numRounds, $numFightersElim);
42
    }
43
44
    /**
45
     * Chunk Fighters into groups for fighting, and optionnaly shuffle
46
     * @param $round
47
     * @param $fightersByEntity
48
     * @return mixed
49
     */
50
    protected function chunkAndShuffle($round, $fightersByEntity)
0 ignored issues
show
Unused Code introduced by
The parameter $round is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        if ($this->championship->hasPreliminary()) {
53
            $fightersGroup = $fightersByEntity->chunk($this->settings->preliminaryGroupSize);
54
            if (!App::runningUnitTests()) {
55
                $fightersGroup = $fightersGroup->shuffle();
56
            }
57
        } else { // Round Robin
58
            $fightersGroup = $fightersByEntity->chunk($fightersByEntity->count());
59
        }
60
        return $fightersGroup;
61
    }
62
63
    /**
64
     * Generate First Round Fights
65
     * @param Championship $championship
66
     */
67
    public static function generateFights(Championship $championship)
68
    {
69
        $settings = $championship->getSettings();
70
        parent::destroyPreviousFights($championship);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (destroyPreviousFights() instead of generateFights()). Are you sure this is correct? If so, you might want to change this to $this->destroyPreviousFights().

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...
71
        // Very specific case to common case : Preliminary with 3 fighters
72
        if ($settings->preliminaryGroupSize == 3) {
73
            for ($numGroup = 1; $numGroup <= $settings->preliminaryGroupSize; $numGroup++) {
74
                PreliminaryFight::saveFights($championship->fightersGroups()->get(), $numGroup);
75
            }
76
        }
77
    }
78
79
80
    public function generateNextRoundsFights()
81
    {
82
//        $championship = $this->championship->withCount('teams', 'competitors')->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
83
//        $fightersCount = $championship->competitors_count + $championship->teams_count;
84
//        $maxRounds = intval(ceil(log($fightersCount, 2)));
85
//        for ($numRound = 1; $numRound < $maxRounds; $numRound++) {
86
//            $fightsByRound = $championship->fightsByRound($numRound)->with('group.parent', 'group.children')->get();
87
//            $this->updateParentFight($championship, $fightsByRound);
88
//        }
89
    }
90
91
}
92