CustomFieldsChoicesRequest::post()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
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\Mailxpert;
10
11
/**
12
 * Class CustomFieldsChoicesRequest
13
 * @package Mailxpert\Request
14
 */
15
class CustomFieldsChoicesRequest
16
{
17
    /**
18
     * @param Mailxpert $mailxpert
19
     * @param string    $customFieldId
20
     * @param array     $params
21
     *
22
     * @return \Mailxpert\MailxpertResponse
23
     */
24
    public static function get(Mailxpert $mailxpert, $customFieldId, array $params = [])
25
    {
26
        $response = $mailxpert->sendRequest('GET', sprintf('custom_fields/%s/choices', $customFieldId), $params);
27
28
        return $response;
29
    }
30
31
    /**
32
     * @param Mailxpert $mailxpert
33
     * @param string    $customFieldId
34
     * @param array     $params
35
     *
36
     * @return \Mailxpert\MailxpertResponse
37
     * @throws MailxpertSDKException
38
     */
39
    public static function post(Mailxpert $mailxpert, $customFieldId, array $params)
40
    {
41
        $response = $mailxpert->sendRequest('POST', sprintf('custom_fields/%s/choices', $customFieldId), [], null, json_encode($params));
42
43
        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...
44
            throw new MailxpertSDKException('An error occured during the Contactfield Choice creation.');
45
        }
46
47
        return $response;
48
    }
49
}
50