Completed
Push — b0.25.0 ( b1670c...6acf42 )
by Sebastian
05:31
created

PermissionTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 23
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A can() 0 9 3
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Authorization;
13
14
/**
15
 * User PermissionTrait.
16
 */
17
trait PermissionTrait
18
{
19
    /**
20
     * @var array User permissions
21
     */
22
    protected $permission = [];
23
24
    /**
25
     * Check Permission.
26
     *
27
     * @param string $permission
28
     *
29
     * @return bool
30
     */
31
    public function can(string $permission): bool
32
    {
33
        foreach ($this->permission as $ownPermission) {
34
            if ($ownPermission->name === $permission) {
35
                return true;
36
            }
37
        }
38
39
        return false;
40
    }
41
}
42