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

RadioList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 25
ccs 11
cts 12
cp 0.9167
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 19 3
1
<?php
2
3
  namespace Fiv\Form\Element;
4
5
  /**
6
   * Generate <input type="radio"> html tag
7
   *
8
   * @author  Ivan Shcherbak <[email protected]>
9
   * @package Fiv\Form
10
   */
11
  class RadioList extends Multiple {
12
13
    /**
14
     * @return string
15
     */
16 1
    public function render() {
17 1
      $html = '';
18 1
      $currentValue = $this->getValue();
19 1
      $attributes = $this->attributes;
20 1
      $attributes['type'] = 'radio';
21
22 1
      foreach ($this->options as $value => $text) {
23 1
        $attributes['value'] = $value;
24 1
        if ($currentValue == $value) {
25
          $attributes['checked'] = 'checked';
26
        } else {
27 1
          unset($attributes['checked']);
28
        }
29
30 1
        $html .= '<label>' . static::tag('input', $attributes) . $text . '</label>';
31
      }
32
33 1
      return $html;
34
    }
35
  }