Completed
Push — master ( d70912...e1269d )
by Shcherbak
03:23
created

Hidden   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 61.11%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 60
ccs 11
cts 18
cp 0.6111
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValue() 0 4 1
A getValue() 0 3 1
A handle() 0 4 1
A getName() 0 3 1
A render() 0 7 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 3
    public function __construct(string $name, string $value = null) {
24 3
      $this->name = $name;
25 3
      $this->value = $value ?? '';
26 3
    }
27
28
29
    public function setValue(string $value) : self {
30
      $this->value = $value;
31
      return $this;
32
    }
33
34
35
    public function getValue() : string {
36
      return $this->value;
37
    }
38
39
40
    /**
41
     * @param FormData $request
42
     * @return $this
43
     */
44
    public function handle(FormData $request) {
45
      # Hidden element can not be  changed via user data
46
      return $this;
47
    }
48
49
50
    /**
51
     * @return string
52
     */
53 3
    public function getName() {
54 3
      return $this->name;
55
    }
56
57
58
    /**
59
     * @return string
60
     */
61 3
    public function render() {
62 3
      return Html::tag('input', [
63 3
        'type' => 'hidden',
64 3
        'name' => $this->getName(),
65 3
        'value' => htmlentities($this->value, ENT_QUOTES),
66
      ]);
67
    }
68
69
  }