GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nip_Form_Renderer_Elements_Select::renderOptions()   D
last analyzed

Complexity

Conditions 10
Paths 20

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 23
nc 20
nop 1
dl 0
loc 32
ccs 0
cts 22
cp 0
crap 110
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
class Nip_Form_Renderer_Elements_Select extends Nip_Form_Renderer_Elements_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...
3
    
4
    public function generateElement() {        
5
        $return = '<select ';
6
        $return .= $this->renderAttributes();
7
        $return .= ' >'. $this->renderOptions() .'</select>';
8
        return $return;
9
    }
10
11
    public function renderOptions($options = false) {
12
        $options = $options ? $options : $this->getElement()->getOptions();
0 ignored issues
show
Bug introduced by
The method getOptions() does not exist on Nip_Form_Element_Abstract. Did you maybe mean getOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
13
        $return = '';
14
        foreach ($options as $value=>$atribs) {
15
            if (is_string($value) && !isset($atribs['label'])) {
16
                $return .= '<optgroup label="' . $value . '">';
17
                $return .= $this->renderOptions($atribs);
18
                $return .= '</optgroup>';
19
            } else {
20
                $return .= '<option';
21
22
                $label = $atribs['label'];
23
                unset ($atribs['label']);
24
25
                $atribs['value'] = $value;
26
                $selectedValue = $this->getElement()->getValue();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $selectedValue is correct as $this->getElement()->getValue() (which targets Nip_Form_Element_Abstract::getValue()) 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...
27
                if ($selectedValue === 0 OR $value=== 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
28
                    if ($value === $selectedValue) {
29
                        $atribs['selected'] = 'selected';
30
                    }
31
                } elseif ($this->getElement()->getValue() == $value) {
32
                    $atribs['selected'] = 'selected';
33
                }
34
                
35
                foreach ($atribs as $name=>$value) {
36
                    $return .= ' ' . $name . '="' . $value . '"';
37
                }
38
                $return .= '>'.$label.'</option>';
39
            }
40
        }
41
        return $return;
42
    }
43
44
    public function getElementAttribs() {
45
        $attribs = parent::getElementAttribs();
46
        return $attribs;
47
    }
48
49
   
50
}