Completed
Push — master ( 7e54ec...8b45a6 )
by Vojta
9s
created

Category   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A scopeIsEnabled() 0 4 1
1
<?php namespace VojtaSvoboda\Reviews\Models;
2
3
use Model;
4
use October\Rain\Database\Traits\SoftDelete as SoftDeletingTrait;
5
use October\Rain\Database\Traits\Sortable as SortableTrait;
6
use October\Rain\Database\Traits\Validation as ValidationTrait;
7
8
class Category extends Model
9
{
10
    use SoftDeletingTrait;
11
12
    use SortableTrait;
13
14
    use ValidationTrait;
15
16
    public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
17
18
    public $table = 'vojtasvoboda_reviews_categories';
19
20
    public $rules = [
21
        'name' => 'required|max:255',
22
        'slug' => 'required|unique:vojtasvoboda_reviews_categories',
23
        'enabled' => 'boolean',
24
        'description' => 'max:10000',
25
    ];
26
27
    public $translatable = ['name', 'slug', 'description'];
28
29
    public $dates = ['created_at', 'updated_at', 'deleted_at'];
30
31
    public $attachOne = [
32
        'image' => ['System\Models\File'],
33
    ];
34
35
    public $belongsToMany = [
36
        'reviews' => ['VojtaSvoboda\Reviews\Models\Review',
37
            'table' => 'vojtasvoboda_reviews_review_category',
38
            'order' => 'name desc',
39
            'scope' => 'isEnabled',
40
            'timestamps' => true,
41
        ],
42
    ];
43
44
    public function scopeIsEnabled($query)
45
    {
46
        return $query->where('enabled', true);
47
    }
48
}
49