Completed
Push — master ( b3f24e...84a5c5 )
by Tobias
03:15
created

Bounce   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 89
loc 89
ccs 0
cts 27
cp 0
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
/*
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\Bounce\CreateResponse;
16
use Mailgun\Model\Suppression\Bounce\DeleteResponse;
17
use Mailgun\Model\Suppression\Bounce\IndexResponse;
18
use Mailgun\Model\Suppression\Bounce\ShowResponse;
19
20
/**
21
 * @see https://documentation.mailgun.com/api-suppressions.html#bounces
22
 *
23
 * @author Sean Johnson <[email protected]>
24
 */
25 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...
26
{
27
    use Pagination;
28
29
    /**
30
     * @param string $domain Domain to list bounces 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/bounces', $domain), $params);
45
46
        return $this->safeHydrate($response, IndexResponse::class);
47
    }
48
49
    /**
50
     * @param string $domain  Domain to show bounce from
51
     * @param string $address Bounce address to show
52
     *
53
     * @return ShowResponse
54
     */
55
    public function show($domain, $address)
56
    {
57
        Assert::stringNotEmpty($domain);
58
        Assert::stringNotEmpty($address);
59
60
        $response = $this->httpGet(sprintf('/v3/%s/bounces/%s', $domain, $address));
61
62
        return $this->safeHydrate($response, ShowResponse::class);
63
    }
64
65
    /**
66
     * @param string $domain  Domain to create a bounce for
67
     * @param string $address Address to create a bounce for
68
     * @param array  $params  optional
69
     *
70
     * @return CreateResponse
71
     */
72
    public function create($domain, $address, array $params = [])
73
    {
74
        Assert::stringNotEmpty($domain);
75
        Assert::stringNotEmpty($address);
76
77
        $params['address'] = $address;
78
79
        $response = $this->httpPost(sprintf('/v3/%s/bounces', $domain), $params);
80
81
        return $this->safeHydrate($response, CreateResponse::class);
82
    }
83
84
    /**
85
     * @param string $domain  Domain to delete a bounce for
86
     * @param string $address Bounce address to delete
87
     *
88
     * @return DeleteResponse
89
     */
90
    public function delete($domain, $address)
91
    {
92
        Assert::stringNotEmpty($domain);
93
        Assert::stringNotEmpty($address);
94
95
        $response = $this->httpDelete(sprintf('/v3/%s/bounces/%s', $domain, $address));
96
97
        return $this->safeHydrate($response, DeleteResponse::class);
98
    }
99
100
    /**
101
     * @param string $domain Domain to delete all bounces for
102
     *
103
     * @return DeleteResponse
104
     */
105
    public function deleteAll($domain)
106
    {
107
        Assert::stringNotEmpty($domain);
108
109
        $response = $this->httpDelete(sprintf('/v3/%s/bounces', $domain));
110
111
        return $this->safeHydrate($response, DeleteResponse::class);
112
    }
113
}
114