ConfigureForm::loadSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace humhub\modules\discordapp\models;
4
5
use Yii;
6
use yii\base\Model;
7
8
/**
9
 * ConfigureForm defines the configurable fields.
10
 */
11
class ConfigureForm extends Model
12
{
13
14
    public $serverUrl;
15
16
    /**
17
     * Sort the order of the widget
18
     */
19
    public $sortOrder;
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function rules()
25
    {
26
        return [
27
            ['serverUrl', 'required'],
28
            ['sortOrder', 'string'],
29
        ];
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function attributeLabels()
36
    {
37
        return [
38
            'serverUrl' => Yii::t('DiscordappModule.base', 'Discord Widget URL:'),
39
        ];
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function attributeHints()
46
    {
47
        return [
48
            'serverUrl' => Yii::t('DiscordappModule.base', 'e.g. https://discordapp.com/widget?id={server-id} or https://discord.com/widget?id={server-id}'),
49
        ];
50
    }
51
52 View Code Duplication
    public function loadSettings()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->serverUrl = Yii::$app->getModule('discordapp')->settings->get('serverUrl');
55
56
        $this->sortOrder = Yii::$app->getModule('discordapp')->settings->get('sortOrder');
57
58
        return true;
59
    }
60
61 View Code Duplication
    public function save()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        Yii::$app->getModule('discordapp')->settings->set('serverUrl', $this->serverUrl);
64
65
        Yii::$app->getModule('discordapp')->settings->set('sortOrder', $this->sortOrder);
66
67
        return true;
68
    }
69
70
}
71