EditableCheckbox   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isCheckBoxField() 0 3 1
A getValueFromData() 0 7 3
A getCMSFields() 0 10 1
A getFormField() 0 9 2
1
<?php
2
3
namespace SilverStripe\UserForms\Model\EditableFormField;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\UserForms\Model\EditableFormField;
7
8
/**
9
 * EditableCheckbox
10
 *
11
 * A user modifiable checkbox on a UserDefinedForm
12
 *
13
 * @package userforms
14
 */
15
16
class EditableCheckbox extends EditableFormField
17
{
18
    private static $singular_name = 'Checkbox Field';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
19
20
    private static $plural_name = 'Checkboxes';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
21
22
    protected $jsEventHandler = 'click';
23
24
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
25
        'CheckedDefault' => 'Boolean' // from CustomSettings
26
    ];
27
28
    private static $table_name = 'EditableCheckbox';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
29
30
    /**
31
     * @return FieldList
0 ignored issues
show
Bug introduced by
The type SilverStripe\UserForms\M...ableFormField\FieldList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
     */
33
    public function getCMSFields()
34
    {
35
        $fields = parent::getCMSFields();
36
37
        $fields->replaceField('Default', CheckboxField::create(
38
            "CheckedDefault",
39
            _t('SilverStripe\\UserForms\\Model\\EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
40
        ));
41
42
        return $fields;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $fields returns the type SilverStripe\Forms\FieldList which is incompatible with the documented return type SilverStripe\UserForms\M...ableFormField\FieldList.
Loading history...
43
    }
44
45
    public function getFormField()
46
    {
47
        $field = CheckboxField::create($this->Name, $this->Title ?: false, $this->CheckedDefault)
0 ignored issues
show
Bug Best Practice introduced by
The property CheckedDefault does not exist on SilverStripe\UserForms\M...mField\EditableCheckbox. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
            ->setFieldHolderTemplate(__CLASS__ . '_holder')
49
            ->setTemplate(__CLASS__);
50
51
        $this->doUpdateFormField($field);
52
53
        return $field;
54
    }
55
56
    public function getValueFromData($data)
57
    {
58
        $value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
59
60
        return ($value)
61
            ? _t('SilverStripe\\UserForms\\Model\\EditableFormField.YES', 'Yes')
62
            : _t('SilverStripe\\UserForms\\Model\\EditableFormField.NO', 'No');
63
    }
64
65
    public function isCheckBoxField()
66
    {
67
        return true;
68
    }
69
}
70