1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\ControlDB\Repositories; |
||
4 | |||
5 | use BristolSU\ControlDB\Contracts\Models\Position as PositionModel; |
||
6 | use BristolSU\ControlDB\Contracts\Repositories\Position as PositionContract; |
||
7 | use Illuminate\Support\Collection; |
||
8 | |||
9 | /** |
||
10 | * Handles positions |
||
11 | */ |
||
0 ignored issues
–
show
|
|||
12 | class Position implements PositionContract |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Get a position by ID |
||
17 | * |
||
18 | * @param int $id ID of the position |
||
19 | * @return PositionModel |
||
0 ignored issues
–
show
|
|||
20 | */ |
||
21 | 23 | public function getById(int $id): PositionModel |
|
22 | { |
||
23 | 23 | return \BristolSU\ControlDB\Models\Position::findOrFail($id); |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * Get all positions |
||
28 | * |
||
29 | * @return Collection|PositionModel[] |
||
30 | */ |
||
31 | 2 | public function all(): Collection |
|
32 | { |
||
33 | 2 | return \BristolSU\ControlDB\Models\Position::all(); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Create a new position |
||
38 | * |
||
39 | * @param int $dataProviderId |
||
0 ignored issues
–
show
|
|||
40 | * @return PositionModel |
||
0 ignored issues
–
show
|
|||
41 | */ |
||
42 | 4 | public function create(int $dataProviderId): PositionModel |
|
43 | { |
||
44 | 4 | return \BristolSU\ControlDB\Models\Position::create([ |
|
0 ignored issues
–
show
|
|||
45 | 4 | 'data_provider_id' => $dataProviderId |
|
46 | ]); |
||
0 ignored issues
–
show
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.
![]() |
|||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Delete a position by ID |
||
51 | * |
||
52 | * @param int $id |
||
0 ignored issues
–
show
|
|||
53 | */ |
||
0 ignored issues
–
show
|
|||
54 | 2 | public function delete(int $id): void |
|
55 | { |
||
56 | 2 | \BristolSU\ControlDB\Models\Position::findOrFail($id)->delete(); |
|
57 | 2 | } |
|
58 | |||
59 | /** |
||
60 | * Get a position by its data provider ID |
||
61 | * |
||
62 | * @param int $dataProviderId |
||
0 ignored issues
–
show
|
|||
63 | * @return PositionModel |
||
0 ignored issues
–
show
|
|||
64 | */ |
||
65 | 4 | public function getByDataProviderId(int $dataProviderId): PositionModel { |
|
0 ignored issues
–
show
|
|||
66 | 4 | return \BristolSU\ControlDB\Models\Position::where('data_provider_id', $dataProviderId)->firstOrFail(); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Paginate through all the positions |
||
71 | * |
||
72 | * @param int $page The page number to return |
||
0 ignored issues
–
show
|
|||
73 | * @param int $perPage The number of results to return per page |
||
74 | * |
||
75 | * @return Collection|PositionModel[] |
||
76 | */ |
||
77 | 3 | public function paginate(int $page, int $perPage): Collection |
|
78 | { |
||
79 | 3 | return \BristolSU\ControlDB\Models\Position::paginate($perPage, ['*'], 'page', $page)->getCollection(); |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get the number of positions |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | 3 | public function count(): int |
|
88 | { |
||
89 | 3 | return \BristolSU\ControlDB\Models\Position::count(); |
|
0 ignored issues
–
show
|
|||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Update the position model |
||
94 | * |
||
95 | * @param int $id |
||
0 ignored issues
–
show
|
|||
96 | * @param int $dataProviderId New data provider ID |
||
97 | * @return PositionModel |
||
0 ignored issues
–
show
|
|||
98 | */ |
||
99 | 3 | public function update(int $id, int $dataProviderId): PositionModel |
|
100 | { |
||
101 | 3 | $position = $this->getById($id)->fill(['data_provider_id' => $dataProviderId]); |
|
102 | 3 | $position->save(); |
|
103 | 3 | return $position; |
|
104 | } |
||
105 | } |
||
106 |