| Total Complexity | 6 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class User extends AbstractApi implements UserInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @param string $userId |
||
| 15 | * @param array|null $fields |
||
| 16 | * |
||
| 17 | * @throws \InvalidArgumentException |
||
| 18 | * |
||
| 19 | * @return \Kerox\Messenger\Response\UserResponse |
||
| 20 | */ |
||
| 21 | public function profile(string $userId, array $fields = []): UserResponse |
||
| 22 | { |
||
| 23 | 3 | $allowedFields = $this->getAllowedFields(); |
|
| 24 | $fields = empty($fields) ? $allowedFields : $fields; |
||
| 25 | 3 | ||
| 26 | 3 | if ($fields !== $allowedFields) { |
|
| 27 | foreach ($fields as $field) { |
||
| 28 | if (!\in_array($field, $allowedFields, true)) { |
||
| 29 | throw new \InvalidArgumentException( |
||
| 30 | $field . ' is not a valid value. $fields must only contain ' . implode(', ', $allowedFields) |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | 1 | } |
|
| 35 | |||
| 36 | 1 | $request = new UserRequest($this->pageToken, $fields); |
|
| 37 | 1 | $response = $this->client->get($userId, $request->build()); |
|
| 38 | |||
| 39 | return new UserResponse($response); |
||
| 40 | 1 | } |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @return array |
||
| 44 | */ |
||
| 45 | private function getAllowedFields(): array |
||
| 55 | 1 | ]; |
|
| 56 | } |
||
| 58 |