Passed
Push — main ( aeb638...595d14 )
by Nicolaas
04:07 queued 02:06
created

SiteConfig::getCMSFields()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 143
Code Lines 102

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 102
nc 16
nop 0
dl 0
loc 143
rs 7.3777
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Sunnysideup\CMSDarkTheme\Model\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\OptionsetField;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Class \Sunnysideup\CMSDarkTheme\Model\Extensions\DarkThemePreference.
11
 *
12
 * @property SiteConfig|Member|DarkThemePreference $owner
13
 * @property string $DarkModeSetting
14
 */
15
class DarkThemePreference extends DataExtension
16
{
17
    private static $db = [
18
        'DarkModeSetting' => 'Enum("Use browser setting, Dark, Light", "Use browser setting")',
19
    ];
20
21
    private static $field_labels = [
22
        'DarkModeSetting' => 'Preferred Display Mode for CMS',
23
    ];
24
25
    public function updateCMSFields(FieldList $fields)
26
    {
27
        $fieldLabels = $this->getOwner()->fieldLabels();
28
        $fields->addFieldsToTab(
29
            'Root.Cms',
30
            [
31
                OptionsetField::create(
32
                    'DarkModeSetting',
33
                    $fieldLabels['DarkModeSetting'] ?? self::$field_labels['DarkModeSetting'],
34
                    $this->getOwner()->dbObject('DarkModeSetting')->enumValues()
35
                )
36
                    ->setDescription('Using a dark mode may reduce your electricity use. Please reload browser window to see change.'),
37
            ]
38
        );
39
    }
40
}
41