Completed
Push — master ( 0c0d2f...7c0457 )
by Nate
04:27
created

Add::assemblePayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Flipbox\Relay\HubSpot\Segment\ContactLists;
4
5
use Flipbox\Relay\HubSpot\Middleware\Client;
6
use Flipbox\Relay\HubSpot\Middleware\ContactLists\Add as ContactListAddMiddleware;
7
use Flipbox\Relay\Middleware\Stash as CacheMiddleware;
8
use Flipbox\Relay\Segments\AbstractSegment;
9
use Psr\Cache\CacheItemPoolInterface;
10
use Flipbox\Relay\HubSpot\Middleware\JsonRequest as JsonRequestMiddleware;
11
12
class Add extends AbstractSegment
13
{
14
    /**
15
     * @var int
16
     */
17
    public $id;
18
19
    /**
20
     * @var array
21
     */
22
    public $contactIds = [];
23
24
    /**
25
     * @var array
26
     */
27
    public $emails = [];
28
29
    /**
30
     * @return array
31
     */
32
    protected function defaultSegments(): array
33
    {
34
        return [
35
            'body' => [
36
                'class' => JsonRequestMiddleware::class,
37
                'payload' => $this->assemblePayload(),
38
                'logger' => $this->getLogger()
39
            ],
40
            'uri' => [
41
                'class' => ContactListAddMiddleware::class,
42
                'id' => $this->id,
43
                'logger' => $this->getLogger()
44
            ],
45
            'client' => [
46
                'class' => Client::class,
47
                'logger' => $this->getLogger()
48
            ]
49
        ];
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    protected function assemblePayload(): array
56
    {
57
        return [
58
            'vids' => array_filter($this->contactIds),
59
            'emails' => array_filter($this->emails)
60
        ];
61
    }
62
}
63