Completed
Branch develop-3.0 (4fe777)
by Mohamed
11:06
created

FetchRoleTrait::getRoleNameDropdown()   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 0
1
<?php
2
/*
3
 * This file is part of the site package.
4
 *
5
 * (c) Mohamed Alsharaf <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Tinyissue\Extensions\Model;
12
13
use Illuminate\Database\Eloquent\Collection;
14
use Tinyissue\Contracts\Repository\Role\RoleRepository;
15
16
/**
17
 * FetchRoleTrait is trait class contains method to set and fetch roles.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
trait FetchRoleTrait
22
{
23
    /**
24
     * Collection of all tags.
25
     *
26
     * @var Collection
27
     */
28
    protected $roles = null;
29
30
    /**
31
     * @var RoleRepository
32
     */
33
    protected $roleRepository;
34
35
    public function setRoleRepository(RoleRepository $roleRepository)
36
    {
37
        $this->roleRepository = $roleRepository;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return TagRepository
44
     */
45
    public function getRoleRepository()
46
    {
47
        if (is_null($this->roleRepository) && property_exists($this, 'app')) {
48
            $this->roleRepository = $this->app->make(RoleRepository::class);
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49
        }
50
51
        return $this->roleRepository;
52
    }
53
54
    /**
55
     * @return Collection
56
     */
57
    protected function getRoleNameDropdown()
58
    {
59
        return $this->getRoleRepository()->getNameDropdown();
60
    }
61
}
62