Completed
Push — master ( 3a35d5...02819f )
by Gabriel
08:58
created

checkDefaultValue()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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