Code Duplication    Length = 37-40 lines in 2 locations

app/Containers/Authorization/Tasks/CreatePermissionTask.php 1 location

@@ 16-52 (lines=37) @@
13
 *
14
 * @author  Mahmoud Zalt  <[email protected]>
15
 */
16
class CreatePermissionTask extends Task
17
{
18
19
    /**
20
     * @var  \App\Containers\Authorization\Data\Repositories\PermissionRepository
21
     */
22
    protected $repository;
23
24
    /**
25
     * CreatePermissionTask constructor.
26
     *
27
     * @param \App\Containers\Authorization\Data\Repositories\PermissionRepository $repository
28
     */
29
    public function __construct(PermissionRepository $repository)
30
    {
31
        $this->repository = $repository;
32
    }
33
34
    /**
35
     * @param string      $name
36
     * @param string|null $description
37
     * @param string|null $displayName
38
     *
39
     * @return Permission
40
     * @throws CreateResourceFailedException
41
     */
42
    public function run(string $name, string $description = null, string $displayName = null): Permission
43
    {
44
        app()['cache']->forget('spatie.permission.cache');
45
46
        try {
47
            $permission = $this->repository->create([
48
                'name'         => $name,
49
                'description'  => $description,
50
                'display_name' => $displayName,
51
                'guard_name'   => 'web',
52
            ]);
53
        } catch (Exception $exception) {
54
            throw new CreateResourceFailedException();
55
        }

app/Containers/Authorization/Tasks/CreateRoleTask.php 1 location

@@ 16-55 (lines=40) @@
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class CreateRoleTask extends Task
17
{
18
19
    /**
20
     * @var  \App\Containers\Authorization\Data\Repositories\RoleRepository
21
     */
22
    protected $repository;
23
24
    /**
25
     * CreateRoleTask constructor.
26
     *
27
     * @param \App\Containers\Authorization\Data\Repositories\RoleRepository $repository
28
     */
29
    public function __construct(RoleRepository $repository)
30
    {
31
        $this->repository = $repository;
32
    }
33
34
    /**
35
     * @param string      $name
36
     * @param string|null $description
37
     * @param string|null $displayName
38
     * @param int         $level
39
     *
40
     * @return Role
41
     * @throws CreateResourceFailedException
42
     */
43
    public function run(string $name, string $description = null, string $displayName = null, int $level = 0): Role
44
    {
45
        app()['cache']->forget('spatie.permission.cache');
46
47
        try {
48
            $role = $this->repository->create([
49
                'name'         => strtolower($name),
50
                'description'  => $description,
51
                'display_name' => $displayName,
52
                'guard_name'   => 'web',
53
                'level'        => $level,
54
            ]);
55
        } catch (Exception $exception) {
56
            throw new CreateResourceFailedException();
57
        }
58