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