Settings::getDisqusPublicKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Disqus plugin for Craft CMS 3.x
4
 *
5
 * Integrates the Disqus commenting system into Craft 3 websites, including
6
 * Single Sign On (SSO) and custom login/logout URLs
7
 *
8
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\disqus\models;
13
14
use craft\base\Model;
15
use craft\behaviors\EnvAttributeParserBehavior;
16
use craft\helpers\App;
17
use yii\behaviors\AttributeTypecastBehavior;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
21
 * @package   Disqus
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
23
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
24
class Settings extends Model
25
{
26
    // Public Properties
27
    // =========================================================================
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var bool
31
     */
32
    public bool $lazyLoadDisqus = true;
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @var string
36
     */
37
    public string $disqusShortname = '';
38
39
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
40
     * @var bool
41
     */
42
    public bool $useSSO = false;
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
45
     * @var string
46
     */
47
    public string $disqusPublicKey = '';
48
49
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
50
     * @var string
51
     */
52
    public string $disqusSecretKey = '';
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @var bool
56
     */
57
    public bool $customLogin = false;
58
59
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @var string
61
     */
62
    public string $loginName = '';
63
64
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
     * @var string
66
     */
67
    public string $loginButton = '';
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @var string
71
     */
72
    public string $loginIcon = '';
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @var string
76
     */
77
    public string $loginUrl = '';
78
79
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
80
     * @var string
81
     */
82
    public string $loginLogoutUrl = '';
83
84
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
85
     * @var int
86
     */
87
    public int $loginWidth = 800;
88
89
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
90
     * @var int
91
     */
92
    public int $loginHeight = 400;
93
94
    // Public Methods
95
    // =========================================================================
96
97
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
98
     * @return string the parsed secret key (e.g. 'XXXXXXXXXXX')
99
     */
100
    public function getDisqusSecretKey(): string
101
    {
102
        return App::parseEnv($this->disqusSecretKey);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...$this->disqusSecretKey) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
103
    }
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
106
     * @return string the parsed public key (e.g. 'XXXXXXXXXXX')
107
     */
108
    public function getDisqusPublicKey(): string
109
    {
110
        return App::parseEnv($this->disqusPublicKey);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...$this->disqusPublicKey) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
111
    }
112
113
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
114
     * @return string
115
     */
116
    public function getDisqusShortname(): string
117
    {
118
        return $this->disqusShortname;
119
    }
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @return bool
123
     */
124
    public function getUseSSO(): bool
125
    {
126
        return $this->useSSO;
127
    }
128
129
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
130
     * @return bool
131
     */
132
    public function getCustomLogin(): bool
133
    {
134
        return $this->customLogin;
135
    }
136
137
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
138
     * @return string
139
     */
140
    public function getLoginName(): string
141
    {
142
        return App::parseEnv($this->loginName);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...seEnv($this->loginName) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
143
    }
144
145
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
146
     * @return string
147
     */
148
    public function getLoginButton(): string
149
    {
150
        return App::parseEnv($this->loginButton);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...Env($this->loginButton) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
151
    }
152
153
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
154
     * @return string
155
     */
156
    public function getLoginIcon(): string
157
    {
158
        return App::parseEnv($this->loginIcon);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...seEnv($this->loginIcon) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
159
    }
160
161
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
162
     * @return string
163
     */
164
    public function getLoginUrl(): string
165
    {
166
        return App::parseEnv($this->loginUrl);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...rseEnv($this->loginUrl) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
167
    }
168
169
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
170
     * @return string
171
     */
172
    public function getLoginLogoutUrl(): string
173
    {
174
        return App::parseEnv($this->loginLogoutUrl);
0 ignored issues
show
Bug Best Practice introduced by
The expression return craft\helpers\App...($this->loginLogoutUrl) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
175
    }
176
177
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
178
     * @return int
179
     */
180
    public function getLoginWidth(): int
181
    {
182
        return $this->loginWidth;
183
    }
184
185
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
186
     * @return int
187
     */
188
    public function getLoginHeight(): int
189
    {
190
        return $this->loginHeight;
191
    }
192
193
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
194
     * @inheritdoc
195
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
196
    public function rules(): array
197
    {
198
        return [
199
            ['lazyLoadDisqus', 'boolean'],
200
            ['lazyLoadDisqus', 'default', 'value' => false],
201
            ['disqusShortname', 'string'],
202
            ['disqusShortname', 'default', 'value' => ''],
203
            ['useSSO', 'boolean'],
204
            ['useSSO', 'default', 'value' => false],
205
            ['disqusPublicKey', 'string'],
206
            ['disqusPublicKey', 'default', 'value' => ''],
207
            ['disqusSecretKey', 'string'],
208
            ['disqusSecretKey', 'default', 'value' => ''],
209
            ['customLogin', 'boolean'],
210
            ['customLogin', 'default', 'value' => false],
211
            ['loginName', 'string'],
212
            ['loginName', 'default', 'value' => ''],
213
            ['loginButton', 'string'],
214
            ['loginButton', 'default', 'value' => ''],
215
            ['loginIcon', 'string'],
216
            ['loginIcon', 'default', 'value' => ''],
217
            ['loginUrl', 'string'],
218
            ['loginUrl', 'default', 'value' => ''],
219
            ['loginLogoutUrl', 'string'],
220
            ['loginLogoutUrl', 'default', 'value' => ''],
221
            ['loginWidth', 'integer', 'min' => 400, 'max' => 2000],
222
            ['loginWidth', 'default', 'value' => 800],
223
            ['loginHeight', 'integer', 'min' => 200, 'max' => 1000],
224
            ['loginHeight', 'default', 'value' => 400],
225
        ];
226
    }
227
228
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
229
     * @return array
230
     */
231
    public function behaviors(): array
232
    {
233
        return [
234
            'parser' => [
235
                'class' => EnvAttributeParserBehavior::class,
236
                'attributes' => [
237
                    'loginName',
238
                    'loginButton',
239
                    'loginIcon',
240
                    'loginUrl',
241
                    'loginLogoutUrl',
242
                    'disqusPublicKey',
243
                    'disqusSecretKey',
244
                ],
245
            ],
246
            'typecast' => [
247
                'class' => AttributeTypecastBehavior::class,
248
                // 'attributeTypes' will be composed automatically according to `rules()`
249
            ],
250
        ];
251
    }
252
}
253