Completed
Push — master ( b6d035...da6ee3 )
by Sean
03:40
created

Complaint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 88
ccs 0
cts 27
cp 0
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 11 1
A delete() 0 9 1
A deleteAll() 0 8 1
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 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;
11
12
use Mailgun\Assert;
13
use Mailgun\Resource\Api\Suppressions\Complaint\CreateResponse;
14
use Mailgun\Resource\Api\Suppressions\Complaint\DeleteResponse;
15
use Mailgun\Resource\Api\Suppressions\Complaint\IndexResponse;
16
use Mailgun\Resource\Api\Suppressions\Complaint\ShowResponse;
17
18
/**
19
 * @see https://documentation.mailgun.com/api-suppressions.html#complaints
20
 *
21
 * @author Sean Johnson <[email protected]>
22
 */
23
class Complaint extends HttpApi
24
{
25
    use Pagination;
26
27
    /**
28
     * @param string $domain Domain to get complaints for
29
     * @param int    $limit  optional
30
     *
31
     * @return IndexResponse
32
     */
33
    public function index($domain, $limit = 100)
34
    {
35
        Assert::stringNotEmpty($domain);
36
        Assert::range($limit, 1, 10000, 'Limit parameter must be between 1 and 10000');
37
38
        $params = [
39
            'limit' => $limit,
40
        ];
41
42
        $response = $this->httpGet(sprintf('/v3/%s/complaints', $domain), $params);
43
44
        return $this->safeDeserialize($response, IndexResponse::class);
45
    }
46
47
    /**
48
     * @param string $domain  Domain to show complaint for
49
     * @param string $address Complaint address
50
     *
51
     * @return ShowResponse
52
     */
53
    public function show($domain, $address)
54
    {
55
        Assert::stringNotEmpty($domain);
56
        Assert::stringNotEmpty($address);
57
        $response = $this->httpGet(sprintf('/v3/%s/complaints/%s', $domain, $address));
58
59
        return $this->safeDeserialize($response, ShowResponse::class);
60
    }
61
62
    /**
63
     * @param string $domain  Domain to create complaint for
64
     * @param string $address Complaint address
65
     * @param array  $params  optional
0 ignored issues
show
Bug introduced by
There is no parameter named $params. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
66
     *
67
     * @return CreateResponse
68
     */
69
    public function create($domain, $address, $code = null, $error = null, $createdAt = null)
0 ignored issues
show
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $error is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $createdAt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        Assert::stringNotEmpty($domain);
72
        Assert::stringNotEmpty($address);
73
74
        $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...
75
76
        $response = $this->httpPost(sprintf('/v3/%s/complaints', $domain), $params);
77
78
        return $this->safeDeserialize($response, CreateResponse::class);
79
    }
80
81
    /**
82
     * @param string $domain  Domain to delete complaint for
83
     * @param string $address Complaint address
84
     *
85
     * @return DeleteResponse
86
     */
87
    public function delete($domain, $address)
88
    {
89
        Assert::stringNotEmpty($domain);
90
        Assert::stringNotEmpty($address);
91
92
        $response = $this->httpDelete(sprintf('/v3/%s/complaints/%s', $domain, $address));
93
94
        return $this->safeDeserialize($response, DeleteResponse::class);
95
    }
96
97
    /**
98
     * @param string $domain Domain to delete all bounces for
99
     *
100
     * @return DeleteResponse
101
     */
102
    public function deleteAll($domain)
103
    {
104
        Assert::stringNotEmpty($domain);
105
106
        $response = $this->httpDelete(sprintf('/v3/%s/complaints', $domain));
107
108
        return $this->safeDeserialize($response, DeleteResponse::class);
109
    }
110
}
111