RadioList::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 16
cp 0
rs 9.4285
cc 3
eloc 13
nc 3
nop 0
crap 12
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
   */
10
  class RadioList extends Multiple {
11
12
    /**
13
     * @return string
14
     */
15
    public function render() {
16
      $html = '';
17
      $currentValue = $this->getValue();
18
      $attributes = $this->attributes;
19
      $attributes['type'] = 'radio';
20
21
      foreach ($this->options as $value => $text) {
22
        $attributes['value'] = $value;
23
        if ($currentValue == $value) {
24
          $attributes['checked'] = 'checked';
25
        } else {
26
          unset($attributes['checked']);
27
        }
28
29
        $html .= '<label>' . static::tag('input', $attributes) . $text . '</label>';
30
      }
31
32
      return $html;
33
    }
34
  }