Settings   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 136
ccs 0
cts 71
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultConnection() 0 5 1
A getDefaultConnection() 0 4 1
A setDefaultIntegrationConnection() 0 5 1
A getDefaultIntegrationConnection() 0 4 1
A setDefaultCache() 0 5 1
A getDefaultCache() 0 4 1
A getSyncUpsertPayloadTransformer() 0 7 1
A getSyncPopulateElementTransformer() 0 7 1
A attributes() 0 11 1
A rules() 0 19 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\models;
10
11
use craft\base\Model;
12
use flipbox\craft\hubspot\helpers\TransformerHelper;
13
use flipbox\craft\hubspot\services\Cache;
14
use flipbox\craft\hubspot\services\Connections;
15
use flipbox\craft\hubspot\transformers\CreateUpsertPayloadFromElement;
16
use flipbox\craft\hubspot\transformers\PopulateElementFromResponse;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
class Settings extends Model
23
{
24
    /**
25
     * @var string
26
     */
27
    public $environmentTableSuffix = '';
28
29
    /**
30
     * @var string
31
     */
32
    private $defaultCache = Cache::APP_CACHE;
33
34
    /**
35
     * @var string
36
     */
37
    private $defaultConnection = Connections::CONNECTION;
38
39
    /**
40
     * @var string
41
     */
42
    private $defaultIntegrationConnection = Connections::INTEGRATION_CONNECTION;
43
44
    /**
45
     * @param string $key
46
     * @return $this
47
     */
48
    public function setDefaultConnection(string $key)
49
    {
50
        $this->defaultConnection = $key;
51
        return $this;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getDefaultConnection(): string
58
    {
59
        return $this->defaultConnection;
60
    }
61
62
    /**
63
     * @param string $key
64
     * @return $this
65
     */
66
    public function setDefaultIntegrationConnection(string $key)
67
    {
68
        $this->defaultIntegrationConnection = $key;
69
        return $this;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getDefaultIntegrationConnection(): string
76
    {
77
        return $this->defaultIntegrationConnection;
78
    }
79
80
    /**
81
     * @param string $key
82
     * @return $this
83
     */
84
    public function setDefaultCache(string $key)
85
    {
86
        $this->defaultCache = $key;
87
        return $this;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getDefaultCache(): string
94
    {
95
        return $this->defaultCache;
96
    }
97
98
    /**
99
     * @return callable
100
     */
101
    public function getSyncUpsertPayloadTransformer(): callable
102
    {
103
        return TransformerHelper::resolveTransformer([
104
            'class' => CreateUpsertPayloadFromElement::class,
105
            'action' => TransformerHelper::PAYLOAD_ACTION_SYNC
106
        ]);
107
    }
108
109
    /**
110
     * @return callable
111
     */
112
    public function getSyncPopulateElementTransformer(): callable
113
    {
114
        return TransformerHelper::resolveTransformer([
115
            'class' => PopulateElementFromResponse::class,
116
            'action' => TransformerHelper::PAYLOAD_ACTION_SYNC
117
        ]);
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function attributes()
124
    {
125
        return array_merge(
126
            parent::attributes(),
127
            [
128
                'defaultConnection',
129
                'defaultIntegrationConnection',
130
                'defaultCache'
131
            ]
132
        );
133
    }
134
135
    /**
136
     * @return array
137
     */
138
    public function rules()
139
    {
140
        return array_merge(
141
            parent::rules(),
142
            [
143
                [
144
                    [
145
                        'defaultConnection',
146
                        'defaultIntegrationConnection',
147
                        'defaultCache'
148
                    ],
149
                    'safe',
150
                    'on' => [
151
                        self::SCENARIO_DEFAULT
152
                    ]
153
                ]
154
            ]
155
        );
156
    }
157
}
158