Passed
Pull Request — develop (#15)
by
unknown
06:02
created

Settings::getUseSSO()   A

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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 nystudio107\disqus\Disqus;
15
16
use Craft;
17
use craft\base\Model;
18
use craft\behaviors\EnvAttributeParserBehavior;
19
20
use yii\behaviors\AttributeTypecastBehavior;
21
22
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
 * @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...
24
 * @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...
25
 * @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...
26
 */
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...
27
class Settings extends Model
28
{
29
    // Public Properties
30
    // =========================================================================
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
33
     * @var string
34
     */
35
    public $disqusShortname = '';
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
38
     * @var bool
39
     */
40
    public $useSSO = false;
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var string
44
     */
45
    public $disqusPublicKey = '';
46
47
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
48
     * @var string
49
     */
50
    public $disqusSecretKey = '';
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
53
     * @var bool
54
     */
55
    public $customLogin = false;
56
57
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
58
     * @var string
59
     */
60
    public $loginName = '';
61
62
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
63
     * @var string
64
     */
65
    public $loginButton = '';
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @var string
69
     */
70
    public $loginIcon = '';
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
73
     * @var string
74
     */
75
    public $loginUrl = '';
76
77
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
78
     * @var string
79
     */
80
    public $loginLogoutUrl = '';
81
82
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
83
     * @var int
84
     */
85
    public $loginWidth = 800;
86
87
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
88
     * @var int
89
     */
90
    public $loginHeight = 400;
91
92
    // Public Methods
93
    // =========================================================================
94
95
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
96
     * @return string the parsed secret key (e.g. 'XXXXXXXXXXX')
97
     */
98
    public function getDisqusSecretKey(): string
99
    {
100
        return Disqus::$craft31 ? Craft::parseEnv($this->disqusSecretKey) : $this->disqusSecretKey;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu... $this->disqusSecretKey could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
101
    }
102
103
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
104
     * @return string the parsed public key (e.g. 'XXXXXXXXXXX')
105
     */
106
    public function getDisqusPublicKey(): string
107
    {
108
        return Disqus::$craft31 ? Craft::parseEnv($this->disqusPublicKey) : $this->disqusPublicKey;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu... $this->disqusPublicKey could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
109
    }
110
111
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @return string 
113
     */
114
    public function getDisqusShortname(): string
115
    {
116
        return $this->disqusShortname;
117
    }
118
119
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
120
     * @return bool
121
     */
122
    public function getUseSSO(): bool
123
    {
124
        return $this->useSSO;
125
    }
126
127
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
128
     * @return bool
129
     */
130
    public function getCustomLogin(): bool
131
    {
132
        return $this->customLogin;
133
    }
134
135
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
136
     * @return string
137
     */
138
    public function getLoginName(): string
139
    {
140
        return Disqus::$craft31 ? Craft::parseEnv($this->loginName) : $this->loginName;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu...ame) : $this->loginName could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
141
    }
142
143
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
144
     * @return string
145
     */
146
    public function getLoginButton(): string
147
    {
148
        return Disqus::$craft31 ? Craft::parseEnv($this->loginButton) : $this->loginButton;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu...n) : $this->loginButton could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
149
    }
150
151
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
152
     * @return string
153
     */
154
    public function getLoginIcon(): string
155
    {
156
        return Disqus::$craft31 ? Craft::parseEnv($this->loginIcon) : $this->loginIcon;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu...con) : $this->loginIcon could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
157
    }
158
159
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
160
     * @return string
161
     */
162
    public function getLoginUrl(): string
163
    {
164
        return Disqus::$craft31 ? Craft::parseEnv($this->loginUrl) : $this->loginUrl;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu...nUrl) : $this->loginUrl could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
165
    }
166
167
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
168
     * @return string
169
     */
170
    public function getLoginLogoutUrl(): string
171
    {
172
        return Disqus::$craft31 ? Craft::parseEnv($this->loginLogoutUrl) : $this->loginLogoutUrl;
0 ignored issues
show
Bug Best Practice introduced by
The expression return nystudio107\disqu...: $this->loginLogoutUrl could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
173
    }
174
175
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
176
     * @return int
177
     */
178
    public function getLoginWidth(): int
179
    {
180
        return $this->loginWidth;
181
    }
182
183
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
184
     * @return int
185
     */
186
    public function getLoginHeight(): int
187
    {
188
        return $this->loginHeight;
189
    }
190
191
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
192
     * @inheritdoc
193
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
194
    public function rules()
195
    {
196
        return [
197
            ['disqusShortname', 'string'],
198
            ['disqusShortname', 'default', 'value' => ''],
199
            ['useSSO', 'boolean'],
200
            ['useSSO', 'default', 'value' => false],
201
            ['disqusPublicKey', 'string'],
202
            ['disqusPublicKey', 'default', 'value' => ''],
203
            ['disqusSecretKey', 'string'],
204
            ['disqusSecretKey', 'default', 'value' => ''],
205
            ['customLogin', 'boolean'],
206
            ['customLogin', 'default', 'value' => false],
207
            ['loginName', 'string'],
208
            ['loginName', 'default', 'value' => ''],
209
            ['loginButton', 'string'],
210
            ['loginButton', 'default', 'value' => ''],
211
            ['loginIcon', 'string'],
212
            ['loginIcon', 'default', 'value' => ''],
213
            ['loginUrl', 'string'],
214
            ['loginUrl', 'default', 'value' => ''],
215
            ['loginLogoutUrl', 'string'],
216
            ['loginLogoutUrl', 'default', 'value' => ''],
217
            ['loginWidth', 'integer', 'min' => 400, 'max' => 2000],
218
            ['loginWidth', 'default', 'value' => 800],
219
            ['loginHeight', 'integer', 'min' => 200, 'max' => 1000],
220
            ['loginHeight', 'default', 'value' => 400],
221
        ];
222
    }
223
224
225
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
226
     * @return array
227
     */
228
    public function behaviors()
229
    {
230
        $craft31Behaviors = [];
231
        if (Disqus::$craft31) {
232
            $craft31Behaviors = [
233
                'parser' => [
234
                    'class' => EnvAttributeParserBehavior::class,
235
                    'attributes' => [
236
                        'loginName',
237
                        'loginButton',
238
                        'loginIcon',
239
                        'loginUrl',
240
                        'loginLogoutUrl',
241
                        'disqusPublicKey',
242
                        'disqusSecretKey',
243
                    ],
244
                ]
245
            ];
246
        }
247
248
        return array_merge($craft31Behaviors, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
249
            'typecast' => [
250
                'class' => AttributeTypecastBehavior::class,
251
                // 'attributeTypes' will be composed automatically according to `rules()`
252
            ],
253
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
254
    }
255
}
256