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

SubscriberEditHandler::editSubscriber()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 19
ccs 11
cts 12
cp 0.9167
crap 2.0023
rs 9.9332
1
<?php
2
/**
3
 * File: SubscriberEditHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\Subscriber;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
/**
14
 * Class SubscriberEditHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\Subscriber
17
 */
18
class SubscriberEditHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/subscriber/edit';
21
22
    /**
23
     * @param string $email
24
     * @param string $listHash
25
     * @param int $subscriberStatus
26
     * @param array $customFieldsWithValues
27
     * @return null
28
     */
29 28
    public function editSubscriber(
30
        string $email,
31
        string $listHash,
32
        int $subscriberStatus = 0,
33
        array $customFieldsWithValues = []
34
    ) {
35 28
        $getParameters = [];
36 8
        $postParameters = [
37 28
            'email' => $email,
38 28
            'list' => $listHash,
39 28
            'state' => $subscriberStatus,
40
            'custom_fields' => $customFieldsWithValues ?: null
41
        ];
42
43 20
        $postParameters = array_filter($postParameters, function ($value) {
44 28
            return $value !== null;
45 28
        });
46 28
        $this->processRequest($getParameters, $postParameters);
47 7
        return null;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 7
    protected function getApiEndpoint(): string
54
    {
55 7
        return self::API_ENDPOINT;
56
    }
57
}
58