checkDefaultValue()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
cc 4
nc 3
nop 0
crap 4
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