SegmentsRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 75
loc 75
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 10 10 2
A post() 10 10 2
A patch() 10 10 2
A delete() 10 10 2

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
namespace Mailxpert\Request;
4
5
use Mailxpert\Exceptions\MailxpertSDKResponseException;
6
use Mailxpert\Mailxpert;
7
8
/**
9
 * Class SegmentsRequest
10
 * @package Mailxpert\Request
11
 */
12 View Code Duplication
class SegmentsRequest
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...
13
{
14
    /**
15
     * @param  Mailxpert $mailxpert
16
     * @param  array     $params
17
     *
18
     * @return \Mailxpert\MailxpertResponse
19
     * @throws MailxpertSDKResponseException
20
     */
21
    public static function get(Mailxpert $mailxpert, array $params = [])
22
    {
23
        $response = $mailxpert->sendRequest('GET', 'segments', $params);
24
25
        if (!$response->isHttpResponseCodeOK()) {
26
            throw new MailxpertSDKResponseException($response, 'An error occured during receiving Segments.');
27
        }
28
29
        return $response;
30
    }
31
32
    /**
33
     * @param  Mailxpert $mailxpert
34
     * @param  array     $params
35
     *
36
     * @return \Mailxpert\MailxpertResponse
37
     * @throws MailxpertSDKResponseException
38
     */
39
    public static function post(Mailxpert $mailxpert, array $params)
40
    {
41
        $response = $mailxpert->sendRequest('POST', 'segments', [], null, json_encode($params));
42
43
        if (!$response->isHttpResponseCodeOK()) {
44
            throw new MailxpertSDKResponseException($response, 'An error occured during the Segments creation.');
45
        }
46
47
        return $response;
48
    }
49
50
    /**
51
     * @param  Mailxpert $mailxpert
52
     * @param  string    $id
53
     * @param  array     $params
54
     *
55
     * @return \Mailxpert\MailxpertResponse
56
     * @throws MailxpertSDKResponseException
57
     */
58
    public static function patch(Mailxpert $mailxpert, $id, array $params)
59
    {
60
        $response = $mailxpert->sendRequest('PATCH', sprintf('segments/%s', $id), [], null, json_encode($params));
61
62
        if (!$response->isHttpResponseCodeOK()) {
63
            throw new MailxpertSDKResponseException($response, 'An error occured during updating the Segments.');
64
        }
65
66
        return $response;
67
    }
68
69
    /**
70
     * @param  Mailxpert $mailxpert
71
     * @param  string    $id
72
     *
73
     * @return \Mailxpert\MailxpertResponse
74
     * @throws MailxpertSDKResponseException
75
     */
76
    public static function delete(Mailxpert $mailxpert, $id)
77
    {
78
        $response = $mailxpert->sendRequest('DELETE', sprintf('segments/%s', $id));
79
80
        if (!$response->isHttpResponseCodeOK()) {
81
            throw new MailxpertSDKResponseException($response, 'An error occured during the Segments deletion.');
82
        }
83
84
        return $response;
85
    }
86
}
87