Passed
Branch main (e68017)
by James Ekow Abaka
10:11
created

Field::isContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ntentan\honam\engines\php\helpers\form;
4
5
6
/**
7
 * The form field class. 
8
 * This class represents a form field element. Subclasses of this class are to be used to capture information from the 
9
 * user of the application.
10
 */
11
class Field extends Element
12
{
13
    /**
14
     * A flag for setting the required state of the form. If this value
15
     * is set as true then the form would not be validated if there is
16
     * no value entered into this field.
17
     */
18
    public $required = false;
19
20
    /**
21
     * The value of the form field.
22
     */
23
    protected $value;
24
25
    /**
26
     * The constructor for the field element.
27
     */
28
    public function __construct(string $name = "", string $value = "")
29
    {
30
        $this->name = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name of type string is incompatible with the declared type ntentan\honam\engines\php\helpers\form\Element of property $name.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
        $this->value = $value;
32
    }
33
34
    /**
35
     * Sets the value of the field.
36
     *
37
     * @param string $value The value of the field.
38
     * @return Field
39
     */
40
    public function setValue(string $value): Field
41
    {
42
        $this->value = $value;
43
        return $this;
44
    }
45
46
    /**
47
     * Get the value of the field.
48
     *
49
     * @return mixed
50
     */
51
    public function getValue(): ?string
52
    {
53
        return $this->value;
54
    }
55
56
    /**
57
     * Sets the required status of the field.
58
     *
59
     * @param boolean $required
60
     * @return Field
61
     */
62
    public function setRequired(bool $required): Field
63
    {
64
        $this->required = $required;
65
        return $this;
66
    }
67
68
    /**
69
     * Returns the required status of the field.
70
     *
71
     * @return bool
72
     */
73
    public function getRequired(): bool
74
    {
75
        return $this->required;
76
    }
77
78
    /**
79
     * @param $data
80
     */
81
    public function setData(array $data): Field
82
    {
83
        if (array_search($this->getName(), array_keys($data)) !== false) {
84
            $this->setValue($data[$this->getName()]);
85
        }
86
        return $this;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function render()
93
    {
94
        $this->setAttribute("name", $this->getName());
95
        return $this->templateRenderer->render("input_element.tpl.php", array('element' => $this));
96
    }
97
98
    public function isContainer()
99
    {
100
        return false;
101
    }    
102
}
103