Completed
Push — master ( 999644...c70682 )
by Joachim
01:48
created

Customer::getCustomerByEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
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
    public function getCustomer(int $customerId) : array
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/#CreateCustomer_POST
43
     *
44
     * @param array|\stdClass $customer
45
     * @return array
46
     */
47
    public function createCustomer($customer) : array
48
    {
49
        return (array)$this->master->doRequest('POST', '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}', $customer);
50
    }
51
52
    /**
53
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomer_PUT
54
     *
55
     * @param int $customerId
56
     * @param array|\stdClass $customer
57
     * @return array
58
     */
59
    public function updateCustomer(int $customerId, $customer) : array
60
    {
61
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
62
63
        return (array)$this->master->doRequest(
64
            'PUT',
65
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', $customerId),
66
            $customer
67
        );
68
    }
69
70
    /**
71
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#DeleteCustomer_DELETE
72
     *
73
     * @param int $customerId
74
     * @return boolean
75
     */
76
    public function deleteCustomer(int $customerId) : bool
77
    {
78
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
79
80
        return (bool)$this->master->doRequest(
81
            'DELETE',
82
            sprintf(
83
                '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d',
84
                $customerId
85
            )
86
        );
87
    }
88
89
    /**
90
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerGroups_GET
91
     *
92
     * @return array
93
     */
94
    public function getCustomerGroups() : array
95
    {
96
        return (array)$this->master->doRequest(
97
            'GET',
98
            '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/CustomerGroup'
99
        );
100
    }
101
102
    /**
103
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomerDiscountPOST
104
     *
105
     * @param int $customerId
106
     * @param array|\stdClass $customerDiscount
107
     * @return array
108
     */
109
    public function updateCustomerDiscount(int $customerId, $customerDiscount) : array
110
    {
111
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
112
113
        return (array)$this->master->doRequest(
114
            'POST',
115
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/UpdateCustomerDiscount/%d', $customerId),
116
            $customerDiscount
117
        );
118
    }
119
120
    /**
121
     * @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerDiscountGET
122
     *
123
     * @param int $customerId
124
     * @return array
125
     */
126
    public function getCustomerDiscount(int $customerId) : array
127
    {
128
        Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive');
129
130
        return (array)$this->master->doRequest(
131
            'GET',
132
            sprintf(
133
                '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerDiscount/%d',
134
                $customerId
135
            )
136
        );
137
    }
138
}
139