TimelineEventCriteria   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 73
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 5 2
A getPayload() 0 18 2
A getObjectPayload() 0 8 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
/**
12
 * @author Flipbox Factory <[email protected]>
13
 * @since 1.0.0
14
 */
15
class TimelineEventCriteria extends \Flipbox\HubSpot\Criteria\TimelineEventCriteria
16
{
17
    use CacheTrait,
18
        IntegrationConnectionTrait;
19
20
    /**
21
     * @var string|array
22
     */
23
    public $object;
24
25
    /**
26
     * @var array
27
     */
28
    public $extraData = [];
29
30
    /**
31
     * @var array|null
32
     */
33
    public $payload;
34
35
    /**
36
     * @var array
37
     */
38
    public $properties = [];
39
40
    /**
41
     * @var array
42
     */
43
    public $timelineIFrame = [];
44
45
    /**
46
     * @return string
47
     */
48
    public function getId(): string
49
    {
50
        $id = $this->findId();
51
        return (string)($id ?: substr(str_shuffle(md5(time())), 0, 36));
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getPayload(): array
58
    {
59
        // Explicitly set ?
60
        if ($this->payload !== null) {
61
            return (array)$this->payload;
62
        }
63
64
        $payload = array_merge(
65
            $this->getObjectPayload(),
66
            [
67
                'timelineIFrame' => $this->timelineIFrame,
68
                'extraData' => $this->extraData
69
            ],
70
            $this->properties
71
        );
72
73
        return array_filter($payload);
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    protected function getObjectPayload(): array
80
    {
81
        if (is_numeric($this->object)) {
82
            $this->object = ['objectId' => $this->object];
83
        }
84
85
        return (array)$this->object;
86
    }
87
}
88