Permission   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 32
dl 0
loc 73
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A service() 0 3 1
A getAreaSelected() 0 19 4
A getArea() 0 33 4
A role() 0 3 1
1
<?php namespace Distilleries\Expendable\Models;
2
3
class Permission extends BaseModel {
4
5
    protected $fillable = [
6
        'id',
7
        'role_id',
8
        'service_id'
9
    ];
10
11
12 2
    public function role()
13
    {
14 2
        return $this->belongsTo('Distilleries\Expendable\Models\Role');
15
    }
16
17 6
    public function service()
18
    {
19 6
        return $this->belongsTo('Distilleries\Expendable\Models\Service');
20
    }
21
22 6
    public function getArea()
23
    {
24 6
        $roles    = Role::all();
25 6
        $services = Service::orderBy('action')->get();
26 6
        $services = $services->toArray();
27
28 6
        $groupedServices = [];
29
30 6
        foreach ($services as $service)
31
        {
32 6
            $actions = preg_split('/@/', $service['action']);
0 ignored issues
show
Bug introduced by
It seems like $service['action'] can also be of type Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $subject of preg_split() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

32
            $actions = preg_split('/@/', /** @scrutinizer ignore-type */ $service['action']);
Loading history...
33
34 6
            if (count($actions) >= 2)
0 ignored issues
show
Bug introduced by
It seems like $actions can also be of type false; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

34
            if (count(/** @scrutinizer ignore-type */ $actions) >= 2)
Loading history...
35
            {
36 2
                $groupedServices[$actions[0]][] = [
37 2
                    'id'      => $service['id'],
38 2
                    'libelle' => $actions[1]
39
                ];
40
            }
41
42
        }
43
44 6
        $result = [];
45 6
        foreach ($roles as $role)
46
        {
47 6
            $result[] = [
48 6
                'libelle' => $role->libelle,
0 ignored issues
show
Bug introduced by
The property libelle does not seem to exist on Distilleries\Expendable\Models\Role. 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...
49 6
                'id'      => $role->id,
50 6
                'choices' => $groupedServices
51
            ];
52
        }
53
54 6
        return $result;
55
    }
56
57 6
    public function getAreaSelected()
58
    {
59 6
        $roles  = Role::get();
60 6
        $result = [];
61
62 6
        foreach ($roles as $role)
63
        {
64 6
            if (empty($result[$role->id]))
65
            {
66 6
                $result[$role->id] = [];
67
            }
68
69 6
            foreach ($role->permissions as $permission)
70
            {
71 6
                $result[$role->id][] = $permission->service_id;
72
            }
73
        }
74
75 6
        return $result;
76
    }
77
}