HasRoles::removeRole()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Merodiro\SimpleRoles;
4
5
trait HasRoles
6
{
7 8 View Code Duplication
    public function hasRole($role)
0 ignored issues
show
Duplication introduced by
This method 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...
8
    {
9 8
        $roles = config('simple_roles.roles');
10 8
        if (!array_key_exists($role, $roles)) {
11
            throw new Exception("Role doesn't exist");
12
        }
13
14 8
        return $this->role == $roles[$role];
0 ignored issues
show
Bug introduced by
The property role 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...
15
    }
16
17 6 View Code Duplication
    public function setRole($role)
0 ignored issues
show
Duplication introduced by
This method 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...
18
    {
19 6
        $roles = config('simple_roles.roles');
20 6
        if (!array_key_exists($role, $roles)) {
21
            throw new Exception("Role doesn't exist");
22
        }
23
24 6
        $this->role = $roles[$role];
25 6
    }
26
27 2
    public function removeRole()
28
    {
29 2
        $this->role = 0;
30 2
    }
31
}
32