Completed
Push — master ( 3b1bc5...165104 )
by Joachim
06:51 queued 23s
created

Customer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 147
Duplicated Lines 44.22 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 10.87%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 65
loc 147
ccs 5
cts 46
cp 0.1087
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerByEmail() 9 9 1
A getCustomer() 9 9 1
A createdSince() 0 7 1
A createCustomer() 0 4 1
A updateCustomer() 10 10 1
A deleteCustomer() 12 12 1
A getCustomerGroups() 0 7 1
A updateCustomerDiscount() 10 10 1
A getCustomerDiscount() 12 12 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
namespace Loevgaard\Dandomain\Api\Endpoint;
3
4
use Assert\Assert;
5
6
class Customer extends Endpoint
7
{
8
9
    /**
10
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomer_GET
11
     *
12
     * @param int $customerId
13
     * @return array
14
     */
15 3 View Code Duplication
    public function getCustomer(int $customerId) : 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...
16
    {
17 3
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
18
19 2
        return (array)$this->master->doRequest(
20 2
            'GET',
21 2
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', $customerId)
22
        );
23
    }
24
25
    /**
26
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerByEmail_GET
27
     *
28
     * @param string $email
29
     * @return array
30
     */
31 View Code Duplication
    public function getCustomerByEmail(string $email) : 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...
32
    {
33
        Assert::that($email)->email();
34
35
        return (array)$this->master->doRequest(
36
            'GET',
37
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerByEmail?email=%s', rawurlencode($email))
38
        );
39
    }
40
    
41
    /**
42
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#General_Online_Reference
43
     *
44
     * @param  \DateTimeInterface $date
45
     * @return array      
46
     */
47
    public function createdSince(\DateTimeInterface $date) : array
48
    {
49
        return (array)$this->master->doRequest(
50
            'GET',
51
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/CreatedSince?date=%s', $date->format('Y-m-d\TH:i:s'))
52
        );
53
    }
54
55
    /**
56
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#CreateCustomer_POST
57
     *
58
     * @param array|\stdClass $customer
59
     * @return array
60
     */
61
    public function createCustomer($customer) : array
62
    {
63
        return (array)$this->master->doRequest('POST', '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}', $customer);
64
    }
65
66
    /**
67
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomer_PUT
68
     *
69
     * @param int $customerId
70
     * @param array|\stdClass $customer
71
     * @return array
72
     */
73 View Code Duplication
    public function updateCustomer(int $customerId, $customer) : 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...
74
    {
75
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
76
77
        return (array)$this->master->doRequest(
78
            'PUT',
79
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', $customerId),
80
            $customer
81
        );
82
    }
83
84
    /**
85
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#DeleteCustomer_DELETE
86
     *
87
     * @param int $customerId
88
     * @return boolean
89
     */
90 View Code Duplication
    public function deleteCustomer(int $customerId) : bool
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...
91
    {
92
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
93
94
        return (bool)$this->master->doRequest(
95
            'DELETE',
96
            sprintf(
97
                '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d',
98
                $customerId
99
            )
100
        );
101
    }
102
103
    /**
104
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerGroups_GET
105
     *
106
     * @return array
107
     */
108
    public function getCustomerGroups() : array
109
    {
110
        return (array)$this->master->doRequest(
111
            'GET',
112
            '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/CustomerGroup'
113
        );
114
    }
115
116
    /**
117
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomerDiscountPOST
118
     *
119
     * @param int $customerId
120
     * @param array|\stdClass $customerDiscount
121
     * @return array
122
     */
123 View Code Duplication
    public function updateCustomerDiscount(int $customerId, $customerDiscount) : 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...
124
    {
125
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
126
127
        return (array)$this->master->doRequest(
128
            'POST',
129
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/UpdateCustomerDiscount/%d', $customerId),
130
            $customerDiscount
131
        );
132
    }
133
134
    /**
135
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerDiscountGET
136
     *
137
     * @param int $customerId
138
     * @return array
139
     */
140 View Code Duplication
    public function getCustomerDiscount(int $customerId) : 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...
141
    {
142
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
143
144
        return (array)$this->master->doRequest(
145
            'GET',
146
            sprintf(
147
                '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerDiscount/%d',
148
                $customerId
149
            )
150
        );
151
    }
152
}
153