FernandoCalmet /
php-slim-rest-api
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Service\User; |
||
| 6 | |||
| 7 | final class Find extends Base |
||
| 8 | { |
||
| 9 | 1 | /** |
|
| 10 | * @return array<string> |
||
| 11 | 1 | */ |
|
| 12 | public function getAll(): array |
||
| 13 | { |
||
| 14 | 2 | return $this->userRepository->getAllUsers(); |
|
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @return array<string> |
||
| 19 | */ |
||
| 20 | 2 | public function getUsersByPage( |
|
| 21 | 1 | int $page, |
|
| 22 | int $perPage, |
||
| 23 | 2 | ?string $name, |
|
| 24 | 1 | ?string $email |
|
| 25 | ): array { |
||
| 26 | if ($page < 1) { |
||
| 27 | 2 | $page = 1; |
|
| 28 | 2 | } |
|
| 29 | if ($perPage < 1) { |
||
| 30 | $perPage = self::DEFAULT_PER_PAGE_PAGINATION; |
||
| 31 | } |
||
| 32 | |||
| 33 | return $this->userRepository->getUsersByPage( |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 34 | $page, |
||
| 35 | 3 | $perPage, |
|
| 36 | $name, |
||
| 37 | 3 | ||
| 38 | 3 | ); |
|
| 39 | } |
||
| 40 | |||
| 41 | public function getOne(int $userId): object |
||
| 42 | { |
||
| 43 | 2 | if (self::isRedisEnabled() === true) { |
|
| 44 | $user = $this->getUserFromCache($userId); |
||
| 45 | } else { |
||
| 46 | 2 | $user = $this->getUserFromDb($userId)->toJson(); |
|
| 47 | } |
||
| 48 | 2 | ||
| 49 | return $user; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function search(string $usersName): array |
||
| 53 | { |
||
| 54 | return $this->userRepository->search($usersName); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |