Moo_EditableFieldMemberList   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 20.45 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 30.76%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 9
loc 44
ccs 4
cts 13
cp 0.3076
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldConfiguration() 0 13 3
A initFormField() 9 10 2

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
/**
4
 * Moo_EditableFieldMemberList is an object representing member dropdown field created by CMS admin.
5
 *
6
 * @package editablefield
7
 *
8
 * @author  Mohamed Alsharaf <[email protected]>
9
 */
10
class Moo_EditableFieldMemberList extends Moo_EditableField
11
{
12
    private static $singular_name   = 'Member List Field';
13
    private static $plural_name     = 'Member List Fields';
14
15
    /**
16
     * List of allowed custom settings fields.
17
     *
18
     * @var array
19
     */
20
    protected $customSettingsFields = [
21
        'GroupID',
22
    ];
23
24
    /**
25
     * Get extra configuration fields.
26
     *
27
     * @return array
28
     */
29
    public function getFieldConfiguration()
30
    {
31
        $groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
32
        $groups  = DataObject::get('Group');
33
34
        if ($groups) {
35
            $groups = $groups->map('ID', 'Title');
36
        }
37
38
        return [
39
            new DropdownField($this->getSettingName('GroupID'), _t('Moo_EditableField.GROUP', 'Group'), $groups, $groupID),
40
        ];
41
    }
42
43 1 View Code Duplication
    protected function initFormField()
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...
44
    {
45 1
        if ($this->getSetting('GroupID')) {
46 1
            $members = Member::map_in_groups($this->getSetting('GroupID'));
47
48 1
            return new DropdownField($this->Name, $this->Title, $members);
49
        }
50
51
        return false;
52
    }
53
}
54