Passed
Branch master (41990d)
by Gabor
03:31
created

InputElement::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Form\Element\Web;
13
14
/**
15
 * Class InputElement.
16
 */
17
class InputElement extends AbstractElement
18
{
19
    /** @var string */
20
    protected $type = 'text';
21
    /** @var array */
22
    private $availableInputTypes = [
23
        'color',
24
        'date',
25
        'datetime',
26
        'datetime-local',
27
        'email',
28
        'image',
29
        'month',
30
        'number',
31
        'range',
32
        'search',
33
        'tel',
34
        'text',
35
        'time',
36
        'url',
37
        'week',
38
    ];
39
40
    /**
41
     * SelectElement constructor.
42
     *
43
     * @param string $name
44
     * @param string $label
45
     * @param mixed  $value
46
     */
47 5
    public function __construct($name = '', $label = '', $value = null)
48
    {
49 5
        parent::__construct($name, $label, $value);
50
51 5
        $this->setTabIndex();
52 5
    }
53
54
    /**
55
     * Resets the object when cloning.
56
     */
57 1
    public function __clone()
58
    {
59 1
        parent::__clone();
60
61 1
        $this->setTabIndex();
62 1
    }
63
64
    /**
65
     * Sets input element type.
66
     *
67
     * @param string $type
68
     * @return InputElement
69
     */
70 1
    public function setType($type = 'text')
71
    {
72 1
        if (in_array($type, $this->availableInputTypes)) {
73 1
            $this->type = $type;
74 1
        }
75
76 1
        return $this;
77
    }
78
}
79