Passed
Push — master ( 6bbf15...aead9d )
by Jonathan
19:29
created

Role::users()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Uccello\Core\Models;
4
5
use Illuminate\Database\Eloquent\SoftDeletes;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\SoftDeletes was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Spatie\Searchable\Searchable;
0 ignored issues
show
Bug introduced by
The type Spatie\Searchable\Searchable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Spatie\Searchable\SearchResult;
0 ignored issues
show
Bug introduced by
The type Spatie\Searchable\SearchResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Uccello\Core\Database\Eloquent\Model;
9
use Uccello\Core\Support\Traits\UccelloModule;
10
11
class Role extends Model implements Searchable
12
{
13
    use SoftDeletes;
14
    use UccelloModule;
15
16
    /**
17
     * The table associated with the model.
18
     *
19
     * @var string
20
     */
21
    protected $table = 'roles';
22
23
    /**
24
     * The attributes that should be mutated to dates.
25
     *
26
     * @var array
27
     */
28
    protected $dates = [ 'deleted_at' ];
29
30
    /**
31
     * The attributes that are mass assignable.
32
     *
33
     * @var array
34
     */
35
    protected $fillable = [
36
        'name',
37
        'description',
38
        'parent_id',
39
        'domain_id'
40
    ];
41
42
    public $searchableType = 'role';
43
44
    public $searchableColumns = [
45
        'name'
46
    ];
47
48
    public function getSearchResult(): SearchResult
49
    {
50
        return new SearchResult(
51
            $this,
52
            $this->recordLabel
53
        );
54
    }
55
56
    protected function initTablePrefix()
57
    {
58
        $this->tablePrefix = env('UCCELLO_TABLE_PREFIX', 'uccello_');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $this->tablePrefix = /** @scrutinizer ignore-call */ env('UCCELLO_TABLE_PREFIX', 'uccello_');
Loading history...
59
    }
60
61
    public function parent()
62
    {
63
        return $this->belongsTo(static::class);
64
    }
65
66
    public function children()
67
    {
68
        return $this->hasMany(static::class);
69
    }
70
71
    public function domain()
72
    {
73
        return $this->belongsTo(Domain::class);
74
    }
75
76
    public function privileges()
77
    {
78
        return $this->hasMany(Privilege::class);
79
    }
80
81
    public function profiles()
82
    {
83
        return $this->belongsToMany(Profile::class, $this->tablePrefix.'profiles_roles');
84
    }
85
86
    public function users()
87
    {
88
        return $this->belongsToMany(User::class, 'uccello_privileges');
89
    }
90
91
    /**
92
     * Returns record label
93
     *
94
     * @return string
95
     */
96
    public function getRecordLabelAttribute() : string
97
    {
98
        return $this->name;
99
    }
100
}
101