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

Nip_Form_Renderer_Elements_Dateselect   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 33
c 1
b 0
f 0
dl 0
loc 50
ccs 0
cts 32
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateElement() 0 14 3
A generateElement2() 0 32 3
1
<?php
2
3
class Nip_Form_Renderer_Elements_Dateselect extends Nip_Form_Renderer_Elements_MultiElement
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
        $return = '<div class="row">';
8
9
        $elements = $this->getElement()->getElements();
0 ignored issues
show
Bug introduced by
The method getElements() does not exist on Nip_Form_Element_Abstract. It seems like you code against a sub-type of Nip_Form_Element_Abstract such as Nip_Form_Element_MultiElement or Nip_Form_Element_Input_Group. ( Ignorable by Annotation )

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

9
        $elements = $this->getElement()->/** @scrutinizer ignore-call */ getElements();
Loading history...
10
        foreach ($elements as $key => $element) {
11
            $element->addClass('form-control');
12
            $returnElements[] = '<div class="col-xs-4" style="max-width:' . ($key == 'day' ? 95 : 110) . 'px;">' .
13
                $element->render() . '</div>';
14
        }
15
16
        $return .= implode(' ', $returnElements);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $returnElements seems to be defined by a foreach iteration on line 10. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
17
        $return .= '</div>';
18
        return $return;
19
    }
20
21
    public function generateElement2()
22
    {
23
        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...
24
            $this->getElement()->setAttrib('id', $this->getElement()->getJSID());
25
            $this->getElement()->addClass('datepicker');
26
        }
27
        $return = parent::generateElement();
28
        $return .= '<script type="text/javascript">';
29
        $return .= 'document.addEventListener("DOMContentLoaded", function() {';
30
31
        $options = [];
32
        $options[] = 'changeMonth: true';
33
        $options[] = 'changeYear: true';
34
35
        $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...
36
        if ($yearRange) {
0 ignored issues
show
introduced by
$yearRange is of type null, thus it always evaluated to false.
Loading history...
37
            $options[] = 'yearRange: "' . $yearRange . '"';
38
        }
39
        $format = $this->getElement()->getFormat();
0 ignored issues
show
Bug introduced by
The method getFormat() does not exist on Nip_Form_Element_Abstract. 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

39
        $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...
40
        $format = strtr($format, [
41
            'Y' => 'yy',
42
            'd' => 'dd',
43
            'm' => 'mm',
44
        ]);
45
        $options[] = 'dateFormat: "' . $format . '"';
46
47
        $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...
48
			" . implode(',', $options) . "
49
		});";
50
        $return .= '});';
51
        $return .= '</script>';
52
        return $return;
53
    }
54
}
55