Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

generateElement()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.8666
cc 3
nc 4
nop 0
crap 12
1
<?php
2
3
class Nip_Form_Renderer_Elements_Checkbox extends Nip_Form_Renderer_Elements_Input_Abstract
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...
4
{
5
    public function generateElement()
6
    {
7
        if (!$this->getElement()->getValue()) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getElement()->getValue() targeting Nip\Form\Elements\AbstractElement::getValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
8
            $this->getElement()->setValue('on');
9
        }
10
        $this->getElement()->removeClass('form-control');
11
        $this->getElement()->addClass('form-check-input');
12
13
        $class = get_class($this->getRenderer()) == Nip_Form_Renderer_Bootstrap::class ? 'checkbox' : 'form-check';
14
        $return = '<div class="'.$class.'">';
15
        $return .= '<label class="form-check-label">';
16
        $return .= parent::generateElement();
17
        $return .= ' '.$this->getElement()->getLabel();
18
        $return .= '</label>';
19
        $return .= '</div>';
20
21
        return $return;
22
    }
23
24
    public function getelementattribs()
25
    {
26
        $attribs = parent::getelementattribs();
27
        $attribs[] = 'checked';
28
29
        return $attribs;
30
    }
31
}
32