| Total Complexity | 8 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class UserService implements UserServiceContract |
||
| 16 | { |
||
| 17 | public function find($id): ?User |
||
| 18 | { |
||
| 19 | return Cache::remember($this->getCacheName($id), $this->getCacheTime(), function () use ($id) { |
||
| 20 | return User::find($id); |
||
| 21 | }); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function update($id, $data): ?User |
||
| 25 | { |
||
| 26 | $user = $this->find($id); |
||
| 27 | $user->update($data); |
||
| 28 | \Cache::put($this->getCacheName($id), $user, $this->getCacheTime()); |
||
| 29 | return $user; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function create($data): User |
||
| 33 | { |
||
| 34 | if (isset($data['_id'])) { |
||
| 35 | $user = new User(); |
||
| 36 | $user->_id = $data['_id']; |
||
|
|
|||
| 37 | $user->fill($data); |
||
| 38 | $user->save(); |
||
| 39 | } else { |
||
| 40 | $user = User::create($data); |
||
| 41 | } |
||
| 42 | Cache::put($this->getCacheName($user->id), $user, $this->getCacheTime()); |
||
| 43 | return $user; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function delete($id): bool |
||
| 52 | } |
||
| 53 | |||
| 54 | protected function getCacheName($id) |
||
| 55 | { |
||
| 56 | return "user:$id"; |
||
| 57 | } |
||
| 58 | |||
| 59 | protected function getCacheTime() |
||
| 62 | } |
||
| 63 | } |
||
| 64 |