| Total Complexity | 5 |
| Total Lines | 42 |
| 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 | if (!empty($fields)) { |
||
| 25 | 3 | foreach ($fields as $field) { |
|
| 26 | 3 | if (!\in_array($field, $allowedFields, true)) { |
|
| 27 | throw new \InvalidArgumentException($field . ' is not a valid value. $fields must only contain ' . implode(', ', $allowedFields)); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | } else { |
||
| 31 | $fields = $allowedFields; |
||
| 32 | } |
||
| 33 | |||
| 34 | 1 | $request = new UserRequest($this->pageToken, $fields); |
|
| 35 | $response = $this->client->get($userId, $request->build()); |
||
| 36 | 1 | ||
| 37 | 1 | return new UserResponse($response); |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | /** |
|
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | private function getAllowedFields(): array |
||
| 53 | 1 | ]; |
|
| 54 | 1 | } |
|
| 56 |