SyncItemFrom   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTriggerLabel() 0 4 1
A getConfirmationMessage() 0 4 1
A performAction() 0 15 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\craft\hubspot\fields\actions;
10
11
use craft\base\ElementInterface;
12
use flipbox\craft\hubspot\fields\ObjectsFieldInterface;
13
use flipbox\craft\hubspot\HubSpot;
14
use flipbox\craft\integration\fields\actions\AbstractIntegrationItemAction;
15
use flipbox\craft\integration\fields\Integrations;
16
use flipbox\craft\integration\records\IntegrationAssociation;
17
18
class SyncItemFrom extends AbstractIntegrationItemAction
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getTriggerLabel(): string
24
    {
25
        return HubSpot::t('Sync From HubSpot');
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getConfirmationMessage()
32
    {
33
        return HubSpot::t("Performing a sync will override any unsaved data.  Please confirm to continue.");
34
    }
35
36
    /**
37
     * @param Integrations $field
38
     * @param ElementInterface $element
39
     * @param IntegrationAssociation $record
40
     * @return bool
41
     */
42
    public function performAction(Integrations $field, ElementInterface $element, IntegrationAssociation $record): bool
43
    {
44
        if (!$field instanceof ObjectsFieldInterface) {
45
            $this->setMessage("Invalid field type.");
46
            return false;
47
        }
48
49
        if (!$field->syncFromHubSpot($element)) {
50
            $this->setMessage("Failed to sync from HubSpot " . $field->getObjectLabel());
51
            return false;
52
        }
53
54
        $this->setMessage("Sync from HubSpot executed successfully");
55
        return true;
56
    }
57
}
58