Passed
Push — master ( fc2f89...038734 )
by compolom
02:33
created

Customers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 69
ccs 20
cts 20
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 1
A update() 0 9 1
A __invoke() 0 10 1
1
<?php
2
3
namespace Resova\Endpoints;
4
5
use Resova\Client;
6
use Resova\Models\Customer;
7
8
class Customers extends Client
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $namespace = __CLASS__;
14
15
    /**
16
     * Create a customer
17
     * Creates a new customer object.
18
     *
19
     * @param Customer $customer
20
     *
21
     * @return $this
22
     */
23 1
    public function create(Customer $customer): self
24
    {
25 1
        $customer->setRequired([
26 1
            'first_name',
27
            'last_name',
28
            'email',
29
        ]);
30
31
        // Set HTTP params
32 1
        $this->type     = 'post';
33 1
        $this->endpoint = '/customers';
34 1
        $this->params   = $customer;
35 1
        $this->response = Customer::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * Retrieve a customer
42
     * Retrieves the details of a customer. Provide the unique id for the customer.
43
     *
44
     * @param int $customer_id The customer id
45
     *
46
     * @return $this
47
     */
48 1
    public function __invoke(int $customer_id): self
49
    {
50 1
        $this->customer_id = $customer_id;
0 ignored issues
show
Bug Best Practice introduced by
The property customer_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
52
        // Set HTTP params
53 1
        $this->type     = 'get';
54 1
        $this->endpoint = '/customers/' . $customer_id;
55 1
        $this->response = Customer::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * Create a customer
62
     * Creates a new customer object.
63
     *
64
     * @param Customer $customer
65
     *
66
     * @return $this
67
     */
68 1
    public function update(Customer $customer): self
69
    {
70
        // Set HTTP params
71 1
        $this->type     = 'put';
72 1
        $this->endpoint = '/customers';
73 1
        $this->params   = $customer;
74 1
        $this->response = Customer::class;
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
75
76 1
        return $this;
77
    }
78
}
79