GetRoleTask::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
rs 10
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\Ship\Parents\Tasks\Task;
7
8
/**
9
 * Class GetRoleTask.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13 View Code Duplication
class GetRoleTask extends Task
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
16
    /**
17
     * @var  \App\Containers\Authorization\Data\Repositories\RoleRepository
18
     */
19
    private $roleRepository;
20
21
    /**
22
     * GetAdminRoleTask constructor.
23
     *
24
     * @param \App\Containers\Authorization\Data\Repositories\RoleRepository $roleRepository
25
     */
26
    public function __construct(RoleRepository $roleRepository)
27
    {
28
        $this->roleRepository = $roleRepository;
29
    }
30
31
    /**
32
     * @param Integer|String $roleNameOrId
33
     *
34
     * @return  mixed
35
     */
36
    public function run($roleNameOrId)
37
    {
38
        $query = ['id' => $roleNameOrId];
39
40
        if (!is_numeric($roleNameOrId)) {
41
            $query = ['name' => $roleNameOrId];
42
        }
43
44
        return $this->roleRepository->findWhere($query)->first();
45
    }
46
47
}
48