Completed
Pull Request — master (#34)
by Fèvre
06:24 queued 03:17
created

DiscussCategory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 9 9 1
A slugStrategy() 4 4 1
A threads() 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
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\Sluggable;
5
use Xetaravel\Models\Presenters\DiscussCategoryPresenter;
6
7 View Code Duplication
class DiscussCategory extends Model
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...
8
{
9
    use Sluggable,
10
        DiscussCategoryPresenter;
11
12
    /**
13
     * The accessors to append to the model's array form.
14
     *
15
     * @var array
16
     */
17
    protected $appends = [
18
        'category_url'
19
    ];
20
21
    /**
22
     * The "booting" method of the model.
23
     *
24
     * @return void
25
     */
26
    protected static function boot()
27
    {
28
        parent::boot();
29
30
        // Generated the slug before updating.
31
        static::updating(function ($model) {
32
            $model->generateSlug();
33
        });
34
    }
35
36
    /**
37
     * Return the field to slug.
38
     *
39
     * @return string
40
     */
41
    public function slugStrategy(): string
42
    {
43
        return 'title';
44
    }
45
46
    /**
47
     * Get the threads for the category.
48
     *
49
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
50
     */
51
    public function threads()
52
    {
53
        return $this->hasMany(DiscussThread::class);
54
    }
55
}
56