onOffSwitch::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 3
eloc 8
nc 4
nop 2
1
<?php
2
3
namespace Code4\Forms\Fields;
4
5
use Code4\Forms\Traits\checkedTrait;
6
use Code4\Forms\Traits\groupFieldTrait;
7
8
class onOffSwitch extends AbstractField {
9
10
    use checkedTrait;
11
12
    protected $_view = 'onOffSwitch';
13
    protected $_type = 'onOffSwitch';
14
15
    public function __construct($itemId, $config) {
16
17
        if (array_key_exists('group', $config)) {
18
            $this->group($config['group']);
0 ignored issues
show
Documentation Bug introduced by
The method group does not exist on object<Code4\Forms\Fields\onOffSwitch>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
19
            unset($config['group']);
20
        }
21
22
        parent::__construct($itemId, $config);
23
24
        if (array_key_exists('checked', $config)) {
25
            $this->checked = true;
26
        }
27
28
        $this->attributes()->add('class', 'onoffswitch-checkbox');
29
    }
30
}