Send::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace ElasticEmail\Email;
4
5
use ElasticEmail\Client;
6
use ElasticEmail\Response;
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 extends Response
14
{
15
    const URI = 'email/send';
16
17
    /** @var Client */
18
    private $client;
19
20
    public function __construct(Client $client)
21
    {
22
        $this->client = $client;
23
    }
24
25
    public function handle(array $params = [], $muiltipartOption = false)
26
    {
27
        $options = $this->transform($params, $muiltipartOption);
28
29
        $this->response = $this->client->request('POST', self::URI, $options);
30
31
        return $this;
32
    }
33
34
    protected function transform(array $params, $muiltipartOption)
35
    {
36
        if (! $muiltipartOption) {
37
            return ['form_params' => $params];
38
        }
39
40
        $multipart = [];
41
42
        foreach ($params as $key => $value) {
43
            $multipart[] = [
44
                'name'     => $key,
45
                'contents' => $value
46
            ];
47
        }
48
49
        return ['multipart' => $multipart];
50
    }
51
}
52