Conditions | 5 |
Paths | 6 |
Total Lines | 18 |
Lines | 5 |
Ratio | 27.78 % |
Tests | 10 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
17 | 2 | public function profile(string $userId, array $fields = []): UserResponse |
|
18 | { |
||
19 | 2 | $allowedFields = $this->getAllowedFields(); |
|
20 | 2 | $fields = empty($fields) ? $allowedFields : $fields; |
|
21 | |||
22 | 2 | if ($fields !== $allowedFields) { |
|
23 | 1 | View Code Duplication | foreach ($fields as $field) { |
|
|||
24 | 1 | if (!\in_array($field, $allowedFields, true)) { |
|
25 | 1 | throw new InvalidKeyException(sprintf('%s is not a valid value. fields must only contain "%s".', $field, implode(', ', $allowedFields))); |
|
26 | } |
||
27 | } |
||
28 | } |
||
29 | |||
30 | 1 | $request = new UserRequest($this->pageToken, $fields); |
|
31 | 1 | $response = $this->client->get($userId, $request->build()); |
|
32 | |||
33 | 1 | return new UserResponse($response); |
|
34 | } |
||
35 | |||
48 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.