WidgetsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 70
ccs 0
cts 50
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 25 1
A actionSyncFrom() 0 29 4
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\cp\controllers;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use craft\helpers\ArrayHelper;
14
use flipbox\craft\hubspot\cp\actions\widgets\SyncFrom;
15
use flipbox\craft\hubspot\HubSpot;
16
use yii\web\HttpException;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
class WidgetsController extends AbstractController
23
{
24
    /**
25
     * @return array
26
     */
27
    public function behaviors()
28
    {
29
        return ArrayHelper::merge(
30
            parent::behaviors(),
31
            [
32
                'error' => [
33
                    'default' => 'criteria'
34
                ],
35
                'redirect' => [
36
                    'only' => ['sync-from'],
37
                    'actions' => [
38
                        'sync-from' => [200]
39
                    ]
40
                ],
41
                'flash' => [
42
                    'actions' => [
43
                        'sync-from' => [
44
                            200 => HubSpot::t("HubSpot Object synced successfully"),
45
                            400 => HubSpot::t("Failed to sync HubSpot Object")
46
                        ]
47
                    ]
48
                ]
49
            ]
50
        );
51
    }
52
53
    /**
54
     * @param string|null $id
55
     * @param string|null $field
56
     * @param string|null $elementType
57
     * @return ElementInterface|null
58
     * @throws HttpException
59
     * @throws \yii\base\InvalidConfigException
60
     * @throws \yii\web\BadRequestHttpException
61
     */
62
    public function actionSyncFrom(
63
        string $id = null,
64
        string $field = null,
65
        string $elementType = null
66
    ) {
67
        if ($id === null) {
68
            $id = Craft::$app->getRequest()->getRequiredParam('id');
69
        }
70
71
        if ($field === null) {
72
            $field = Craft::$app->getRequest()->getRequiredParam('field');
73
        }
74
75
        if ($elementType === null) {
76
            $elementType = Craft::$app->getRequest()->getRequiredParam('elementType');
77
        }
78
79
        /** @var SyncFrom $action */
80
        return (Craft::createObject([
81
            'class' => SyncFrom::class
82
        ], [
83
            'sync-from',
84
            $this
85
        ]))->runWithParams([
86
            'id' => $id,
87
            'field' => $field,
88
            'elementType' => $elementType
89
        ]);
90
    }
91
}
92