TextArea   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 80
ccs 0
cts 30
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 5 1
A handle() 0 4 1
A setValue() 0 4 1
A setText() 0 4 1
A getText() 0 3 1
A getValue() 0 3 1
A getName() 0 3 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
    public function __construct(string $name, string $value = null) {
38
      $this->name = $name;
39
      $this->value = $value ?? '';
40
    }
41
42
43
    /**
44
     * @return string
45
     */
46
    public function render() {
47
      return Html::tag('textarea', [
48
        'name' => $this->getName(),
49
      ], $this->value);
50
    }
51
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function handle(FormData $data) {
57
      $this->setValue((string) $data->get($this->getName()));
58
      return $this;
59
    }
60
61
62
    public function setValue(string $value) : self {
63
      $this->value = $this->filterValue((string) $value);
64
      return $this;
65
    }
66
67
68
    public function setText(string $text) : self {
69
      $this->text = $text;
70
      return $this;
71
    }
72
73
74
    /**
75
     * @return string|null
76
     */
77
    public function getText() {
78
      return $this->text;
79
    }
80
81
82
    public function getValue() : string {
83
      return $this->value;
84
    }
85
86
87
    /**
88
     * @return string
89
     */
90
    public function getName() {
91
      return $this->name;
92
    }
93
94
  }