Completed
Pull Request — master (#28)
by Vitaliy
04:03
created

Multiple::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
nc 1
cc 1
eloc 2
nop 0
crap 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
   * @package Fiv\Form\Html
11
   */
12
  class Multiple extends BaseElement {
13
14
    /**
15
     * @var array
16
     */
17
    protected $options = [];
18
19
20
    /**
21
     * @param array $values
22
     * @return $this
23
     */
24 6
    public function setOptions($values) {
25 6
      $this->options = $values;
26 6
      return $this;
27
    }
28
29
30
    /**
31
     * @return array
32
     */
33
    public function getOptions() {
34
      return $this->options;
35
    }
36
37
38
    /**
39
     * @inheritdoc
40
     */
41 2
    public function handle(FormData $data) {
42 2
      $this->setValue($data->get($this->getName()));
43 2
    }
44
45
46
    /**
47
     * @param string $value
48
     * @return $this
49
     */
50 2
    public function setValue($value) {
51 2
      if (!isset($this->options[$value])) {
52 2
        reset($this->options);
53 2
        $value = key($this->options);
54
      }
55
56 2
      return parent::setValue($value);
57
    }
58
59
  }