ConfigureForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 16
loc 60
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 7 1
A attributeLabels() 0 6 1
A attributeHints() 0 6 1
A loadSettings() 8 8 1
A save() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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