Passed
Push — master ( 5e9e3d...710625 )
by Maciej
04:36 queued 11s
created

ListCreateHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 35
ccs 12
cts 13
cp 0.9231
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiEndpoint() 0 3 1
A createSubscriberList() 0 17 2
1
<?php
2
/**
3
 * File: ListCreateHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\Lists;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
/**
14
 * Class ListCreateHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\Lists
17
 */
18
class ListCreateHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/subscribers_list/create';
21
22
    /**
23
     * @param string $listName
24
     * @param string $description
25
     * @param array $customFieldsWithValues
26
     * @return \stdClass
27
     */
28 42
    public function createSubscriberList(
29
        string $listName,
30
        string $description = '',
31
        array $customFieldsWithValues = []
32
    ): \stdClass {
33 42
        $getParameters = [];
34 12
        $postParameters = [
35 42
            'name' => $listName,
36
            'description' => $description ?: null,
37 42
            'custom_fields' => $customFieldsWithValues
38
        ];
39
40 30
        $postParameters = array_filter($postParameters, function ($value) {
41 42
            return $value !== null;
42 42
        });
43 42
        $response = $this->processRequest($getParameters, $postParameters);
44 7
        return $response;
45
    }
46
47
    /**
48
     * @return string
49
     */
50 7
    protected function getApiEndpoint(): string
51
    {
52 7
        return self::API_ENDPOINT;
53
    }
54
}
55