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

PlayOffCompetitorTreeGen::getFighter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 PlayOffCompetitorTreeGen extends PlayOffTreeGen
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
14
    use hasCompetitorsTrait;
15
16
    /**
17
     * @param FightersGroup $group
18
     * @param $fighters
19
     *
20
     * @return FightersGroup
21
     */
22
    public function syncGroup(FightersGroup $group, $fighters)
23
    {
24
        // Add all competitors to Pivot Table
25
        return $group->syncCompetitors($fighters);
26
    }
27
28
29
    /**
30
     * @param FightersGroup $group
31
     * @param $competitor
32
     * @param $fighterToUpdate
33
     * Common to All Playoff and singleElim
34
     */
35
    protected function addFighterToGroup(FightersGroup $group, $competitor, $fighterToUpdate)
36
    {
37
        // fighterToUpdate is coming at format c1, c2, c3 etc.
38
        $numFighterToUpdate = substr($fighterToUpdate, 1);
39
        $competitorGroup = FighterGroupCompetitor::where('fighters_group_id', $group->id)
40
            ->get()
41
            ->get($numFighterToUpdate - 1);
42
43
        // we must update the right result
44
        $competitorGroup->competitor_id = $competitor->id;
45
        $competitorGroup->save();
46
    }
47
}
48