Completed
Push — master ( 2c052a...11c889 )
by Shcherbak
11s
created

Multiple   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 18
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 4 1
A getOptions() 0 3 1
A handle() 0 4 1
A setValue() 0 8 2
1
<?php
2
3
  namespace Fiv\Form\Element;
4
5
  use Fiv\Form\FormData;
6
7
  /**
8
   *
9
   * @author Ivan Shcherbak <[email protected]>
10
   */
11
  class Multiple extends BaseElement {
12
13
    /**
14
     * @var array
15
     */
16
    protected $options = [];
17
18
19
    /**
20
     * @param array $values
21
     * @return $this
22
     */
23
    public function setOptions($values) {
24
      $this->options = $values;
25
      return $this;
26
    }
27
28
29
    /**
30
     * @return array
31
     */
32
    public function getOptions() {
33
      return $this->options;
34
    }
35
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function handle(FormData $data) {
41
      $this->setValue($data->get($this->getName()));
42
      return $this;
43
    }
44
45
46
    /**
47
     * @param string $value
48
     * @return $this
49
     */
50
    public function setValue($value) {
51
      if (!isset($this->options[$value])) {
52
        reset($this->options);
53
        $value = key($this->options);
54
      }
55
56
      return parent::setValue($value);
57
    }
58
59
  }