Completed
Push — master ( fcb641...65474d )
by Derek Stephen
04:39
created

CheckBox   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 49
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTag() 0 4 1
A init() 0 6 1
A checkValue() 0 6 1
A uncheckValue() 0 12 3
1
<?php
2
3
namespace Del\Form\Field;
4
5
use Del\Form\Renderer\Field\CheckboxRender;
6
use Del\Form\Traits\CanRenderInlineTrait;
7
use Del\Form\Traits\HasOptionsTrait;
8
9
class CheckBox extends FieldAbstract implements ArrayValueInterface
10
{
11
12
    use CanRenderInlineTrait;
13
    use HasOptionsTrait;
14
15
    /**
16
     * We end up ignoring this during rendering Checkboxes, see the renderer for info
17
     *
18
     * @return string
19
     */
20 8
    public function getTag(): string
21
    {
22 8
        return 'div';
23
    }
24
25 11
    public function init(): void
26
    {
27 11
        $this->setValue([]);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28 11
        $this->setRenderInline(false);
29 11
        $this->setRenderer(new CheckboxRender());
30 11
    }
31
32
    /**
33
     * @param $key
34
     */
35 2
    public function checkValue($key): void
36
    {
37 2
        $values = $this->getValue();
38 2
        $values[$key] = true;
39 2
        $this->setValue($values);
40 2
    }
41
42
    /**
43
     * @param $key
44
     */
45 1
    public function uncheckValue($key): void
46
    {
47 1
        $value = $this->getValue();
48
49 1
        if (is_array($value) && in_array($key, $value, true)) {
50 1
            $index = array_search($key, $value, true);
51 1
            unset($value[$index]);
52 1
            $this->setValue($value);
0 ignored issues
show
Documentation introduced by
$value is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
        } else {
54 1
            $this->setValue(null);
55
        }
56
    }
57
}