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

Multiple   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 1
cbo 2
dl 0
loc 48
ccs 11
cts 13
cp 0.8462
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 4 1
A getOptions() 0 3 1
A handle() 0 3 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
   * @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
  }