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