Completed
Push — master ( 4a903b...b725ab )
by Tobias
03:23 queued 53s
created

Complaint::deleteAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Copyright (C) 2013 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Api\Suppression;
11
12
use Mailgun\Api\HttpApi;
13
use Mailgun\Api\Pagination;
14
use Mailgun\Assert;
15
use Mailgun\Model\Suppression\Complaint\CreateResponse;
16
use Mailgun\Model\Suppression\Complaint\DeleteResponse;
17
use Mailgun\Model\Suppression\Complaint\IndexResponse;
18
use Mailgun\Model\Suppression\Complaint\ShowResponse;
19
20
/**
21
 * @see https://documentation.mailgun.com/api-suppressions.html#complaints
22
 *
23
 * @author Sean Johnson <[email protected]>
24
 */
25
class Complaint extends HttpApi
26
{
27
    use Pagination;
28
29
    /**
30
     * @param string $domain Domain to get complaints for
31
     * @param int    $limit  optional
32
     *
33
     * @return IndexResponse
34
     */
35
    public function index(string $domain, int $limit = 100)
36
    {
37
        Assert::stringNotEmpty($domain);
38
        Assert::range($limit, 1, 10000, 'Limit parameter must be between 1 and 10000');
39
40
        $params = [
41
            'limit' => $limit,
42
        ];
43
44
        $response = $this->httpGet(sprintf('/v3/%s/complaints', $domain), $params);
45
46
        return $this->hydrateResponse($response, IndexResponse::class);
47
    }
48
49
    /**
50
     * @param string $domain  Domain to show complaint for
51
     * @param string $address Complaint address
52
     *
53
     * @return ShowResponse
54
     */
55
    public function show(string $domain, string $address)
56
    {
57
        Assert::stringNotEmpty($domain);
58
        Assert::stringNotEmpty($address);
59
        $response = $this->httpGet(sprintf('/v3/%s/complaints/%s', $domain, $address));
60
61
        return $this->hydrateResponse($response, ShowResponse::class);
62
    }
63
64
    /**
65
     * @param string $domain    Domain to create complaint for
66
     * @param string $address   Complaint address
67
     * @param string $createdAt (optional) rfc2822 compliant format. (new \DateTime())->format('r')
68
     *
69
     * @return CreateResponse
70
     */
71
    public function create(string $domain, string $address, string $createdAt = null)
72
    {
73
        Assert::stringNotEmpty($domain);
74
        Assert::stringNotEmpty($address);
75
76
        $params['address'] = $address;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
77
        if (null !== $createdAt) {
78
            Assert::stringNotEmpty($createdAt);
79
            $params['created_at'] = $createdAt;
80
        }
81
82
        $response = $this->httpPost(sprintf('/v3/%s/complaints', $domain), $params);
83
84
        return $this->hydrateResponse($response, CreateResponse::class);
85
    }
86
87
    /**
88
     * @param string $domain  Domain to delete complaint for
89
     * @param string $address Complaint address
90
     *
91
     * @return DeleteResponse
92
     */
93
    public function delete(string $domain, string $address)
94
    {
95
        Assert::stringNotEmpty($domain);
96
        Assert::stringNotEmpty($address);
97
98
        $response = $this->httpDelete(sprintf('/v3/%s/complaints/%s', $domain, $address));
99
100
        return $this->hydrateResponse($response, DeleteResponse::class);
101
    }
102
103
    /**
104
     * @param string $domain Domain to delete all bounces for
105
     *
106
     * @return DeleteResponse
107
     */
108
    public function deleteAll(string $domain)
109
    {
110
        Assert::stringNotEmpty($domain);
111
112
        $response = $this->httpDelete(sprintf('/v3/%s/complaints', $domain));
113
114
        return $this->hydrateResponse($response, DeleteResponse::class);
115
    }
116
}
117