Completed
Push — master ( 8e0025...04518a )
by
05:55
created

Customer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 96
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A find() 0 6 1
A refresh() 0 4 1
A create() 0 10 2
A createWithCard() 0 8 1
A update() 0 12 2
A updateWithCard() 0 8 1
A destroy() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpMob\Omise\Api;
13
14
use PhpMob\Omise\Api;
15
use PhpMob\Omise\Domain\Customer as Domain;
16
use PhpMob\Omise\Domain\Pagination;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 *
21
 * @see https://www.omise.co/customers-api
22
 */
23
final class Customer extends Api
24
{
25
    /**
26
     * @param array $parameters
27
     *
28
     * @return Pagination
29
     */
30
    public function all(array $parameters = [])
31
    {
32
        return $this->doRequest('GET', '/customers', $parameters);
33
    }
34
35
    /**
36
     * @param string $id
37
     *
38
     * @return Domain
39
     */
40
    public function find($id)
41
    {
42
        self::assertNotEmpty($id);
43
44
        return $this->doRequest('GET', '/customers/'.$id);
45
    }
46
47
    /**
48
     * @param Domain $customer
49
     */
50
    public function refresh(Domain $customer)
51
    {
52
        $customer->updateStore($this->find($customer->id)->toArray());
53
    }
54
55
    /**
56
     * @param Domain $customer
57
     */
58
    public function create(Domain $customer)
59
    {
60
        $data = $customer->getCreateData();
61
62
        if (empty($data['card'])) {
63
            unset($data['card']);
64
        }
65
66
        $customer->updateStore($this->doRequest('POST', '/customers', $data)->toArray());
67
    }
68
69
    /**
70
     * @param Domain $customer
71
     */
72
    public function createWithCard(Domain $customer)
73
    {
74
        $data = $customer->getCreateData();
75
76
        self::assertNotEmpty(@$data['card'], 'Card Id can not be empty.');
77
78
        $this->create($customer);
79
    }
80
81
    /**
82
     * @param Domain $customer
83
     */
84
    public function update(Domain $customer)
85
    {
86
        self::assertNotEmpty($customer->id);
87
88
        $data = $customer->getUpdateData();
89
90
        if (empty($data['card'])) {
91
            unset($data['card']);
92
        }
93
94
        $customer->updateStore($this->doRequest('PATCH', '/customers/'.$customer->id, $data)->toArray());
95
    }
96
97
    /**
98
     * @param Domain $customer
99
     */
100
    public function updateWithCard(Domain $customer)
101
    {
102
        $data = $customer->getCreateData();
103
104
        self::assertNotEmpty(@$data['card'], 'Card Id can not be empty.');
105
106
        $this->update($customer);
107
    }
108
109
    /**
110
     * @param Domain $customer
111
     */
112
    public function destroy(Domain $customer)
113
    {
114
        self::assertNotEmpty($customer->id);
115
116
        $customer->updateStore($this->doRequest('DELETE', '/customers/'.$customer->id)->toArray());
117
    }
118
}
119