ContactListsRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 1
A post() 0 10 2
1
<?php
2
namespace Mailxpert\Request;
3
4
use Mailxpert\Exceptions\MailxpertSDKException;
5
use Mailxpert\Mailxpert;
6
7
/**
8
 * Date: 20/08/15
9
 */
10
class ContactListsRequest
11
{
12
    /**
13
     * @param Mailxpert $mailxpert
14
     * @param array     $params
15
     *
16
     * @return \Mailxpert\MailxpertResponse
17
     */
18
    public static function get(Mailxpert $mailxpert, array $params = [])
19
    {
20
        $response = $mailxpert->sendRequest('GET', 'contact_lists', $params);
21
22
        return $response;
23
    }
24
25
    /**
26
     * @param Mailxpert $mailxpert
27
     * @param string    $name
28
     *
29
     * @return \Mailxpert\MailxpertResponse
30
     * @throws MailxpertSDKException
31
     */
32
    public static function post(Mailxpert $mailxpert, $name)
33
    {
34
        $response = $mailxpert->sendRequest('POST', 'contact_lists', [], null, json_encode(['name' => $name]));
35
36
        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...
37
            throw new MailxpertSDKException('An error occured during the Contact list creation.');
38
        }
39
40
        return $response;
41
    }
42
}
43