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

DirectEliminationTreeGen::chunkAndShuffle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
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 DirectEliminationTreeGen extends TreeGen
9
{
10
11
    /**
12
     * Calculate the Byes need to fill the Championship Tree.
13
     * @param Championship $championship
14
     * @return Collection
15
     */
16
    protected function getByeGroup(Championship $championship, $fighters)
0 ignored issues
show
Unused Code introduced by
The parameter $championship 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...
17
    {
18
        $fighterCount = $fighters->count();
19
        $treeSize = $this->getTreeSize($fighterCount, $preliminaryGroupSize = 2);
20
        $byeCount = $treeSize - $fighterCount;
21
22
        return $this->createNullsGroup($byeCount);
23
    }
24
25
26
    /**
27
     * Create empty groups for direct Elimination Tree
28
     * @param $numFightersEliminatory
29
     */
30
    public function pushEmptyGroupsToTree($numFightersEliminatory)
31
    {
32
        // We calculate how much rounds we will have
33
        $numRounds = intval(log($numFightersEliminatory, 2));
34
        $this->pushGroups($numRounds, $numFightersEliminatory);
35
    }
36
37
    /**
38
     * Chunk Fighters into groups for fighting, and optionnaly shuffle
39
     * @param $round
40
     * @param $shuffle
41
     * @param $fightersByEntity
42
     * @return Collection|null
43
     */
44
    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...
45
    {
46
        $fightersGroup = null;
0 ignored issues
show
Unused Code introduced by
$fightersGroup is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
48
        $fightersGroup = $fightersByEntity->chunk(2);
49
        if ($shuffle) {
50
            $fightersGroup = $fightersGroup->shuffle();
51
        }
52
        return $fightersGroup;
53
    }
54
}
55