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.

DataPosition   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 create() 0 5 1
A getById() 0 3 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 DataPosition implements \BristolSU\ControlDB\Contracts\Repositories\DataPosition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DataPosition
Loading history...
11
{
12
13
    /**
14
     * Get a data position 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\DataPosition
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
18
     */
19 17
    public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataPosition
20
    {
21 17
        return \BristolSU\ControlDB\Models\DataPosition::findOrFail($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return BristolSU\Control...sition::findOrFail($id) could return the type null which is incompatible with the type-hinted return BristolSU\ControlDB\Contracts\Models\DataPosition. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * Get a data position 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\DataPosition
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\DataPosition
31
    {
32 3
        $positions = $this->getAllWhere($attributes);
33
34 3
        if($positions->count() > 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
35 2
            return $positions->first();
36
        }
37 1
        throw (new ModelNotFoundException())->setModel(DataPosition::class);
38
    }
39
40
    /**
41
     * Create a new data position
42
     *
43
     * @param string|null $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
44
     * @param string|null $description
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @return \BristolSU\ControlDB\Contracts\Models\DataPosition
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 $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition
48
    {
49 5
        return \BristolSU\ControlDB\Models\DataPosition::create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return BristolSU\Control...tion' => $description)) could return the type null which is incompatible with the type-hinted return BristolSU\ControlDB\Contracts\Models\DataPosition. 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
            'name' => $name,
51 5
            'description' => $description,
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 positions 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\DataPosition::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\DataPosition::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\DataPosition $dataPosition) 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 ($dataPosition->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 $name Name of the position
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 1 found
Loading history...
91
     * @param string|null $description Description of the position
92
     * @return \BristolSU\ControlDB\Contracts\Models\DataPosition
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 $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition
95
    {
96 6
        $dataPosition = $this->getById($id)->fill([
0 ignored issues
show
Bug introduced by
The method fill() does not exist on BristolSU\ControlDB\Contracts\Models\DataPosition. Since it exists in all sub-types, consider adding an abstract or default implementation to BristolSU\ControlDB\Contracts\Models\DataPosition. ( Ignorable by Annotation )

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

96
        $dataPosition = $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
            'name' => $name, 'description' => $description
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
        $dataPosition->save();
100 6
        return $dataPosition;
101
    }
102
}