Customer::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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
declare(strict_types=1);
13
14
namespace PhpMob\Omise\Api;
15
16
use PhpMob\Omise\Api;
17
use PhpMob\Omise\Domain\Customer as Domain;
18
use PhpMob\Omise\Domain\Pagination;
19
20
/**
21
 * @author Ishmael Doss <[email protected]>
22
 *
23
 * @see https://www.omise.co/customers-api
24
 */
25
final class Customer extends Api
26
{
27
    /**
28
     * @param array $parameters
29
     *
30
     * @return Pagination
31
     */
32 1
    public function all(array $parameters = [])
33
    {
34 1
        return $this->doRequest('GET', '/customers', $parameters);
35
    }
36
37
    /**
38
     * @param string $id
39
     *
40
     * @return Domain
41
     */
42 3
    public function find($id)
43
    {
44 3
        self::assertNotEmpty($id);
45
46 2
        return $this->doRequest('GET', '/customers/' . $id);
47
    }
48
49
    /**
50
     * @param Domain $customer
51
     */
52 1
    public function refresh(Domain $customer)
53
    {
54 1
        $customer->updateStore($this->find($customer->id)->toArray());
55 1
    }
56
57
    /**
58
     * @param Domain $customer
59
     */
60 2
    public function create(Domain $customer)
61
    {
62 2
        $data = $customer->getCreateData();
63
64 2
        if (empty($data['card'])) {
65 1
            unset($data['card']);
66
        }
67
68 2
        $customer->updateStore($this->doRequest('POST', '/customers', $data)->toArray());
69 2
    }
70
71
    /**
72
     * @param Domain $customer
73
     */
74 2
    public function createWithCard(Domain $customer)
75
    {
76 2
        $data = $customer->getCreateData();
77
78 2
        self::assertNotEmpty(@$data['card'], 'Card Token can not be empty.');
79
80 1
        $this->create($customer);
81 1
    }
82
83
    /**
84
     * @param Domain $customer
85
     */
86 3
    public function update(Domain $customer)
87
    {
88 3
        self::assertNotEmpty($customer->id);
89
90 2
        $data = $customer->getUpdateData();
91
92 2
        if (empty($data['card'])) {
93 1
            unset($data['card']);
94
        }
95
96 2
        $customer->updateStore($this->doRequest('PATCH', '/customers/' . $customer->id, $data)->toArray());
97 2
    }
98
99
    /**
100
     * @param Domain $customer
101
     */
102 2
    public function updateWithCard(Domain $customer)
103
    {
104 2
        $data = $customer->getCreateData();
105
106 2
        self::assertNotEmpty(@$data['card'], 'Card Token can not be empty.');
107
108 1
        $this->update($customer);
109 1
    }
110
111
    /**
112
     * @param Domain $customer
113
     */
114 2
    public function destroy(Domain $customer)
115
    {
116 2
        self::assertNotEmpty($customer->id);
117
118 1
        $customer->updateStore($this->doRequest('DELETE', '/customers/' . $customer->id)->toArray());
119 1
    }
120
}
121