Capability::getPackageAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Uccello\Core\Models;
4
5
use Uccello\Core\Database\Eloquent\Model;
6
7
class Capability extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'capabilities';
15
16
    /**
17
     * The attributes that should be casted to native types.
18
     *
19
     * @var array
20
     */
21
    protected $casts = [
22
        'data' => 'object',
23
    ];
24
25
    /**
26
     * The attributes that are mass assignable.
27
     *
28
     * @var array
29
     */
30
    protected $fillable = [
31
        'name',
32
        'data',
33
    ];
34
35
    protected function initTablePrefix()
36
    {
37
        $this->tablePrefix = env('UCCELLO_TABLE_PREFIX', 'uccello_');
38
    }
39
40
    public function permissions()
41
    {
42
        return $this->hasMany(Permission::class);
43
    }
44
45
    /**
46
     * Returns module package name
47
     *
48
     * @return string|null
49
     */
50
    public function getPackageAttribute() : ?string
51
    {
52
        $package = ''; // For modules created directory in the host application
53
54
        // Get only package name if defined (Format: vendor/package)
55
        if (isset($this->data->package))
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\Capability. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
        {
57
            $packageData = explode('/', $this->data->package);
58
            $package = array_pop($packageData);
59
        }
60
61
        return $package;
62
    }
63
}
64