Failed Conditions
Push — psr2-config ( de33cd...0a5b05 )
by Andreas
08:47 queued 04:28
created

SettingOnoff   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A html() 0 18 4
B update() 0 10 5
1
<?php
2
3
namespace dokuwiki\plugin\config\core\Setting;
4
5
/**
6
 * Class setting_onoff
7
 */
8
class SettingOnoff extends SettingNumeric {
9
    /** @inheritdoc */
10
    public function html(\admin_plugin_config $plugin, $echo = false) {
11
        $disable = '';
12
13
        if($this->isProtected()) {
14
            $value = $this->protected;
15
            $disable = ' disabled="disabled"';
16
        } else {
17
            $value = is_null($this->local) ? $this->default : $this->local;
18
        }
19
20
        $key = htmlspecialchars($this->key);
21
        $checked = ($value) ? ' checked="checked"' : '';
22
23
        $label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
24
        $input = '<div class="input"><input id="config___' . $key . '" name="config[' . $key .
25
            ']" type="checkbox" class="checkbox" value="1"' . $checked . $disable . '/></div>';
26
        return array($label, $input);
27
    }
28
29
    /** @inheritdoc */
30
    public function update($input) {
31
        if($this->isProtected()) return false;
32
33
        $input = ($input) ? 1 : 0;
34
        $value = is_null($this->local) ? $this->default : $this->local;
35
        if($value == $input) return false;
36
37
        $this->local = $input;
38
        return true;
39
    }
40
}
41