Completed
Push — master ( b6d035...da6ee3 )
by Sean
03:40
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;
11
12
use Mailgun\Assert;
13
use Mailgun\Resource\Api\Suppressions\Bounce\CreateResponse;
14
use Mailgun\Resource\Api\Suppressions\Bounce\DeleteResponse;
15
use Mailgun\Resource\Api\Suppressions\Bounce\IndexResponse;
16
use Mailgun\Resource\Api\Suppressions\Bounce\ShowResponse;
17
18
/**
19
 * @see https://documentation.mailgun.com/api-suppressions.html#bounces
20
 *
21
 * @author Sean Johnson <[email protected]>
22
 */
23 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...
24
{
25
    use Pagination;
26
27
    /**
28
     * @param string $domain Domain to list bounces for
29
     * @param int    $limit  optional
30
     *
31
     * @return IndexResponse
32
     */
33
    public function index($domain, $limit = 100)
34
    {
35
        Assert::stringNotEmpty($domain);
36
        Assert::range($limit, 1, 10000, '"Limit" parameter must be between 1 and 10000');
37
38
        $params = [
39
            'limit' => $limit,
40
        ];
41
42
        $response = $this->httpGet(sprintf('/v3/%s/bounces', $domain), $params);
43
44
        return $this->safeDeserialize($response, IndexResponse::class);
45
    }
46
47
    /**
48
     * @param string $domain  Domain to show bounce from
49
     * @param string $address Bounce address to show
50
     *
51
     * @return ShowResponse
52
     */
53
    public function show($domain, $address)
54
    {
55
        Assert::stringNotEmpty($domain);
56
        Assert::stringNotEmpty($address);
57
58
        $response = $this->httpGet(sprintf('/v3/%s/bounces/%s', $domain, $address));
59
60
        return $this->safeDeserialize($response, ShowResponse::class);
61
    }
62
63
    /**
64
     * @param string $domain  Domain to create a bounce for
65
     * @param string $address Address to create a bounce for
66
     * @param array  $params  optional
67
     *
68
     * @return CreateResponse
69
     */
70
    public function create($domain, $address, array $params = [])
71
    {
72
        Assert::stringNotEmpty($domain);
73
        Assert::stringNotEmpty($address);
74
75
        $params['address'] = $address;
76
77
        $response = $this->httpPost(sprintf('/v3/%s/bounces', $domain), $params);
78
79
        return $this->safeDeserialize($response, CreateResponse::class);
80
    }
81
82
    /**
83
     * @param string $domain  Domain to delete a bounce for
84
     * @param string $address Bounce address to delete
85
     *
86
     * @return DeleteResponse
87
     */
88
    public function delete($domain, $address)
89
    {
90
        Assert::stringNotEmpty($domain);
91
        Assert::stringNotEmpty($address);
92
93
        $response = $this->httpDelete(sprintf('/v3/%s/bounces/%s', $domain, $address));
94
95
        return $this->safeDeserialize($response, DeleteResponse::class);
96
    }
97
98
    /**
99
     * @param string $domain Domain to delete all bounces for
100
     *
101
     * @return DeleteResponse
102
     */
103
    public function deleteAll($domain)
104
    {
105
        Assert::stringNotEmpty($domain);
106
107
        $response = $this->httpDelete(sprintf('/v3/%s/bounces', $domain));
108
109
        return $this->safeDeserialize($response, DeleteResponse::class);
110
    }
111
}
112