Checkbox   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValue() 0 5 1
A isChecked() 0 10 2
A getAttributes() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of slick/form package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Form\Input;
11
12
use Slick\Filter\StaticFilter;
13
use Slick\Form\Input\Filter\Boolean;
14
use Slick\Form\InputInterface;
15
use Slick\Form\Renderer\Checkbox as CheckboxRenderer;
16
use Slick\Form\Utils\AttributesMapInterface;
17
18
/**
19
 * Checkbox input
20
 *
21
 * @package Slick\Form\Input
22
 * @author  Filipe Silva <[email protected]>
23
 */
24
class Checkbox  extends AbstractInput implements InputInterface
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
25
{
26
    /**
27
     * @var bool
28
     */
29
    protected $checked = null;
30
31
    /**
32
     * @var string|mixed
33
     */
34
    protected $value = 0;
35
36
    /**
37
     * @var string Renderer class
38
     */
39
    protected $rendererClass = CheckboxRenderer::class;
40
41
    /**
42
     * Crates the input with the attribute type as text
43
     */
44 4
    public function __construct()
45
    {
46 4
        $this->setAttribute('type', 'checkbox');
47 4
    }
48
49
    /**
50
     * Sets the value of the checkbox
51
     *
52
     * @param mixed $value
53
     *
54
     * @return mixed
55
     */
56 2
    public function setValue($value)
57
    {
58 2
        $this->checked = null;
59 2
        return parent::setValue($value);
60
    }
61
62
    /**
63
     * Check whenever the checkbox state is checked
64
     *
65
     * @return bool|mixed
66
     */
67 4
    public function isChecked()
68
    {
69 4
        if (null == $this->checked) {
70 4
            $this->checked = StaticFilter::filter(
71 4
                Boolean::class,
72 4
                $this->getValue()
73 4
            );
74 4
        }
75 4
        return $this->checked;
76
    }
77
78
    /**
79
     * Get the attributes map collection
80
     *
81
     * @return AttributesMapInterface
82
     */
83 4
    public function getAttributes()
84
    {
85 4
        $attributes = parent::getAttributes();
86 4
        if ($this->isChecked()) {
87 2
            $attributes->set('checked', null);
88 2
        }
89 4
        return $attributes;
90
    }
91
92
93
}