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

Authorizer::canAny()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 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