Passed
Push — master ( 2c144a...cc2b65 )
by Christian
03:20
created

ExistsAndDeletePermission::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Permissions\Features;
4
5
use Omatech\Mage\Core\Domains\Permissions\Permission;
6
use Omatech\Mage\Core\Domains\Permissions\Jobs\DeletePermission;
7
use Omatech\Mage\Core\Domains\Permissions\Jobs\ExistsPermission;
8
use Omatech\Mage\Core\Domains\Permissions\Jobs\AttachedPermission;
9
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionIsAttachedException;
10
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionDoesNotExistsException;
11
12
class ExistsAndDeletePermission
13
{
14
    private $exists;
15
    private $attached;
16
    private $delete;
17
18
    /**
19
     * ExistsAndDeletePermission constructor.
20
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
21
     */
22 3
    public function __construct()
23
    {
24 3
        $this->exists = app()->make(ExistsPermission::class);
25 3
        $this->attached = app()->make(AttachedPermission::class);
26 3
        $this->delete = app()->make(DeletePermission::class);
27 3
    }
28
29
    /**
30
     * @param Permission $permission
31
     * @return bool
32
     * @throws PermissionDoesNotExistsException
33
     * @throws PermissionIsAttachedException
34
     */
35 3 View Code Duplication
    public function make(Permission $permission): bool
36
    {
37 3
        $exists = $this->exists->make($permission);
38
39 3
        if ($exists === false) {
40 1
            throw new PermissionDoesNotExistsException;
41
        }
42
43 3
        $attached = $this->attached->make($permission);
44
45 3
        if ($attached === true) {
46 1
            throw new PermissionIsAttachedException;
47
        }
48
49 2
        return $this->delete->make($permission);
50
    }
51
}
52