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

PlayOffCompetitorTreeGen   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 37
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A syncGroup() 5 5 1
A addFighterToGroup() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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