ExistsAndDeleteRole::__construct()   A
last analyzed

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\Roles\Features;
4
5
use Omatech\Mage\Core\Domains\Roles\Exceptions\RoleDoesNotExistsException;
6
use Omatech\Mage\Core\Domains\Roles\Exceptions\RoleIsAttachedException;
7
use Omatech\Mage\Core\Domains\Roles\Jobs\AttachedRole;
8
use Omatech\Mage\Core\Domains\Roles\Jobs\DeleteRole;
9
use Omatech\Mage\Core\Domains\Roles\Jobs\ExistsRole;
10
use Omatech\Mage\Core\Domains\Roles\Role;
11
12
class ExistsAndDeleteRole
13
{
14
    private $exists;
15
    private $attached;
16
    private $delete;
17
18
    /**
19
     * ExistsAndDeleteRole constructor.
20
     */
21 4
    public function __construct()
22
    {
23 4
        $this->exists = new ExistsRole();
24 4
        $this->attached = new AttachedRole();
25 4
        $this->delete = new DeleteRole();
26 4
    }
27
28
    /**
29
     * @param Role $role
30
     * @return bool
31
     * @throws RoleDoesNotExistsException
32
     * @throws RoleIsAttachedException
33
     */
34 4
    public function make(Role $role): bool
35
    {
36 4
        $exists = $this->exists->make($role);
37
38 4
        if (false === $exists) {
39 1
            throw new RoleDoesNotExistsException();
40
        }
41
42 4
        $attached = $this->attached->make($role);
43
44 4
        if (true === $attached) {
45 1
            throw new RoleIsAttachedException();
46
        }
47
48 3
        return $this->delete->make($role);
49
    }
50
}
51