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

app/Support/LogicUserRoleRepository.php (8 issues)

1
<?php
2
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
Missing doc comment for class LogicUserRoleRepository
Loading history...
12
{
13
14
    /**
15
     * @var UserRole
16
     */
17
    private $userRoleRepository;
18
    /**
19
     * @var \BristolSU\Support\Logic\Contracts\LogicTester
20
     */
21
    private $logicTester;
22
23 17
    public function __construct(UserRole $userRoleRepository, \BristolSU\Support\Logic\Contracts\LogicTester $logicTester)
24
    {
25 17
        $this->userRoleRepository = $userRoleRepository;
26 17
        $this->logicTester = $logicTester;
27 17
    }
28
    
29
    /**
30
     * @inheritDoc
31
     */
32 8
    public function getUsersThroughRole(Role $role): Collection
33
    {
34 8
        return $this->userRoleRepository->getUsersThroughRole($role);
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40 11
    public function getRolesThroughUser(User $user): Collection
41
    {
42 11
        return $this->filter($this->userRoleRepository->getRolesThroughUser($user));
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48 2
    public function addUserToRole(User $user, Role $role): void
49
    {
50 2
        $this->userRoleRepository->addUserToRole($user, $role);
51 2
    }
52
53
    /**
54
     * @inheritDoc
55
     */
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
Private method name "LogicUserRoleRepository::hasLogicGroup" must be prefixed with an underscore
Loading history...
62
    {
63 11
        return $this->logicGroupId() !== null;
64
    }
65
66 11
    private function logicGroupId()
0 ignored issues
show
Private method name "LogicUserRoleRepository::logicGroupId" must be prefixed with an underscore
Loading history...
67
    {
68 11
        $id = settings('logic_group', null);
69 11
        if($id === null) {
0 ignored issues
show
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
Private method name "LogicUserRoleRepository::logicGroup" must be prefixed with an underscore
Loading history...
76
    {
77
        return app(LogicRepository::class)->getById(
78
            $this->logicGroupId()
0 ignored issues
show
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
Private method name "LogicUserRoleRepository::isInLogicGroup" must be prefixed with an underscore
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
Private method name "LogicUserRoleRepository::filter" must be prefixed with an underscore
Loading history...
88
    {
89 11
        if($this->hasLogicGroup()) {
90
            return $roles->filter(function(\BristolSU\ControlDB\Contracts\Models\Role $role) {
91
                return $this->isInLogicGroup($role);
92
            })->values();
93
        }
94 11
        return $roles;
95
    }
96
}