Completed
Push — master ( e1d59a...95b59d )
by Nate
07:06
created

Settings::getWebHookToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/force/license
6
 * @link       https://www.flipboxfactory.com/software/force/
7
 */
8
9
namespace flipbox\craft\salesforce\models;
10
11
use Craft;
12
use craft\base\Model;
13
use craft\helpers\StringHelper;
14
use flipbox\craft\ember\helpers\ModelHelper;
15
use flipbox\craft\salesforce\helpers\TransformerHelper;
16
use flipbox\craft\salesforce\services\Cache;
17
use flipbox\craft\salesforce\transformers\CreateUpsertPayloadFromElement;
18
use flipbox\craft\salesforce\transformers\PopulateElementFromResponse;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since 1.0.0
23
 */
24
class Settings extends Model
25
{
26
    const DEFAULT_CONNECTION = 'salesforce';
27
28
    /**
29
     * @var string
30
     */
31
    public $environmentTablePostfix = '';
32
33
    /**
34
     * @var string
35
     */
36
    private $defaultCache = Cache::APP_CACHE;
37
38
    /**
39
     * @var string
40
     */
41
    private $defaultConnection = self::DEFAULT_CONNECTION;
42
43
    /**
44
     * @var string
45
     */
46
    private $webhookToken;
47
48
    /**
49
     * @param string $key
50
     * @return $this
51
     */
52
    public function setDefaultConnection(string $key)
53
    {
54
        $this->defaultConnection = $key;
55
        return $this;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getDefaultConnection(): string
62
    {
63
        return $this->defaultConnection;
64
    }
65
66
    /**
67
     * @param string $key
68
     * @return $this
69
     */
70
    public function setDefaultCache(string $key)
71
    {
72
        $this->defaultCache = $key;
73
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getDefaultCache(): string
80
    {
81
        return $this->defaultCache;
82
    }
83
84
    /**
85
     * @return callable
86
     */
87
    public function getSyncUpsertPayloadTransformer(): callable
88
    {
89
        return TransformerHelper::resolveTransformer([
90
            'class' => CreateUpsertPayloadFromElement::class,
91
            'action' => TransformerHelper::PAYLOAD_ACTION_SYNC
92
        ]);
93
    }
94
95
    /**
96
     * @return callable
97
     */
98
    public function getSyncPopulateElementTransformer(): callable
99
    {
100
        return TransformerHelper::resolveTransformer([
101
            'class' => PopulateElementFromResponse::class,
102
            'action' => TransformerHelper::PAYLOAD_ACTION_SYNC
103
        ]);
104
    }
105
106
    /**
107
     * @param string $token
108
     * @return $this
109
     */
110
    public function setWebHookToken(string $token)
111
    {
112
        $this->webhookToken = $token;
113
        return $this;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getWebHookToken(): string
120
    {
121
        return $this->webhookToken ?: StringHelper::randomString();
122
    }
123
124
    /**
125
     * @return array
126
     */
127
    public function attributes()
128
    {
129
        return array_merge(
130
            parent::attributes(),
131
            [
132
                'defaultConnection',
133
                'defaultCache',
134
                'webHookToken'
135
            ]
136
        );
137
    }
138
139
    /**
140
     * @return array
141
     */
142
    public function rules()
143
    {
144
        return array_merge(
145
            parent::rules(),
146
            [
147
                [
148
                    [
149
                        'defaultConnection',
150
                        'defaultCache',
151
                        'webHookToken'
152
                    ],
153
                    'safe',
154
                    'on' => [
155
                        ModelHelper::SCENARIO_DEFAULT
0 ignored issues
show
Deprecated Code introduced by
The constant flipbox\craft\ember\help...elper::SCENARIO_DEFAULT has been deprecated with message: Use `yii\base\Model::SCENARIO_DEFAULT`

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
156
                    ]
157
                ]
158
            ]
159
        );
160
    }
161
}
162