Completed
Push — master ( d86698...3d0fab )
by
unknown
03:08
created

DeleteRoleTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Containers\Authorization\Tasks;
4
5
use App\Containers\Authorization\Data\Repositories\RoleRepository;
6
use App\Containers\Authorization\Models\Role;
7
use App\Ship\Exceptions\DeleteResourceFailedException;
8
use App\Ship\Parents\Tasks\Task;
9
use Exception;
10
11
/**
12
 * Class DeleteRoleTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class DeleteRoleTask extends Task
17
{
18
19
    protected $repository;
20
21
    public function __construct(RoleRepository $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    /**
27
     * @param Integer|Role $role
28
     *
29
     * @return bool
30
     * @throws DeleteResourceFailedException
31
     */
32
    public function run($role): bool
33
    {
34
        if ($role instanceof Role) {
35
            $role = $role->id;
36
        }
37
38
        // delete the record from the roles table.
39
        try {
40
            return $this->repository->delete($role);
41
        }
42
        catch (Exception $exception) {
43
            throw new DeleteResourceFailedException();
44
        }
45
    }
46
}
47