SubscriberAddHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 41
ccs 14
cts 15
cp 0.9333
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiEndpoint() 0 3 1
A addSubscriber() 0 21 2
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