| Conditions | 6 |
| Paths | 6 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | public static function retrieve(array $params = []): User |
||
| 31 | { |
||
| 32 | $filteredParams = UserFilterFactory::sanitizeRetrievingParams($params); |
||
| 33 | $repository = new UserRepository(); |
||
| 34 | |||
| 35 | if ($filteredParams->userID) { |
||
| 36 | if ($filteredParams->email) { |
||
| 37 | throw new UserException('Only one retrieving param should be defined: userID or email.'); |
||
| 38 | } |
||
| 39 | |||
| 40 | $user = $repository->fetchUserModelById($filteredParams->userID); |
||
| 41 | if (!$user) { |
||
| 42 | throw new UserException("User {$filteredParams->userID} not found."); |
||
| 43 | } |
||
| 44 | } elseif ($filteredParams->email) { |
||
| 45 | $user = $repository->fetchUserModelByEmail($filteredParams->email); |
||
| 46 | if (!$user) { |
||
| 47 | throw new UserException("User with email = {$filteredParams->email} not found."); |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | throw new UserException('Bad params for retrieving User'); |
||
| 51 | } |
||
| 52 | |||
| 53 | $userSpecification = new UserSpecification($user); |
||
| 54 | $userSpecification->validate(); |
||
| 55 | |||
| 56 | return $user; |
||
| 57 | } |
||
| 58 | } |
||
| 59 |