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

Multiple::setValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
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
  }