Completed
Push — master ( b7038b...d64f6f )
by Nate
05:37 queued 03:37
created

TimelineEventBatchCriteria::getPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\criteria;
10
11
use craft\helpers\ArrayHelper;
12
use Flipbox\HubSpot\Criteria\AbstractCriteria;
13
use Flipbox\HubSpot\Criteria\PayloadAttributeTrait;
14
use Flipbox\HubSpot\Resources\TimelineEvent;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 2.0.0
20
 */
21
class TimelineEventBatchCriteria extends AbstractCriteria
22
{
23
    use IntegrationConnectionTrait,
24
        PayloadAttributeTrait;
25
26
    /**
27
     * @return array
28
     */
29
    public function getPayload(): array
30
    {
31
        $payload = array_filter((array)$this->payload);
32
33
        return [
34
            'eventWrappers' => ArrayHelper::remove($payload, 'eventWrappers', $payload)
35
        ];
36
    }
37
38
    /**
39
     * @param array $items
40
     * @return $this
41
     * @throws \Exception
42
     */
43
    public function setItems(array $items)
44
    {
45
        foreach ($items as $item) {
46
            if (!$item instanceof TimelineEventCriteria) {
47
                continue;
48
            }
49
50
            $this->addItem($item);
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param TimelineEventCriteria $criteria
58
     * @return $this
59
     * @throws \Exception
60
     */
61
    public function addItem(TimelineEventCriteria $criteria)
62
    {
63
        $this->payload[] = $criteria->getPayload();
64
        return $this;
65
    }
66
67
    /**
68
     * @param array $criteria
69
     * @param array $config
70
     * @return ResponseInterface
71
     * @throws \Exception
72
     */
73
    public function batch(array $criteria = [], array $config = []): ResponseInterface
74
    {
75
        $this->populate($criteria);
76
77
        return TimelineEvent::batch(
78
            $this->getPayload(),
79
            $this->getConnection(),
80
            $this->getLogger(),
81
            $config
82
        );
83
    }
84
}
85