Completed
Push — master ( e96a0c...fa76da )
by Mr
01:59
created

Webhooks::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Resova\Endpoints;
4
5
use Resova\Client;
6
use Resova\Models\Webhook;
7
use Resova\Models\WebhookDelete;
8
use Resova\Models\WebhookList;
9
10
class Webhooks extends Client
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $namespace = __CLASS__;
16
17
    /**
18
     * @param int $webhook_id The webhook id
19
     *
20
     * @return $this
21
     */
22
    public function __invoke(int $webhook_id): self
23
    {
24
        $this->webhook_id = $webhook_id;
0 ignored issues
show
Bug Best Practice introduced by
The property webhook_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
26
        return $this;
27
    }
28
29
    /**
30
     * List all webhooks
31
     * Returns a list of your promotions. The promotions are returned sorted by creation date, with the most recent promotion appearing first.
32
     *
33
     * @return $this
34
     */
35
    public function all(): self
36
    {
37
        // Set HTTP params
38
        $this->type     = 'get';
39
        $this->endpoint = '/webhooks';
40
        $this->response = WebhookList::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...
41
42
        return $this;
43
    }
44
45
    /**
46
     * Create a webhook
47
     *
48
     * @param Webhook $webhook
49
     *
50
     * @return $this
51
     */
52
    public function create(Webhook $webhook): self
53
    {
54
        $webhook->setRequired([
55
            'endpoint',
56
            'events',
57
        ]);
58
59
        // Set HTTP params
60
        $this->type     = 'post';
61
        $this->endpoint = '/webhooks';
62
        $this->params   = $webhook;
63
        $this->response = Webhook::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...
64
65
        return $this;
66
    }
67
68
    /**
69
     * Update a webhook
70
     *
71
     * @param Webhook $webhook
72
     *
73
     * @return $this
74
     */
75
    public function update(Webhook $webhook): self
76
    {
77
        $webhook->setRequired([
78
            'endpoint',
79
            'events',
80
        ]);
81
82
        // Set HTTP params
83
        $this->type     = 'put';
84
        $this->endpoint = '/webhooks/' . $this->webhook_id;
85
        $this->params   = $webhook;
86
        $this->response = Webhook::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...
87
88
        return $this;
89
    }
90
91
    /**
92
     * Delete a webhook
93
     *
94
     * @return $this
95
     */
96
    public function delete(): self
97
    {
98
        // Set HTTP params
99
        $this->type     = 'delete';
100
        $this->endpoint = '/webhooks/' . $this->webhook_id;
101
        $this->response = WebhookDelete::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...
102
103
        return $this;
104
    }
105
}
106