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

CampaignTestHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
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 32
ccs 12
cts 13
cp 0.9231
rs 10
wmc 3

2 Methods

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