ExistsAndDeletePermission::make()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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