These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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($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->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($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->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 | View Code Duplication | public function create($domain, $address, $createdAt = null) |
|
0 ignored issues
–
show
|
|||
72 | { |
||
73 | Assert::stringNotEmpty($domain); |
||
74 | Assert::stringNotEmpty($address); |
||
75 | Assert::stringNotEmpty($createdAt); |
||
76 | |||
77 | $params['address'] = $address; |
||
78 | if (null !== $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($domain, $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($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 |
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.