Completed
Push — master ( e1269d...14565d )
by Shcherbak
02:35
created

Hidden::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
  declare(strict_types=1);
4
5
  namespace Fiv\Form\Element;
6
7
  use Fiv\Form\Elements\DataElementInterface;
8
  use Fiv\Form\FormData;
9
10
  class Hidden implements DataElementInterface {
11
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
17
    /**
18
     * @var string
19
     */
20
    private $value;
21
22
23 8
    public function __construct(string $name, string $value = null) {
24 8
      $this->name = $name;
25 8
      $this->value = $value ?? '';
26 8
    }
27
28
29 5
    public function setValue(string $value) : self {
30 5
      $this->value = $value;
31 5
      return $this;
32
    }
33
34
35 5
    public function getValue() : string {
36 5
      return $this->value;
37
    }
38
39
40
    /**
41
     * @param FormData $request
42
     * @return $this
43
     */
44 5
    public function handle(FormData $request) {
45 5
      $value = $request->get($this->getName());
46 5
      $this->setValue((string) $value);
47 5
      return $this;
48
    }
49
50
51
    /**
52
     * @return string
53
     */
54 8
    public function getName() {
55 8
      return $this->name;
56
    }
57
58
59
    /**
60
     * @return string
61
     */
62 3
    public function render() {
63 3
      return Html::tag('input', [
64 3
        'type' => 'hidden',
65 3
        'name' => $this->getName(),
66 3
        'value' => htmlentities($this->value, ENT_QUOTES),
67
      ]);
68
    }
69
70
  }