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

Radio::multiple()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.7938

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 5
cts 12
cp 0.4167
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
crap 2.7938
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