Team   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 29.09 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 16
loc 55
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A teamMembers() 0 4 1
A tournamentTeams() 0 4 1
A addTeam() 16 16 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 App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use App\Http\Requests\Request;
7
use Illuminate\Support\Facades\File;
8
use Illuminate\Support\Facades\Storage;
9
10
/**
11
 * Class Team
12
 * @package App
13
 */
14
class Team extends Model
15
{
16
17
    /**
18
     * @var string
19
     */
20
    protected $table = 'teams';
21
22
    /**
23
     * @var array
24
     */
25
    protected $fillable = ['name', 'logoPath', 'leagueId'];
26
27
    /**
28
     * @var bool
29
     */
30
    public $timestamps = true;
31
32
    /**
33
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
34
     */
35
    public function teamMembers()
36
    {
37
        return $this->hasMany(Member::class, 'teamId');
38
    }
39
40
    /**
41
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
42
     */
43
    public function tournamentTeams()
44
    {
45
        return $this->hasMany(TournamentTeam::class, 'teamId');
46
    }
47
48
    /**
49
     * @param $request
50
     * @return static
51
     */
52 View Code Duplication
    public function addTeam($request)
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        $mime = $request->leagueTeam['logo']->getMimeType();
55
        $mime = explode('/', $mime);
56
        $fileName = $request->leagueTeam['name'] . '.' . $mime[1];
57
58
        Storage::disk('public')->putFileAs('teams-logo/', $request->leagueTeam['logo'], $fileName);
59
60
        $team = Team::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on App\Team. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
            'leagueId' => $request->leagueTeam['leagueId'],
62
            'name' => $request->leagueTeam['name'],
63
            'logoPath' => 'teams-logo/' . $fileName,
64
        ]);
65
66
        return $team;
67
    }
68
}
69