ExistsAndDeletePermission   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 0 16 3
1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Permissions\Features;
4
5
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionDoesNotExistsException;
6
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionIsAttachedException;
7
use Omatech\Mage\Core\Domains\Permissions\Jobs\AttachedPermission;
8
use Omatech\Mage\Core\Domains\Permissions\Jobs\DeletePermission;
9
use Omatech\Mage\Core\Domains\Permissions\Jobs\ExistsPermission;
10
use Omatech\Mage\Core\Domains\Permissions\Permission;
11
12
class ExistsAndDeletePermission
13
{
14
    private $exists;
15
    private $attached;
16
    private $delete;
17
18
    /**
19
     * ExistsAndDeletePermission constructor.
20
     */
21 4
    public function __construct()
22
    {
23 4
        $this->exists = new ExistsPermission();
24 4
        $this->attached = new AttachedPermission();
25 4
        $this->delete = new DeletePermission();
26 4
    }
27
28
    /**
29
     * @param Permission $permission
30
     * @return bool
31
     * @throws PermissionDoesNotExistsException
32
     * @throws PermissionIsAttachedException
33
     */
34 4
    public function make(Permission $permission): bool
35
    {
36 4
        $exists = $this->exists->make($permission);
37
38 4
        if (false === $exists) {
39 1
            throw new PermissionDoesNotExistsException();
40
        }
41
42 4
        $attached = $this->attached->make($permission);
43
44 4
        if (true === $attached) {
45 1
            throw new PermissionIsAttachedException();
46
        }
47
48 3
        return $this->delete->make($permission);
49
    }
50
}
51