1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\ControlDB\Observers\NotifyObservers; |
||
4 | |||
5 | use BristolSU\ControlDB\Contracts\Repositories\DataRole as DataRoleRepository; |
||
6 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
||
7 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
||
8 | use Illuminate\Support\Collection; |
||
9 | |||
10 | class DataRoleNotifier extends Notifier implements DataRoleRepository |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | |||
13 | /** |
||
0 ignored issues
–
show
|
|||
14 | * @var DataRoleRepository |
||
15 | */ |
||
16 | private $dataRoleRepository; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | 18 | public function __construct(DataRoleRepository $dataRoleRepository, ObserverStore $observerStore) |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | 18 | parent::__construct($observerStore, DataRoleRepository::class); |
|
21 | 18 | $this->dataRoleRepository = $dataRoleRepository; |
|
22 | 18 | } |
|
23 | |||
24 | /** |
||
25 | * Get a data role by ID |
||
26 | * |
||
27 | * @param int $id |
||
0 ignored issues
–
show
|
|||
28 | * @return \BristolSU\ControlDB\Contracts\Models\DataRole |
||
0 ignored issues
–
show
|
|||
29 | */ |
||
30 | 18 | public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataRole |
|
31 | { |
||
32 | 18 | return $this->dataRoleRepository->getById($id); |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * Get a data role where the given attributes match, including additional attributes. |
||
37 | * |
||
38 | * @param array $attributes |
||
0 ignored issues
–
show
|
|||
39 | * @return \BristolSU\ControlDB\Contracts\Models\DataRole |
||
0 ignored issues
–
show
|
|||
40 | */ |
||
41 | public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataRole |
||
42 | { |
||
43 | return $this->dataRoleRepository->getWhere($attributes); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get all data roles where the given attributes match, including additional attributes. |
||
48 | * |
||
49 | * @param array $attributes |
||
0 ignored issues
–
show
|
|||
50 | * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataRole[] |
||
0 ignored issues
–
show
|
|||
51 | */ |
||
52 | public function getAllWhere($attributes = []): Collection |
||
53 | { |
||
54 | return $this->dataRoleRepository->getAllWhere($attributes); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Create a data role with the given attributes |
||
59 | * |
||
60 | * @param string|null $roleName Custom name for the role |
||
61 | * @param string|null $email Email of the role |
||
0 ignored issues
–
show
|
|||
62 | * @return \BristolSU\ControlDB\Contracts\Models\DataRole |
||
0 ignored issues
–
show
|
|||
63 | */ |
||
64 | 2 | public function create(?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole |
|
65 | { |
||
66 | 2 | $dataRole = $this->dataRoleRepository->create($roleName, $email); |
|
67 | 2 | $this->notify('create', $dataRole); |
|
68 | 2 | return $dataRole; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Update a role with the given attributes |
||
73 | * |
||
74 | * @param int $id |
||
0 ignored issues
–
show
|
|||
75 | * @param string|null $roleName Name of the role |
||
76 | * @param string|null $email Email of the role |
||
0 ignored issues
–
show
|
|||
77 | * @return \BristolSU\ControlDB\Contracts\Models\DataRole |
||
0 ignored issues
–
show
|
|||
78 | */ |
||
79 | 4 | public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole |
|
80 | { |
||
81 | 4 | $oldDataRole = $this->getById($id); |
|
82 | 4 | $newDataRole = $this->dataRoleRepository->update($id, $roleName, $email); |
|
83 | 4 | $this->notify('update', $oldDataRole, $newDataRole); |
|
84 | 4 | return $newDataRole; |
|
85 | } |
||
86 | |||
87 | |||
88 | } |