GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — develop ( 35624a...012a1d )
by Toby
05:53
created

LogicUserRoleRepository   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 74.19%

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 84
ccs 23
cts 31
cp 0.7419
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A logicGroupId() 0 7 2
A getRolesThroughUser() 0 3 1
A logicGroup() 0 4 1
A removeUserFromRole() 0 3 1
A getUsersThroughRole() 0 3 1
A hasLogicGroup() 0 3 1
A filter() 0 8 2
A addUserToRole() 0 3 1
A isInLogicGroup() 0 3 1
A __construct() 0 4 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\Module\AssignRoles\Support;
4
5
use BristolSU\ControlDB\Contracts\Models\Role;
6
use BristolSU\ControlDB\Contracts\Models\User;
7
use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole;
8
use BristolSU\Support\Logic\Contracts\LogicRepository;
9
use Illuminate\Support\Collection;
10
11
class LogicUserRoleRepository implements UserRole
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class LogicUserRoleRepository
Loading history...
12
{
13
14
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
15
     * @var UserRole
16
     */
17
    private $userRoleRepository;
0 ignored issues
show
Coding Style introduced by
Private member variable "userRoleRepository" must be prefixed with an underscore
Loading history...
18
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
     * @var \BristolSU\Support\Logic\Contracts\LogicTester
20
     */
21
    private $logicTester;
0 ignored issues
show
Coding Style introduced by
Private member variable "logicTester" must be prefixed with an underscore
Loading history...
22
23 17
    public function __construct(UserRole $userRoleRepository, \BristolSU\Support\Logic\Contracts\LogicTester $logicTester)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
24
    {
25 17
        $this->userRoleRepository = $userRoleRepository;
26 17
        $this->logicTester = $logicTester;
27 17
    }
28
    
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $role should have a doc-comment as per coding-style.
Loading history...
30
     * @inheritDoc
31
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
32 8
    public function getUsersThroughRole(Role $role): Collection
33
    {
34 8
        return $this->userRoleRepository->getUsersThroughRole($role);
35
    }
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
38
     * @inheritDoc
39
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
40 11
    public function getRolesThroughUser(User $user): Collection
41
    {
42 11
        return $this->filter($this->userRoleRepository->getRolesThroughUser($user));
43
    }
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $role should have a doc-comment as per coding-style.
Loading history...
46
     * @inheritDoc
47
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
48 2
    public function addUserToRole(User $user, Role $role): void
49
    {
50 2
        $this->userRoleRepository->addUserToRole($user, $role);
51 2
    }
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $role should have a doc-comment as per coding-style.
Loading history...
54
     * @inheritDoc
55
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
56 1
    public function removeUserFromRole(User $user, Role $role): void
57
    {
58 1
        $this->userRoleRepository->removeUserFromRole($user, $role);
59 1
    }
60
61 11
    private function hasLogicGroup()
0 ignored issues
show
Coding Style introduced by
Private method name "LogicUserRoleRepository::hasLogicGroup" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function hasLogicGroup()
Loading history...
62
    {
63 11
        return $this->logicGroupId() !== null;
64
    }
65
66 11
    private function logicGroupId()
0 ignored issues
show
Coding Style introduced by
Private method name "LogicUserRoleRepository::logicGroupId" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function logicGroupId()
Loading history...
67
    {
68 11
        $id = settings('logic_group', null);
69 11
        if($id === null) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
70 11
            return null;
71
        }
72
        return (int) $id;
73
    }
74
75
    private function logicGroup()
0 ignored issues
show
Coding Style introduced by
Private method name "LogicUserRoleRepository::logicGroup" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function logicGroup()
Loading history...
76
    {
77
        return app(LogicRepository::class)->getById(
78
            $this->logicGroupId()
0 ignored issues
show
Bug introduced by
It seems like $this->logicGroupId() can also be of type null; however, parameter $id of BristolSU\Support\Logic\...icRepository::getById() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
            /** @scrutinizer ignore-type */ $this->logicGroupId()
Loading history...
79
        );
80
    }
81
82
    private function isInLogicGroup(\BristolSU\ControlDB\Contracts\Models\Role $role)
0 ignored issues
show
Coding Style introduced by
Private method name "LogicUserRoleRepository::isInLogicGroup" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function isInLogicGroup()
Loading history...
83
    {
84
        return $this->logicTester->evaluate($this->logicGroup(), null, $role->group(), $role);
85
    }
86
87 11
    private function filter(Collection $roles)
0 ignored issues
show
Coding Style introduced by
Private method name "LogicUserRoleRepository::filter" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function filter()
Loading history...
88
    {
89 11
        if($this->hasLogicGroup()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
90
            return $roles->filter(function(\BristolSU\ControlDB\Contracts\Models\Role $role) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
91
                return $this->isInLogicGroup($role);
92
            })->values();
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
93
        }
94 11
        return $roles;
95
    }
96
}