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.

PositionCanBeUsed::passes()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
crap 3.0987
rs 9.9332
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\Module\AssignRoles\Rules;
4
5
use BristolSU\ControlDB\Contracts\Repositories\Role;
6
use BristolSU\Module\AssignRoles\Support\PositionSettingRetrieval;
7
use BristolSU\Support\Authentication\Contracts\Authentication;
8
use BristolSU\Support\Logic\Contracts\LogicRepository;
9
use BristolSU\Support\Logic\Facade\LogicTester;
10
use Illuminate\Contracts\Validation\Rule;
11
12
class PositionCanBeUsed implements Rule
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PositionCanBeUsed
Loading history...
13
{
14
15
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
16
     * @var PositionSettingRetrieval
17
     */
18
    private $positionSettingRetrieval;
0 ignored issues
show
Coding Style introduced by
Private member variable "positionSettingRetrieval" must be prefixed with an underscore
Loading history...
19
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
     * @var Role
21
     */
22
    private $roleRepository;
0 ignored issues
show
Coding Style introduced by
Private member variable "roleRepository" must be prefixed with an underscore
Loading history...
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
     * @var Authentication
25
     */
26
    private $authentication;
0 ignored issues
show
Coding Style introduced by
Private member variable "authentication" must be prefixed with an underscore
Loading history...
27
28 11
    public function __construct(PositionSettingRetrieval $positionSettingRetrieval, Role $roleRepository, Authentication $authentication)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
29
    {
30 11
        $this->positionSettingRetrieval = $positionSettingRetrieval;
31 11
        $this->roleRepository = $roleRepository;
32 11
        $this->authentication = $authentication;
33 11
    }
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $attribute should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
36
     * @inheritDoc
37
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
38 10
    public function passes($attribute, $value)
39
    {
40
        try {
41 10
            $settings = $this->positionSettingRetrieval->getSettings($this->group());
0 ignored issues
show
Bug introduced by
It seems like $this->group() can also be of type null; however, parameter $group of BristolSU\Module\AssignR...etrieval::getSettings() does only seem to accept BristolSU\ControlDB\Contracts\Models\Group, 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

41
            $settings = $this->positionSettingRetrieval->getSettings(/** @scrutinizer ignore-type */ $this->group());
Loading history...
42
        } catch (\Exception $e) {
43
            return false;
44
        }
45 10
        if(in_array($value, $settings['only_one_role'])) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
46 3
            $roles = $this->roleRepository->allThroughGroup($this->group());
0 ignored issues
show
Bug introduced by
It seems like $this->group() can also be of type null; however, parameter $group of BristolSU\ControlDB\Cont...Role::allThroughGroup() does only seem to accept BristolSU\ControlDB\Contracts\Models\Group, 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

46
            $roles = $this->roleRepository->allThroughGroup(/** @scrutinizer ignore-type */ $this->group());
Loading history...
47
            
48
            return $roles->filter(function(\BristolSU\ControlDB\Contracts\Models\Role $role) use ($value) {
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...
49 1
                return $role->positionId() === (int) $value;
50 3
            })->count() === 0;
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...
51
        }
52 7
        return true;
53
    }
54
55 10
    protected function group()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function group()
Loading history...
56
    {
57 10
        return $this->authentication->getGroup();
58
    }
59
    
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @inheritDoc
62
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
63 1
    public function message()
64
    {
65 1
        return 'The position has already been used in another role';
66
    }
67
}