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

ContactListContactsMutator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 60
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getPayload() 0 9 1
A addElement() 0 17 3
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\base\ElementInterface;
12
use flipbox\hubspot\fields\Objects;
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 ContactListContactsMutator extends BaseObject implements ObjectMutatorInterface
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: getCache, getConnection, getTransformer
Loading history...
21
{
22
    /**
23
     * @var string
24
     */
25
    public $id;
26
27
    /**
28
     * @var array
29
     */
30
    public $vids = [];
31
32
    /**
33
     * @var array
34
     */
35
    public $emails = [];
36
37
    /**
38
     * @return string
39
     */
40
    public function getId(): string
41
    {
42
        return (string)$this->id;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getPayload(): array
49
    {
50
        return array_filter(
51
            [
52
                'vids' => array_filter($this->vids),
53
                'emails' => array_filter($this->emails)
54
            ]
55
        );
56
    }
57
58
    /**
59
     * @param ElementInterface $element
60
     * @param Objects $field
61
     */
62
    public function addElement(ElementInterface $element, Objects $field)
63
    {
64
        $objectId = HubSpot::getInstance()->getObjectAssociations()->findObjectIdByElement(
65
            $element,
66
            $field
67
        );
68
69
        if ($objectId !== null) {
70
            $this->vids[] = $objectId;
71
            return;
72
        }
73
74
        if (null !== ($email = $element['email'] ?? null)) {
75
            $this->emails[] = $email;
76
            return;
77
        }
78
    }
79
}
80