Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
2 / 3
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Permissions
66.67% covered (warning)
66.67%
2 / 3
66.67% covered (warning)
66.67%
2 / 3
3.33
0.00% covered (danger)
0.00%
0 / 1
 add
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 has
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray;
6
7class Permissions
8{
9    protected array $permissions = [
10        'superuser' => [
11            'superuser',
12            'admin',
13            'editor',
14            'panel',
15            'edit-settings',
16            'edit-users',
17            'edit-pages',
18            'edit-blocks',
19            'authenticated',
20        ],
21        'admin' => [
22            'admin',
23            'editor',
24            'panel',
25            'edit-users',
26            'edit-pages',
27            'edit-blocks',
28            'authenticated',
29        ],
30        'editor' => [
31            'editor',
32            'panel',
33            'edit-pages',
34            'edit-blocks',
35            'authenticated',
36        ],
37    ];
38
39    public function add(string $role, string $permission)
40    {
41        $this->permissions[$role][] = $permission;
42    }
43
44    public function has(string $role, string $permission): bool
45    {
46        return in_array($permission, $this->permissions[$role] ?? [], true);
47    }
48
49    public function get(string $role): array
50    {
51        return $this->permissions[$role] ?? [];
52    }
53}