Completed
Push — develop ( 0bdcf1...3b506c )
by Enea
09:31 queued 08:05
created

Operator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 27
ccs 9
cts 10
cp 0.9
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
permissions() 0 1 ?
roles() 0 1 ?
A castToModel() 0 8 2
A dispatchEvent() 0 4 1
1
<?php
2
/**
3
 * Created on 13/02/18 by enea dhack.
4
 */
5
6
namespace Enea\Authorization\Operators;
7
8
use Enea\Authorization\Contracts\{
9
    Grantable, PermissionsOwner, RolesOwner
10
};
11
use Enea\Authorization\Events\Operation;
12
use Enea\Authorization\Exceptions\{
13
    GrantableIsNotValidModelException
14
};
15
use Illuminate\Contracts\Events\Dispatcher;
16
use Illuminate\Database\Eloquent\Model;
17
use Illuminate\Support\Collection;
18
19
abstract class Operator
20
{
21
    private $event;
22
23 34
    public function __construct(Dispatcher $event)
24
    {
25 34
        $this->event = $event;
26 34
    }
27
28
    abstract public function permissions(PermissionsOwner $owner, Collection $permissions): void;
29
30
    abstract public function roles(RolesOwner $owner, Collection $roles): void;
31
32 34
    protected function castToModel(Grantable $grantable): Model
33
    {
34 34
        if (! $grantable instanceof Model) {
35
            throw GrantableIsNotValidModelException::make($grantable);
36
        }
37
38 34
        return $grantable;
39
    }
40
41 34
    protected function dispatchEvent(Operation $operation): void
42
    {
43 34
        $this->event->dispatch($operation);
44 34
    }
45
}
46