Completed
Push — master ( ec6e44...6e7b68 )
by Shcherbak
03:21
created

TextArea::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
  namespace Fiv\Form\Element;
4
5
  use Fiv\Form\Elements\StringDataElementInterface;
6
  use Fiv\Form\Filter\StringFilter\StringFilterTrait;
7
  use Fiv\Form\FormData;
8
  use Fiv\Form\Validation\StringValidation\StringValidationTrait;
9
10
  /**
11
   * Generate <textarea></textarea> html tag
12
   *
13
   * @author Ivan Shcherbak <[email protected]>
14
   */
15
  class TextArea implements StringDataElementInterface {
16
17
    use StringFilterTrait;
18
    use StringValidationTrait;
19
20
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * @var string
28
     */
29
    private $value;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $text = null;
35
36
37 7
    public function __construct(string $name, string $value = null) {
38 7
      $this->name = $name;
39 7
      $this->value = $value ?? '';
40 7
    }
41
42
43
    /**
44
     * @return string
45
     */
46 2
    public function render() {
47 2
      return Html::tag('textarea', [
48 2
        'name' => $this->getName(),
49 2
      ], $this->value);
50
    }
51
52
53
    /**
54
     * @inheritdoc
55
     */
56 2
    public function handle(FormData $data) {
57 2
      $this->setValue((string) $data->get($this->getName()));
58 2
      return $this;
59
    }
60
61
62 4
    public function setValue(string $value) : self {
63 4
      $this->value = $this->filterValue((string) $value);
64 4
      return $this;
65
    }
66
67
68 1
    public function setText(string $text) : self {
69 1
      $this->text = $text;
70 1
      return $this;
71
    }
72
73
74
    /**
75
     * @return string|null
76
     */
77 1
    public function getText() {
78 1
      return $this->text;
79
    }
80
81
82 3
    public function getValue() : string {
83 3
      return $this->value;
84
    }
85
86
87
    /**
88
     * @return string
89
     */
90 5
    public function getName() {
91 5
      return $this->name;
92
    }
93
94
  }