TimelineEventBatchCriteria   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 6
dl 0
loc 64
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPayload() 0 8 1
A setItems() 0 12 3
A addItem() 0 5 1
A batch() 0 11 1
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 1.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