Completed
Push — develop ( c127f1...97f65e )
by Enea
03:21
created

Authorizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAny() 0 3 1
A canAny() 0 3 1
A any() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author enea dhack <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Enea\Authorization\Drivers\Cache;
13
14
use Closure;
15
use Enea\Authorization\Contracts\PermissionsOwner;
16
use Enea\Authorization\Contracts\RolesOwner;
17
use Enea\Authorization\Drivers\Authorizer as BaseAuthorizer;
18
19
class Authorizer extends BaseAuthorizer
20
{
21
    private $database;
22
23 5
    public function __construct(Database $database)
24
    {
25 5
        $this->database = $database;
26 5
    }
27
28 3
    public function canAny(PermissionsOwner $owner, array $permissions): bool
29
    {
30 3
        return $this->database->permissions($owner)->contains($this->any($permissions));
31
    }
32
33 2
    public function isAny(RolesOwner $owner, array $roles): bool
34
    {
35 2
        return $this->database->roles($owner)->contains($this->any($roles));
36
    }
37
38
    private function any(array $authorizations): Closure
39
    {
40 5
        return function (Authorization $authorization) use ($authorizations): bool {
41 5
            return in_array($authorization->getName(), $authorizations);
42 5
        };
43
    }
44
}
45