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.

DataGroup::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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

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

94
        $dataGroup = $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...
95 6
            'name' => $name, 'email' => $email
96
        ]);
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...
97 6
        $dataGroup->save();
98 6
        return $dataGroup;
99
    }
100
}