SubscriberAddHandler::addSubscriber()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.0017

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 11
c 1
b 0
f 1
nc 1
nop 5
dl 0
loc 21
ccs 12
cts 13
cp 0.9231
crap 2.0017
rs 9.9
1
<?php
2
/**
3
 * File: SubscriberAddHandler.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 SubscriberAddHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\Subscriber
17
 */
18
class SubscriberAddHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/subscriber/add';
21
22
    /**
23
     * @param string $email
24
     * @param string $listHash
25
     * @param int $subscriberStatus
26
     * @param bool $sendConfirmationToSubscriber
27
     * @param array $customFieldsWithValues
28
     * @return null
29
     */
30 42
    public function addSubscriber(
31
        string $email,
32
        string $listHash,
33
        int $subscriberStatus = 0,
34
        bool $sendConfirmationToSubscriber = false,
35
        array $customFieldsWithValues = []
36
    ) {
37 42
        $getParameters = [];
38 12
        $postParameters = [
39 42
            'email' => $email,
40 42
            'list' => $listHash,
41 42
            'state' => $subscriberStatus,
42 42
            'confirm' => $sendConfirmationToSubscriber,
43
            'custom_fields' => $customFieldsWithValues ?: null
44
        ];
45
46 30
        $postParameters = array_filter($postParameters, function ($value) {
47 42
            return $value !== null;
48 42
        });
49 42
        $this->processRequest($getParameters, $postParameters);
50 7
        return null;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 7
    protected function getApiEndpoint(): string
57
    {
58 7
        return self::API_ENDPOINT;
59
    }
60
}
61