Completed
Push — develop ( de31bd...3158f9 )
by Nate
20:35
created

TimelineEventMutator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

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

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