Completed
Push — master ( 26d986...9b7bb9 )
by Julien
09:29
created

SingleEliminationCompetitorTreeGen   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 43
loc 43
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFighter() 4 4 1
A getFighters() 4 4 1
A syncGroup() 4 4 1
A createByeFighter() 4 4 1
A addFighterToGroup() 4 4 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\FightersGroup;
8
9 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...
10
{
11
    /**
12
     * get Fighter by Id.
13
     *
14
     * @param $competitorId
15
     *
16
     * @return Competitor
17
     */
18
    protected function getFighter($competitorId)
19
    {
20
        return Competitor::find($competitorId);
21
    }
22
23
    /**
24
     * Fighter is the name for competitor or team, depending on the case.
25
     *
26
     * @return Collection
27
     */
28
    protected function getFighters()
29
    {
30
        return $this->championship->competitors;
31
    }
32
33
    /**
34
     * @param $group
35
     * @param $fighters
36
     */
37
    public function syncGroup(FightersGroup $group, $fighters)
38
    {
39
        return $group->syncCompetitors($fighters);
40
    }
41
42
    protected function createByeFighter()
43
    {
44
        return new Competitor();
45
    }
46
47
    protected function addFighterToGroup(FightersGroup $group, $competitor)
48
    {
49
        $group->competitors()->attach($competitor->id);
50
    }
51
}
52