Completed
Pull Request — master (#246)
by Tobias
10:39
created

Webhook::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Mailgun\Api;
4
5
use Mailgun\Assert;
6
use Mailgun\Resource\Api\Webhook\CreateResponse;
7
use Mailgun\Resource\Api\Webhook\DeleteResponse;
8
use Mailgun\Resource\Api\Webhook\IndexResponse;
9
use Mailgun\Resource\Api\Webhook\ShowResponse;
10
use Mailgun\Resource\Api\Webhook\UpdateResponse;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
class Webhook extends HttpApi
16
{
17
    /**
18
     * @param string $domain
19
     *
20
     * @return IndexResponse
21
     */
22
    public function index($domain)
23
    {
24
        Assert::notEmpty($domain);
25
        $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks', $domain));
26
27
        return $this->deserializer->deserialize($response, IndexResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
28
    }
29
30
    /**
31
     * @param string $domain
32
     * @param string $webhook
33
     *
34
     * @return ShowResponse
35
     */
36 View Code Duplication
    public function show($domain, $webhook)
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...
37
    {
38
        Assert::notEmpty($domain);
39
        Assert::notEmpty($webhook);
40
        $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks/%s', $domain, $webhook));
41
42
        return $this->deserializer->deserialize($response, ShowResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
43
    }
44
45
    /**
46
     * @param string $domain
47
     * @param string $id
48
     * @param string $url
49
     *
50
     * @return CreateResponse
51
     */
52 View Code Duplication
    public function create($domain, $id, $url)
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...
53
    {
54
        Assert::notEmpty($domain);
55
        Assert::notEmpty($id);
56
        Assert::notEmpty($url);
57
58
        $params = [
59
            'id' => $id,
60
            'url' => $url,
61
        ];
62
63
        $response = $this->httpPost(sprintf('/v3/domains/%s/webhooks', $domain), $params);
64
65
        return $this->deserializer->deserialize($response, CreateResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
66
    }
67
68
    /**
69
     * @param string $domain
70
     * @param string $id
71
     * @param string $url
72
     *
73
     * @return UpdateResponse
74
     */
75
    public function update($domain, $id, $url)
76
    {
77
        Assert::notEmpty($domain);
78
        Assert::notEmpty($id);
79
        Assert::notEmpty($url);
80
81
        $params = [
82
            'url' => $url,
83
        ];
84
85
        $response = $this->httpPut(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id), $params);
86
87
        return $this->deserializer->deserialize($response, UpdateResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
    }
89
90
    /**
91
     * @param string $domain
92
     * @param string $id
93
     *
94
     * @return DeleteResponse
95
     */
96 View Code Duplication
    public function delete($domain, $id)
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...
97
    {
98
        Assert::notEmpty($domain);
99
        Assert::notEmpty($id);
100
101
        $response = $this->httpDelete(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id));
102
103
        return $this->deserializer->deserialize($response, DeleteResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
104
    }
105
}
106