User::profile()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 18

Duplication

Lines 5
Ratio 27.78 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 5
loc 18
ccs 10
cts 10
cp 1
rs 9.3554
c 0
b 0
f 0
cc 5
nc 6
nop 2
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Api;
6
7
use Kerox\Messenger\Exception\InvalidKeyException;
8
use Kerox\Messenger\Request\UserRequest;
9
use Kerox\Messenger\Response\UserResponse;
10
use Kerox\Messenger\UserInterface;
11
12
class User extends AbstractApi implements UserInterface
13
{
14
    /**
15
     * @throws \Kerox\Messenger\Exception\MessengerException
16
     */
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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
36 2 View Code Duplication
    private function getAllowedFields(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
37
    {
38
        return [
39 2
            self::FIRST_NAME,
40 2
            self::LAST_NAME,
41 2
            self::PROFILE_PIC,
42 2
            self::LOCALE,
43 2
            self::TIMEZONE,
44 2
            self::GENDER,
45
        ];
46
    }
47
}
48