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
Pull Request — master (#13)
by Toby
16:48 queued 03:24
created

DataUser::getAllWhere()   A

Complexity

Conditions 6
Paths 3

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.1111
cc 6
nc 3
nop 1
crap 6
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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 17
    public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataUser
19
    {
20 17
        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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
45
     * @param DateTime|null $dob
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
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 4
    public function getAllWhere($attributes = []): Collection
67
    {
68 4
        $baseAttributes = $attributes;
69 4
        $additionalAttributes = [];
70 4
        foreach (\BristolSU\ControlDB\Models\DataUser::getAdditionalAttributes() as $property) {
71 2
            if (array_key_exists($property, $baseAttributes)) {
72 1
                $additionalAttributes[$property] = $baseAttributes[$property];
73 2
                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 4
            foreach($baseAttributes as $key => $value) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
78 4
                $query = $query->orWhere($key, 'LIKE', '%' . $value . '%');
79
            }
80 4
            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 3
            foreach ($additionalAttributes as $additionalAttribute => $value) {
83 1
                if ($dataUser->getAdditionalAttribute($additionalAttribute) !== $value) {
84 1
                    return false;
85
                }
86
            }
87 3
            return true;
88 4
        })->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
}