Test Failed
Branch master (d80a5c)
by
unknown
05:06
created

Send::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace ElasticEmail\Email;
4
5
use ElasticEmail\Client;
6
use ElasticEmail\ClientHelpers;
7
8
/**
9
 * @author  Rizart Dokollari <[email protected]>
10
 * @since   12/24/17
11
 * @see http://api.elasticemail.com/public/help#Email_Send
12
 */
13
class Send
14
{
15
    const URI = 'email/send';
16
17
    use ClientHelpers;
18
19
    /** @var Client */
20
    private $client;
21
22
    public function __construct(Client $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
    public function handle(array $params = [], $muiltipartOption = false)
28
    {
29
        $options = $this->transform($params, $muiltipartOption);
30
31
        $this->response = $this->client->request('POST', self::URI, $options);
32
33
        return $this;
34
    }
35
36
    protected function transform(array $params, $muiltipartOption)
37
    {
38
        if ( ! $muiltipartOption) {
39
            return ['form_params' => $params];
40
        }
41
42
        $multipart = [];
43
44
        foreach ($params as $key => $value) {
45
            $multipart[] = [
46
                'name'     => $key,
47
                'contents' => $value
48
            ];
49
        }
50
51
        return ['multipart' => $multipart];
52
    }
53
}