Total Complexity | 11 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Coverage | 28.57% |
Changes | 0 |
1 | <?php |
||
16 | class UserService implements UserServiceContract |
||
17 | 30 | { |
|
18 | public function all() |
||
19 | 30 | { |
|
20 | return User::all(); |
||
21 | } |
||
22 | |||
23 | public function find($id): ?User |
||
24 | { |
||
25 | if ($id instanceof User) |
||
26 | return $id; |
||
27 | |||
28 | $user = User::find($id); |
||
29 | |||
30 | if ($user === null) |
||
31 | throw new NotFoundHttpException(); |
||
32 | |||
33 | return $user; |
||
|
|||
34 | } |
||
35 | |||
36 | public function findByIdentityId($id): ?User |
||
37 | { |
||
38 | return User::where('identity_id', $id)->first(); |
||
39 | } |
||
40 | |||
41 | public function update($id, $data): ?User |
||
42 | { |
||
43 | 30 | $user = $this->find($id); |
|
44 | $user->update($data); |
||
45 | 30 | ||
46 | return $user; |
||
47 | } |
||
48 | |||
49 | public function create($data): User |
||
50 | { |
||
51 | $user = User::create($data); |
||
52 | $user->assignRole(Role::USER); |
||
53 | |||
54 | return $user; |
||
55 | } |
||
56 | |||
57 | public function delete($id): bool |
||
58 | { |
||
59 | return User::destroy($id); |
||
60 | } |
||
61 | |||
62 | public function newUser($data): User |
||
68 | } |
||
69 | |||
70 | public function setRoles($id, array $roles): void |
||
71 | { |
||
72 | if (!in_array(Role::USER, $roles)) |
||
73 | $roles[] = Role::USER; |
||
74 | $this->find($id)->syncRoles($roles); |
||
77 |