Passed
Push — master ( 935f6a...526326 )
by Gabriel
36:15 queued 01:14
created

generateElementJavscript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 31
ccs 0
cts 14
cp 0
rs 9.6
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
class Nip_Form_Renderer_Elements_Dateinput extends Nip_Form_Renderer_Elements_Input
4
{
5
    public function generateElement()
6
    {
7
        if (!$this->getElement()->getAttrib('id')) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getElement()->getAttrib('id') targeting Nip\Form\Elements\AbstractElement::getAttrib() 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()->setAttrib('id', $this->getElement()->getJSID());
9
            $this->getElement()->addClass('datepicker');
10
        }
11
        $return = parent::generateElement();
12
//        $return .= $this->generateElementJavscript();
13
        return $return;
14
    }
15
16
    protected function generateElementJavscript()
17
    {
18
        $return = '<script type="text/javascript">';
19
        $return .= 'document.addEventListener("DOMContentLoaded", function() {';
20
21
        $options = [];
22
        $options[] = 'changeMonth: true';
23
        $options[] = 'changeYear: true';
24
25
        $yearRange = $this->getElement()->getOption('yearRange');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $yearRange is correct as $this->getElement()->getOption('yearRange') targeting Nip\Form\Elements\AbstractElement::getOption() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
26
        if ($yearRange) {
0 ignored issues
show
introduced by
$yearRange is of type null, thus it always evaluated to false.
Loading history...
27
            $options[] = 'yearRange: "' . $yearRange . '"';
28
        }
29
        $format = $this->getElement()->getFormat();
0 ignored issues
show
Bug introduced by
The method getFormat() does not exist on Nip\Form\Elements\AbstractElement. Did you maybe mean getForm()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $format = $this->getElement()->/** @scrutinizer ignore-call */ getFormat();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
        $format = strtr(
31
            $format,
32
            [
33
                'Y' => 'yy',
34
                'd' => 'dd',
35
                'm' => 'mm',
36
            ]
37
        );
38
        $options[] = 'dateFormat: "' . $format . '"';
39
40
        $return .= "    jQuery('#{$this->getElement()->getAttrib('id')}').datepicker({
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getElement()->getAttrib('id') targeting Nip\Form\Elements\AbstractElement::getAttrib() 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...
41
			" . implode(',', $options) . "
42
		});";
43
        $return .= '});';
44
        $return .= '</script>';
45
46
        return $return;
47
    }
48
}
49