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.

DataUser::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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

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

104
        $dataUser = $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...
105 9
            'first_name' => $firstName,
106 9
            'last_name' => $lastName,
107 9
            'email' => $email,
108 9
            'dob' => $dob,
109 9
            'preferred_name' => $preferredName
110
        ]);
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...
111 9
        $dataUser->save();
112 9
        return $dataUser;
113
    }
114
}