Completed
Pull Request — 2.x (#43)
by jake
02:49 queued 50s
created

Radio   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 26.32%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 1
cbo 1
dl 0
loc 45
ccs 5
cts 19
cp 0.2632
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 12 2
A multiple() 0 15 2
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Html\Helper\Input;
10
11
/**
12
 *
13
 * An HTML radio input.
14
 *
15
 * @package Aura.Html
16
 *
17
 */
18
class Radio extends AbstractChecked
19
{
20
    /**
21
     *
22
     * Returns the HTML for the input.
23
     *
24
     * @return string
25
     *
26
     */
27
    public function __toString()
28
    {
29
        $this->attribs['type'] = 'radio';
30
31
        if ($this->options) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->options of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            return $this->multiple();
33
        }
34
35
        $input = $this->htmlChecked();
36
        $html  = $this->htmlLabel($input);
37
        return $this->indent(0, $html);
38
    }
39
40
    /**
41
     *
42
     * Returns the HTML for multiple radios.
43
     *
44
     * @return string
45
     *
46
     */
47 2
    protected function multiple()
48
    {
49 2
        $html = '';
50 2
        $radio = clone($this);
51 2
        foreach ($this->options as $value => $label) {
52
            $this->attribs['value'] = $value;
53
            $this->attribs['label'] = $label;
54
            $html .= $radio(array(
55
                'name'    => $this->name,
56
                'value'   => $this->value,
57
                'attribs' => $this->attribs
58
            ));
59
        }
60 2
        return $html;
61
    }
62
}
63