SyncElementToHubSpotJob   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 59
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 3
A serialize() 0 9 1
A unserialize() 0 7 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\queue;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use craft\queue\BaseJob;
14
use flipbox\craft\ember\objects\ElementAttributeTrait;
15
use flipbox\craft\ember\objects\FieldAttributeTrait;
16
use flipbox\craft\hubspot\fields\ObjectsFieldInterface;
17
18
/**
19
 * Sync a Craft Element to a HubSpot Object
20
 */
21
class SyncElementToHubSpotJob extends BaseJob implements \Serializable
22
{
23
    use FieldAttributeTrait,
24
        ElementAttributeTrait;
25
26
    /**
27
     * @var string|null
28
     */
29
    public $objectId;
30
31
    /**
32
     * @var callable|array|string
33
     */
34
    public $transformer;
35
36
    /**
37
     * @inheritdoc
38
     * @return bool
39
     */
40
    public function execute($queue)
41
    {
42
        $field = $this->getField();
43
        $element = $this->getElement();
44
45
        if (!$field instanceof ObjectsFieldInterface || !$element instanceof ElementInterface) {
46
            return false;
47
        }
48
49
        return $field->syncToHubSpot(
50
            $element,
51
            $this->objectId,
52
            $this->transformer
53
        );
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function serialize()
60
    {
61
        return serialize([
62
            'fieldId' => $this->getFieldId(),
63
            'elementId' => $this->getElementId(),
64
            'objectId' => $this->objectId,
65
            'transformer' => $this->transformer
66
        ]);
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function unserialize($serialized)
73
    {
74
        Craft::configure(
75
            $this,
76
            unserialize($serialized)
77
        );
78
    }
79
}
80