CustomFieldsRequest::delete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * Date: 21/08/15
4
 */
5
6
namespace Mailxpert\Request;
7
8
use Mailxpert\Exceptions\MailxpertSDKException;
9
use Mailxpert\Exceptions\MailxpertSDKResponseException;
10
use Mailxpert\Mailxpert;
11
12
/**
13
 * Class CustomFieldsRequest
14
 * @package Mailxpert\Request
15
 */
16 View Code Duplication
class CustomFieldsRequest
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...
17
{
18
    /**
19
     * @param Mailxpert $mailxpert
20
     * @param array     $params
21
     *
22
     * @return \Mailxpert\MailxpertResponse
23
     * @throws MailxpertSDKResponseException
24
     */
25
    public static function get(Mailxpert $mailxpert, array $params = [])
26
    {
27
        $response = $mailxpert->sendRequest('GET', 'custom_fields', $params);
28
29
        if (!$response->isHttpResponseCodeOK()) {
30
            throw new MailxpertSDKResponseException($response, 'An error occured during the Custom field fetching.');
31
        }
32
33
        return $response;
34
    }
35
36
    /**
37
     * @param Mailxpert $mailxpert
38
     * @param array     $params
39
     *
40
     * @return \Mailxpert\MailxpertResponse
41
     * @throws MailxpertSDKResponseException
42
     */
43
    public static function post(Mailxpert $mailxpert, array $params)
44
    {
45
        $response = $mailxpert->sendRequest('POST', 'custom_fields', [], null, json_encode($params));
46
47
        if (!$response->getHeader('Location')) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $response->getHeader('Location') of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48
            throw new MailxpertSDKResponseException($response, 'An error occured during the Custom field creation.');
49
        }
50
51
        return $response;
52
    }
53
54
    /**
55
     * @param  Mailxpert $mailxpert
56
     * @param  string    $id
57
     * @param  array     $params
58
     *
59
     * @return \Mailxpert\MailxpertResponse
60
     * @throws MailxpertSDKResponseException
61
     */
62
    public static function patch(Mailxpert $mailxpert, $id, array $params)
63
    {
64
        $response = $mailxpert->sendRequest('PATCH', sprintf('custom_fields/%s', $id), [], null, json_encode($params));
65
66
        if (!$response->isHttpResponseCodeOK()) {
67
            throw new MailxpertSDKResponseException($response, 'An error occured during updating the CustomField.');
68
        }
69
70
        return $response;
71
    }
72
73
    /**
74
     * @param  Mailxpert $mailxpert
75
     * @param  string    $id
76
     *
77
     * @return \Mailxpert\MailxpertResponse
78
     * @throws MailxpertSDKResponseException
79
     */
80
    public static function delete(Mailxpert $mailxpert, $id)
81
    {
82
        $response = $mailxpert->sendRequest('DELETE', sprintf('custom_fields/%s', $id));
83
84
        if (!$response->isHttpResponseCodeOK()) {
85
            throw new MailxpertSDKResponseException($response, 'An error occured during the CustomField deletion.');
86
        }
87
88
        return $response;
89
    }
90
}
91