Completed
Push — master ( 0f5433...3fbd33 )
by David
01:51
created

Complaint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.1%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 92
ccs 27
cts 29
cp 0.931
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 13 1
A show() 0 8 1
A create() 0 15 2
A delete() 0 9 1
A deleteAll() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2013 Mailgun
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license. See the LICENSE file for details.
10
 */
11
12
namespace Mailgun\Api\Suppression;
13
14
use Mailgun\Api\HttpApi;
15
use Mailgun\Api\Pagination;
16
use Mailgun\Assert;
17
use Mailgun\Model\Suppression\Complaint\CreateResponse;
18
use Mailgun\Model\Suppression\Complaint\DeleteResponse;
19
use Mailgun\Model\Suppression\Complaint\IndexResponse;
20
use Mailgun\Model\Suppression\Complaint\ShowResponse;
21
22
/**
23
 * @see https://documentation.mailgun.com/api-suppressions.html#complaints
24
 *
25
 * @author Sean Johnson <[email protected]>
26
 */
27
class Complaint extends HttpApi
28
{
29
    use Pagination;
30
31
    /**
32
     * @param string $domain Domain to get complaints for
33
     * @param int    $limit  optional
34
     *
35
     * @return IndexResponse
36
     */
37 1
    public function index(string $domain, int $limit = 100)
38
    {
39 1
        Assert::stringNotEmpty($domain);
40 1
        Assert::range($limit, 1, 10000, 'Limit parameter must be between 1 and 10000');
41
42
        $params = [
43 1
            'limit' => $limit,
44
        ];
45
46 1
        $response = $this->httpGet(sprintf('/v3/%s/complaints', $domain), $params);
47
48 1
        return $this->hydrateResponse($response, IndexResponse::class);
49
    }
50
51
    /**
52
     * @param string $domain  Domain to show complaint for
53
     * @param string $address Complaint address
54
     *
55
     * @return ShowResponse
56
     */
57 1
    public function show(string $domain, string $address)
58
    {
59 1
        Assert::stringNotEmpty($domain);
60 1
        Assert::stringNotEmpty($address);
61 1
        $response = $this->httpGet(sprintf('/v3/%s/complaints/%s', $domain, $address));
62
63 1
        return $this->hydrateResponse($response, ShowResponse::class);
64
    }
65
66
    /**
67
     * @param string $domain    Domain to create complaint for
68
     * @param string $address   Complaint address
69
     * @param string $createdAt (optional) rfc2822 compliant format. (new \DateTime())->format('r')
70
     *
71
     * @return CreateResponse
72
     */
73 1
    public function create(string $domain, string $address, string $createdAt = null)
74
    {
75 1
        Assert::stringNotEmpty($domain);
76 1
        Assert::stringNotEmpty($address);
77
78 1
        $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...
79 1
        if (null !== $createdAt) {
80
            Assert::stringNotEmpty($createdAt);
81
            $params['created_at'] = $createdAt;
82
        }
83
84 1
        $response = $this->httpPost(sprintf('/v3/%s/complaints', $domain), $params);
85
86 1
        return $this->hydrateResponse($response, CreateResponse::class);
87
    }
88
89
    /**
90
     * @param string $domain  Domain to delete complaint for
91
     * @param string $address Complaint address
92
     *
93
     * @return DeleteResponse
94
     */
95 1
    public function delete(string $domain, string $address)
96
    {
97 1
        Assert::stringNotEmpty($domain);
98 1
        Assert::stringNotEmpty($address);
99
100 1
        $response = $this->httpDelete(sprintf('/v3/%s/complaints/%s', $domain, $address));
101
102 1
        return $this->hydrateResponse($response, DeleteResponse::class);
103
    }
104
105
    /**
106
     * @param string $domain Domain to delete all bounces for
107
     *
108
     * @return DeleteResponse
109
     */
110 1
    public function deleteAll(string $domain)
111
    {
112 1
        Assert::stringNotEmpty($domain);
113
114 1
        $response = $this->httpDelete(sprintf('/v3/%s/complaints', $domain));
115
116 1
        return $this->hydrateResponse($response, DeleteResponse::class);
117
    }
118
}
119