Nip_Form_Renderer_Elements_RadioGroup   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkDefaultValue() 0 7 4
A generateElement() 0 5 1
1
<?php
2
3
/**
4
 * Class Nip_Form_Renderer_Elements_RadioGroup
5
 *
6
 * @method \Nip_Form_Element_RadioGroup getElement()
7
 */
8
class Nip_Form_Renderer_Elements_RadioGroup extends Nip_Form_Renderer_Elements_Input_Group
9
{
10
    /**
11
     * @return string
12
     */
13 5
    public function generateElement()
14
    {
15 5
        $this->checkDefaultValue();
16
17 5
        return parent::generateElement();
18
    }
19
20 5
    protected function checkDefaultValue()
21
    {
22 5
        if (!$this->getElement()->hasValue() && $this->getElement()->isAutoSelectFirst()) {
23 4
            $elements = $this->getElement()->getElements();
24 4
            if ($elements) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $elements 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...
25 2
                $element = reset($elements);
26 2
                $element->setChecked(true);
27
            }
28
        }
29 5
    }
30
}
31