Completed
Push — develop ( 639fa1...b48ec5 )
by Nate
02:32
created

TimelineEventBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 89
c 0
b 0
f 0
ccs 0
cts 30
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeId() 0 4 1
A getId() 0 4 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\hubspot\builders;
10
11
use craft\helpers\StringHelper;
12
use flipbox\ember\helpers\ObjectHelper;
13
use flipbox\hubspot\HubSpot;
14
use yii\base\BaseObject;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class TimelineEventBuilder extends BaseObject implements TimelineEventBuilderInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    public $id;
26
27
    /**
28
     * @var string|array
29
     */
30
    public $object;
31
32
    /**
33
     * The event type Id
34
     *
35
     * @var string
36
     */
37
    public $typeId;
38
39
    /**
40
     * @var array
41
     */
42
    public $extraData = [];
43
44
    /**
45
     * @var array|null
46
     */
47
    public $payload;
48
49
    /**
50
     * @var array
51
     */
52
    public $properties = [];
53
54
    /**
55
     * @var array
56
     */
57
    public $timelineIFrame = [];
58
59
    /**
60
     * @return string
61
     */
62
    public function getTypeId(): string
63
    {
64
        return $this->typeId;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getId(): string
71
    {
72
        return (string)($this->id ?: StringHelper::randomString());
73
    }
74
75
    /**
76
     * @return array
77
     */
78
    public function getPayload(): array
79
    {
80
        // Explicitly set ?
81
        if ($this->payload !== null) {
82
            return (array)$this->payload;
83
        }
84
85
        $payload = array_merge(
86
            $this->getObjectPayload(),
87
            [
88
                'timelineIFrame' => $this->timelineIFrame,
89
                'extraData' => $this->extraData
90
            ],
91
            $this->properties
92
        );
93
94
        return array_filter($payload);
95
    }
96
97
    /**
98
     * @return array
99
     */
100
    protected function getObjectPayload(): array
101
    {
102
        if (is_numeric($this->object)) {
103
            $this->object = ['objectId' => $this->object];
104
        }
105
106
        return (array)$this->object;
107
    }
108
}
109