Passed
Push — master ( 59b1f2...d98836 )
by Julien
33:15
created

PlayOffTreeGen::chunkAndShuffle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 8
nc 3
nop 3
1
<?php
2
3
namespace Xoco70\KendoTournaments\TreeGen;
4
5
use Illuminate\Support\Collection;
6
use Xoco70\KendoTournaments\Models\Championship;
7
8
class PlayOffTreeGen extends TreeGen
9
{
10
    /**
11
     * Calculate the Byes need to fill the Championship Tree.
12
     * @param Championship $championship
13
     * @return Collection
14
     */
15
    protected function getByeGroup(Championship $championship, $fighters)
16
    {
17
        $fighterCount = $fighters->count();
18
        $preliminaryGroupSize = $championship->settings->preliminaryGroupSize;
19
        $treeSize = $this->getTreeSize($fighterCount, $preliminaryGroupSize);
20
        $byeCount = $treeSize - $fighterCount;
21
22
        return $this->createNullsGroup($byeCount);
23
    }
24
25
26
    /**
27
     * Create empty groups for direct Elimination Tree
28
     * @param $numFighters
29
     */
30
    public function pushEmptyGroupsToTree($numFighters)
31
    {
32
        $numFightersEliminatory = $numFighters / $this->championship->getSettings()->preliminaryGroupSize * 2;
33
        // We calculate how much rounds we will have
34
        $numRounds = intval(log($numFightersEliminatory, 2));
35
        $this->pushGroups($numRounds, $numFightersEliminatory);
36
    }
37
38
    /**
39
     * Chunk Fighters into groups for fighting, and optionnaly shuffle
40
     * @param $round
41
     * @param $shuffle
42
     * @param $fightersByEntity
43
     * @return mixed
44
     */
45
    protected function chunkAndShuffle($round, $shuffle, $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...
46
    {
47
        if ($this->championship->hasPreliminary()) {
48
            $fightersGroup = $fightersByEntity->chunk($this->settings->preliminaryGroupSize);
49
            if ($shuffle) {
50
                $fightersGroup = $fightersGroup->shuffle();
51
            }
52
        } else { // Round Robin
53
            $fightersGroup = $fightersByEntity->chunk($fightersByEntity->count());
54
        }
55
        return $fightersGroup;
56
    }
57
}
58