Completed
Push — master ( b3f24e...84a5c5 )
by Tobias
03:15
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\Supression;
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($domain, $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->safeHydrate($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($domain, $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->safeHydrate($response, ShowResponse::class);
62
    }
63
64
    /**
65
     * @param string $domain  Domain to create complaint for
66
     * @param string $address Complaint address
67
     * @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...
68
     *
69
     * @return CreateResponse
70
     */
71
    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...
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
78
        $response = $this->httpPost(sprintf('/v3/%s/complaints', $domain), $params);
79
80
        return $this->safeHydrate($response, CreateResponse::class);
81
    }
82
83
    /**
84
     * @param string $domain  Domain to delete complaint for
85
     * @param string $address Complaint address
86
     *
87
     * @return DeleteResponse
88
     */
89
    public function delete($domain, $address)
90
    {
91
        Assert::stringNotEmpty($domain);
92
        Assert::stringNotEmpty($address);
93
94
        $response = $this->httpDelete(sprintf('/v3/%s/complaints/%s', $domain, $address));
95
96
        return $this->safeHydrate($response, DeleteResponse::class);
97
    }
98
99
    /**
100
     * @param string $domain Domain to delete all bounces for
101
     *
102
     * @return DeleteResponse
103
     */
104
    public function deleteAll($domain)
105
    {
106
        Assert::stringNotEmpty($domain);
107
108
        $response = $this->httpDelete(sprintf('/v3/%s/complaints', $domain));
109
110
        return $this->safeHydrate($response, DeleteResponse::class);
111
    }
112
}
113