TextField   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A asPassword() 0 3 1
A asPhone() 0 3 1
A value() 0 7 2
A withSubtype() 0 3 1
A asEmail() 0 3 1
A asTel() 0 3 1
A subtype() 0 3 1
1
<?php
2
3
namespace ArgentCrusade\Forms\Fields;
4
5
use ArgentCrusade\Forms\FormField;
6
7
class TextField extends FormField
8
{
9
    protected $type = 'text';
10
11
    /**
12
     * Get field value.
13
     *
14
     * @return mixed
15
     */
16
    public function value()
17
    {
18
        if ($this->subtype() === 'password') {
19
            return '';
20
        }
21
22
        return parent::value();
23
    }
24
25
    /**
26
     * Mark field as email.
27
     *
28
     * @return TextField
29
     */
30
    public function asEmail()
31
    {
32
        return $this->withSubtype('email');
33
    }
34
35
    /**
36
     * Mark field as password.
37
     *
38
     * @return TextField
39
     */
40
    public function asPassword()
41
    {
42
        return $this->withSubtype('password');
43
    }
44
45
    /**
46
     * Mark field as phone.
47
     *
48
     * @return TextField
49
     */
50
    public function asPhone()
51
    {
52
        return $this->asTel();
53
    }
54
55
    /**
56
     * Mark field as phone.
57
     *
58
     * @return TextField
59
     */
60
    public function asTel()
61
    {
62
        return $this->withSubtype('tel');
63
    }
64
65
    /**
66
     * Set field subtype.
67
     *
68
     * @param string $subtype
69
     *
70
     * @return TextField
71
     */
72
    public function withSubtype(string $subtype = 'text')
73
    {
74
        return $this->withAttribute('type', $subtype);
75
    }
76
77
    /**
78
     * Get field subtype.
79
     *
80
     * @return string
81
     */
82
    public function subtype()
83
    {
84
        return $this->getAttribute('type', 'text');
85
    }
86
}
87