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

Multiple::setValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
  namespace Fiv\Form\Element;
4
5
  /**
6
   *
7
   * @author  Ivan Shcherbak <[email protected]>
8
   * @package Fiv\Form\Html
9
   */
10
  class Multiple extends \Fiv\Form\Element\BaseElement {
11
12
    /**
13
     * @var array
14
     */
15
    protected $options = [];
16
17
18
    /**
19
     * @param array $values
20
     * @return $this
21
     */
22 6
    public function setOptions($values) {
23 6
      $this->options = $values;
24 6
      return $this;
25
    }
26
27
28
    /**
29
     * @return array
30
     */
31
    public function getOptions() {
32
      return $this->options;
33
    }
34
35
36
    /**
37
     * @param string $value
38
     * @return $this
39
     */
40 2
    public function setValue($value) {
41 2
      if (!isset($this->options[$value])) {
42
        reset($this->options);
43
        $value = key($this->options);
44
      }
45
46 2
      return parent::setValue($value);
47
    }
48
49
  }