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

Add   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 51
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultSegments() 0 19 1
A assemblePayload() 0 7 1
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