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

Bounce   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 89
loc 89
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 13 13 1
A show() 9 9 1
A create() 11 11 1
A delete() 9 9 1
A deleteAll() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
class Bounce extends HttpApi
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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
    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
    public function show(string $domain, string $address)
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
    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