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.

DataRole   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 29
c 1
b 0
f 0
dl 0
loc 91
ccs 31
cts 31
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllWhere() 0 23 6
A getWhere() 0 8 2
A getById() 0 3 1
A create() 0 5 1
A update() 0 7 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
namespace BristolSU\ControlDB\Repositories;
5
6
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Illuminate\Support\Collection;
9
10
class DataRole implements \BristolSU\ControlDB\Contracts\Repositories\DataRole
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DataRole
Loading history...
11
{
12
13
    /**
14
     * Get a data role by ID
15
     *
16
     * @param int $id
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
17
     * @return \BristolSU\ControlDB\Contracts\Models\DataRole
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
18
     */
19 22
    public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataRole
20
    {
21 22
        return \BristolSU\ControlDB\Models\DataRole::findOrFail($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return BristolSU\Control...taRole::findOrFail($id) could return the type null which is incompatible with the type-hinted return BristolSU\ControlDB\Contracts\Models\DataRole. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * Get a data role with the given attributes, including additional attributes.
26
     *
27
     * @param array $attributes
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
28
     * @return \BristolSU\ControlDB\Contracts\Models\DataRole
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
29
     */
30 3
    public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataRole
31
    {
32 3
        $roles = $this->getAllWhere($attributes);
33
34 3
        if($roles->count() > 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
35 2
            return $roles->first();
36
        }
37 1
        throw (new ModelNotFoundException())->setModel(DataRole::class);
38
    }
39
40
    /**
41
     * Create a new data role
42
     *
43
     * @param string|null $roleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
44
     * @param string|null $email
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @return \BristolSU\ControlDB\Contracts\Models\DataRole
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
46
     */
47 5
    public function create(?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole
48
    {
49 5
        return \BristolSU\ControlDB\Models\DataRole::create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return BristolSU\Control...me, 'email' => $email)) could return the type null which is incompatible with the type-hinted return BristolSU\ControlDB\Contracts\Models\DataRole. Consider adding an additional type-check to rule them out.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
50 5
            'role_name' => $roleName,
51 5
            'email' => $email,
52
        ]);
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...
53
    }
54
55
    /**
56
     * Get all data roles where the given attributes match, including additional attributes.
57
     *
58
     * @param array $attributes
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
59
     * @return Collection
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
60
     */
61 6
    public function getAllWhere($attributes = []): Collection
62
    {
63 6
        $baseAttributes = $attributes;
64 6
        $additionalAttributes = [];
65 6
        foreach (\BristolSU\ControlDB\Models\DataRole::getAdditionalAttributes() as $property) {
66 2
            if (array_key_exists($property, $baseAttributes)) {
67 1
                $additionalAttributes[$property] = $baseAttributes[$property];
68 1
                unset($baseAttributes[$property]);
69
            }
70
        }
71
        return \BristolSU\ControlDB\Models\DataRole::where(function($query) use ($baseAttributes) {
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...
72 6
            foreach($baseAttributes as $key => $value) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
73 6
                $query = $query->where($key, 'LIKE', '%' . $value . '%');
74
            }
75 6
            return $query;
76
        })->get()->filter(function (\BristolSU\ControlDB\Models\DataRole $dataRole) use ($additionalAttributes) {
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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
77 5
            foreach ($additionalAttributes as $additionalAttribute => $value) {
78 1
                if ($dataRole->getAdditionalAttribute($additionalAttribute) !== $value) {
79 1
                    return false;
80
                }
81
            }
82 5
            return true;
83 6
        })->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...
84
    }
85
86
    /**
87
     * Update a data position with the given attributes
88
     *
89
     * @param int $id
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
90
     * @param string|null $roleName Custom name for the role
91
     * @param string|null $email Email of the role
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
92
     * @return \BristolSU\ControlDB\Contracts\Models\DataRole
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
93
     */
94 6
    public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole
95
    {
96 6
        $dataRole = $this->getById($id)->fill([
0 ignored issues
show
Bug introduced by
The method fill() does not exist on BristolSU\ControlDB\Contracts\Models\DataRole. Since it exists in all sub-types, consider adding an abstract or default implementation to BristolSU\ControlDB\Contracts\Models\DataRole. ( Ignorable by Annotation )

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

96
        $dataRole = $this->getById($id)->/** @scrutinizer ignore-call */ fill([
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
97 6
            'role_name' => $roleName, 'email' => $email
98
        ]);
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...
99 6
        $dataRole->save();
100 6
        return $dataRole;
101
    }
102
}