Profile   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 37.88 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 25
loc 66
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 1
A get() 11 11 1
A delete() 9 9 1
A isValidFields() 5 9 3
A getAllowedFields() 0 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Model\ProfileSettings;
9
use Kerox\Messenger\ProfileInterface;
10
use Kerox\Messenger\Request\ProfileRequest;
11
use Kerox\Messenger\Response\ProfileResponse;
12
13
class Profile extends AbstractApi implements ProfileInterface
14
{
15 1
    public function add(ProfileSettings $profileSettings): ProfileResponse
16
    {
17 1
        $request = new ProfileRequest($this->pageToken, $profileSettings);
18 1
        $response = $this->client->post('me/messenger_profile', $request->build());
19
20 1
        return new ProfileResponse($response);
21
    }
22
23
    /**
24
     * @throws \Kerox\Messenger\Exception\MessengerException
25
     */
26 1 View Code Duplication
    public function get(array $profileSettings): ProfileResponse
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...
27
    {
28 1
        $this->isValidFields($profileSettings);
29
30 1
        $profileSettings = implode(',', $profileSettings);
31
32 1
        $request = new ProfileRequest($this->pageToken, $profileSettings);
33 1
        $response = $this->client->get('me/messenger_profile', $request->build());
34
35 1
        return new ProfileResponse($response);
36
    }
37
38
    /**
39
     * @throws \Kerox\Messenger\Exception\MessengerException
40
     */
41 2 View Code Duplication
    public function delete(array $profileSettings): ProfileResponse
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...
42
    {
43 2
        $this->isValidFields($profileSettings);
44
45 1
        $request = new ProfileRequest($this->pageToken, $profileSettings);
46 1
        $response = $this->client->delete('me/messenger_profile', $request->build());
47
48 1
        return new ProfileResponse($response);
49
    }
50
51
    /**
52
     * @throws \Kerox\Messenger\Exception\MessengerException
53
     */
54 3
    private function isValidFields(array $fields): void
55
    {
56 3
        $allowedFields = $this->getAllowedFields();
57 3 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...
58 3
            if (!\in_array($field, $allowedFields, true)) {
59 1
                throw new InvalidKeyException(sprintf('%s is not a valid value. fields must only contain "%s".', $field, implode(', ', $allowedFields)));
60
            }
61
        }
62 2
    }
63
64 3
    private function getAllowedFields(): array
65
    {
66
        return [
67 3
            self::GET_STARTED,
68 3
            self::GREETING,
69 3
            self::ICE_BREAKERS,
70 3
            self::PERSISTENT_MENU,
71 3
            self::DOMAIN_WHITELISTING,
72 3
            self::ACCOUNT_LINKING_URL,
73 3
            self::PAYMENT_SETTINGS,
74 3
            self::HOME_URL,
75 3
            self::TARGET_AUDIENCE,
76
        ];
77
    }
78
}
79