Skip to content

Commit

Permalink
fix code smells for codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafamaklad committed Mar 17, 2018
1 parent 63adf2f commit 59bed27
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,16 @@ public function hasRole($roles, bool $strict = false): bool
}

if (\is_array($roles) || $roles instanceof Collection) {
$roles = \collect()->make($roles)->map(function ($role) {
$roles = \collect($roles)->map(function ($role) {
return $role instanceof Role ? $role->name : $role;
});

if ($strict) {
$hasRoles = $roles->intersect($this->roles->pluck('name')) == $roles;
} else {
$hasRoles = ! $roles->intersect($this->roles->pluck('name'))->isEmpty();
return $roles->intersect($this->roles->pluck('name'))->count() === $roles->count();
}
} else {
$hasRoles = $this->roles->contains('name', $roles->name?? $roles);
return ! $roles->intersect($this->roles->pluck('name'))->isEmpty();
}

return $hasRoles;
return $this->roles->contains('name', $roles->name?? $roles);
}

/**
Expand Down

0 comments on commit 59bed27

Please sign in to comment.