These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Bounce\CreateResponse; |
||
18 | use Mailgun\Model\Suppression\Bounce\DeleteResponse; |
||
19 | use Mailgun\Model\Suppression\Bounce\IndexResponse; |
||
20 | use Mailgun\Model\Suppression\Bounce\ShowResponse; |
||
21 | |||
22 | /** |
||
23 | * @see https://documentation.mailgun.com/api-suppressions.html#bounces |
||
24 | * |
||
25 | * @author Sean Johnson <[email protected]> |
||
26 | */ |
||
27 | class Bounce extends HttpApi |
||
28 | { |
||
29 | use Pagination; |
||
30 | |||
31 | /** |
||
32 | * @param string $domain Domain to list bounces for |
||
33 | * @param int $limit optional |
||
34 | * |
||
35 | * @return IndexResponse |
||
36 | */ |
||
37 | 1 | View Code Duplication | 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/bounces', $domain), $params); |
|
47 | |||
48 | 1 | return $this->hydrateResponse($response, IndexResponse::class); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param string $domain Domain to show bounce from |
||
53 | * @param string $address Bounce address to show |
||
54 | * |
||
55 | * @return ShowResponse |
||
56 | */ |
||
57 | 1 | View Code Duplication | public function show(string $domain, string $address) |
0 ignored issues
–
show
|
|||
58 | { |
||
59 | 1 | Assert::stringNotEmpty($domain); |
|
60 | 1 | Assert::stringNotEmpty($address); |
|
61 | |||
62 | 1 | $response = $this->httpGet(sprintf('/v3/%s/bounces/%s', $domain, $address)); |
|
63 | |||
64 | 1 | return $this->hydrateResponse($response, ShowResponse::class); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param string $domain Domain to create a bounce for |
||
69 | * @param string $address Address to create a bounce for |
||
70 | * @param array $params optional |
||
71 | * |
||
72 | * @return CreateResponse |
||
73 | */ |
||
74 | 1 | public function create(string $domain, string $address, array $params = []) |
|
75 | { |
||
76 | 1 | Assert::stringNotEmpty($domain); |
|
77 | 1 | Assert::stringNotEmpty($address); |
|
78 | |||
79 | 1 | $params['address'] = $address; |
|
80 | |||
81 | 1 | $response = $this->httpPost(sprintf('/v3/%s/bounces', $domain), $params); |
|
82 | |||
83 | 1 | return $this->hydrateResponse($response, CreateResponse::class); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param string $domain Domain to delete a bounce for |
||
88 | * @param string $address Bounce address to delete |
||
89 | * |
||
90 | * @return DeleteResponse |
||
91 | */ |
||
92 | 1 | View Code Duplication | public function delete(string $domain, string $address) |
93 | { |
||
94 | 1 | Assert::stringNotEmpty($domain); |
|
95 | 1 | Assert::stringNotEmpty($address); |
|
96 | |||
97 | 1 | $response = $this->httpDelete(sprintf('/v3/%s/bounces/%s', $domain, $address)); |
|
98 | |||
99 | 1 | return $this->hydrateResponse($response, DeleteResponse::class); |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param string $domain Domain to delete all bounces for |
||
104 | * |
||
105 | * @return DeleteResponse |
||
106 | */ |
||
107 | 1 | public function deleteAll(string $domain) |
|
108 | { |
||
109 | 1 | Assert::stringNotEmpty($domain); |
|
110 | |||
111 | 1 | $response = $this->httpDelete(sprintf('/v3/%s/bounces', $domain)); |
|
112 | |||
113 | 1 | return $this->hydrateResponse($response, DeleteResponse::class); |
|
114 | } |
||
115 | } |
||
116 |
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.