Passed
Push — v1 ( 828872...11a290 )
by Andrew
06:56 queued 14s
created

Settings::getDisqusPublicKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
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 Craft;
15
use craft\base\Model;
16
use craft\behaviors\EnvAttributeParserBehavior;
17
use nystudio107\disqus\Disqus;
18
use yii\behaviors\AttributeTypecastBehavior;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @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...
22
 * @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...
23
 * @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...
24
 */
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...
25
class Settings extends Model
26
{
27
    // Public Properties
28
    // =========================================================================
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var bool
32
     */
33
    public $lazyLoadDisqus = true;
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @var string
37
     */
38
    public $disqusShortname = '';
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @var bool
42
     */
43
    public $useSSO = false;
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @var string
47
     */
48
    public $disqusPublicKey = '';
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @var string
52
     */
53
    public $disqusSecretKey = '';
54
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var bool
57
     */
58
    public $customLogin = false;
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @var string
62
     */
63
    public $loginName = '';
64
65
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
66
     * @var string
67
     */
68
    public $loginButton = '';
69
70
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
71
     * @var string
72
     */
73
    public $loginIcon = '';
74
75
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
76
     * @var string
77
     */
78
    public $loginUrl = '';
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @var string
82
     */
83
    public $loginLogoutUrl = '';
84
85
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @var int
87
     */
88
    public $loginWidth = 800;
89
90
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
91
     * @var int
92
     */
93
    public $loginHeight = 400;
94
95
    // Public Methods
96
    // =========================================================================
97
98
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
99
     * @return string the parsed secret key (e.g. 'XXXXXXXXXXX')
100
     */
101
    public function getDisqusSecretKey(): string
102
    {
103
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

103
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->disqusSecretKey) : $this->disqusSecretKey;

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

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

Loading history...
104
    }
105
106
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
107
     * @return string the parsed public key (e.g. 'XXXXXXXXXXX')
108
     */
109
    public function getDisqusPublicKey(): string
110
    {
111
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

111
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->disqusPublicKey) : $this->disqusPublicKey;

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

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

Loading history...
112
    }
113
114
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
115
     * @return string
116
     */
117
    public function getDisqusShortname(): string
118
    {
119
        return $this->disqusShortname;
120
    }
121
122
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
123
     * @return bool
124
     */
125
    public function getUseSSO(): bool
126
    {
127
        return $this->useSSO;
128
    }
129
130
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
131
     * @return bool
132
     */
133
    public function getCustomLogin(): bool
134
    {
135
        return $this->customLogin;
136
    }
137
138
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
139
     * @return string
140
     */
141
    public function getLoginName(): string
142
    {
143
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

143
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->loginName) : $this->loginName;

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

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

Loading history...
144
    }
145
146
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
147
     * @return string
148
     */
149
    public function getLoginButton(): string
150
    {
151
        return Disqus::$craft31 ? Craft::parseEnv($this->loginButton) : $this->loginButton;
0 ignored issues
show
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

151
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->loginButton) : $this->loginButton;

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

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

Loading history...
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...
152
    }
153
154
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
155
     * @return string
156
     */
157
    public function getLoginIcon(): string
158
    {
159
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

159
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->loginIcon) : $this->loginIcon;

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

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

Loading history...
160
    }
161
162
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
163
     * @return string
164
     */
165
    public function getLoginUrl(): string
166
    {
167
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

167
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->loginUrl) : $this->loginUrl;

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

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

Loading history...
168
    }
169
170
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
171
     * @return string
172
     */
173
    public function getLoginLogoutUrl(): string
174
    {
175
        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...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

175
        return Disqus::$craft31 ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($this->loginLogoutUrl) : $this->loginLogoutUrl;

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

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

Loading history...
176
    }
177
178
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
179
     * @return int
180
     */
181
    public function getLoginWidth(): int
182
    {
183
        return $this->loginWidth;
184
    }
185
186
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
187
     * @return int
188
     */
189
    public function getLoginHeight(): int
190
    {
191
        return $this->loginHeight;
192
    }
193
194
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
195
     * @inheritdoc
196
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
197
    public function rules()
198
    {
199
        return [
200
            ['lazyLoadDisqus', 'boolean'],
201
            ['lazyLoadDisqus', 'default', 'value' => false],
202
            ['disqusShortname', 'string'],
203
            ['disqusShortname', 'default', 'value' => ''],
204
            ['useSSO', 'boolean'],
205
            ['useSSO', 'default', 'value' => false],
206
            ['disqusPublicKey', 'string'],
207
            ['disqusPublicKey', 'default', 'value' => ''],
208
            ['disqusSecretKey', 'string'],
209
            ['disqusSecretKey', 'default', 'value' => ''],
210
            ['customLogin', 'boolean'],
211
            ['customLogin', 'default', 'value' => false],
212
            ['loginName', 'string'],
213
            ['loginName', 'default', 'value' => ''],
214
            ['loginButton', 'string'],
215
            ['loginButton', 'default', 'value' => ''],
216
            ['loginIcon', 'string'],
217
            ['loginIcon', 'default', 'value' => ''],
218
            ['loginUrl', 'string'],
219
            ['loginUrl', 'default', 'value' => ''],
220
            ['loginLogoutUrl', 'string'],
221
            ['loginLogoutUrl', 'default', 'value' => ''],
222
            ['loginWidth', 'integer', 'min' => 400, 'max' => 2000],
223
            ['loginWidth', 'default', 'value' => 800],
224
            ['loginHeight', 'integer', 'min' => 200, 'max' => 1000],
225
            ['loginHeight', 'default', 'value' => 400],
226
        ];
227
    }
228
229
230
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
231
     * @return array
232
     */
233
    public function behaviors()
234
    {
235
        $craft31Behaviors = [];
236
        if (Disqus::$craft31) {
237
            $craft31Behaviors = [
238
                'parser' => [
239
                    'class' => EnvAttributeParserBehavior::class,
240
                    'attributes' => [
241
                        'loginName',
242
                        'loginButton',
243
                        'loginIcon',
244
                        'loginUrl',
245
                        'loginLogoutUrl',
246
                        'disqusPublicKey',
247
                        'disqusSecretKey',
248
                    ],
249
                ],
250
            ];
251
        }
252
253
        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...
254
            'typecast' => [
255
                'class' => AttributeTypecastBehavior::class,
256
                // 'attributeTypes' will be composed automatically according to `rules()`
257
            ],
258
        ]);
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...
259
    }
260
}
261