Completed
Push — master ( 547255...753a4f )
by Julien
11:37 queued 25s
created

SingleEliminationCompetitorTreeGen::createByeFighter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Xoco70\LaravelTournaments\TreeGen;
4
5
use Illuminate\Support\Collection;
6
use Xoco70\LaravelTournaments\Models\Competitor;
7
use Xoco70\LaravelTournaments\Models\FighterGroupCompetitor;
8
use Xoco70\LaravelTournaments\Models\FightersGroup;
9
use Xoco70\LaravelTournaments\Traits\hasCompetitorsTrait;
10
11 View Code Duplication
class SingleEliminationCompetitorTreeGen extends SingleEliminationTreeGen
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    use hasCompetitorsTrait;
14
15
    /**
16
     * @param $group
17
     * @param $fighters
18
     */
19
    public function syncGroup(FightersGroup $group, $fighters)
20
    {
21
        return $group->syncCompetitors($fighters);
22
    }
23
24
25
    /**
26
     * @param FightersGroup $group
27
     * @param $competitor
28
     * @param $fighterToUpdate
29
     */
30
    protected function addFighterToGroup(FightersGroup $group, $competitor, $fighterToUpdate)
31
    {
32
        // fighterToUpdate is coming at format c1, c2, c3 etc.
33
        $numFighterToUpdate = substr($fighterToUpdate, 1);
34
        $competitorGroup = FighterGroupCompetitor::where('fighters_group_id', $group->id)
35
            ->get()
36
            ->get($numFighterToUpdate - 1);
37
38
        // we must update the right result
39
        $competitorGroup->competitor_id = $competitor->id;
40
        $competitorGroup->save();
41
    }
42
}
43