Completed
Branch master (44f723)
by Michael
11:35 queued 08:26
created

PedigreeRadioButton::showValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * Pedigree module for XOOPS
13
 *
14
 * @copyright   {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project}
15
 * @copyright   {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
16
 * @license     GPL 2.0 or later
17
 * @package     pedigree
18
 * @subpackage  class
19
 * @author      XOOPS Mod Development Team
20
 */
21
22
/**
23
 * Class PedigreeRadioButton
24
 */
25
require_once __DIR__ . '/htmlinput.abstract.php';
26
27
/**
28
 * Class PedigreeRadioButton
29
 */
30
class PedigreeRadioButton extends PedigreeHtmlInputAbstract
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...
31
{
32
    // Define class variables
33
    private $fieldnumber;
34
    private $fieldname;
35
    private $value;
36
    private $defaultvalue;
37
    private $lookuptable;
38
39
    /**
40
     * Constructor
41
     *
42
     * @todo move hard coded language string to language file
43
     *
44
     * @param object $parentObject {@see PedigreeField}
45
     * @param object $animalObject {@see PedigreeAnimal}
46
     */
47 View Code Duplication
    public function __construct($parentObject, $animalObject)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $this->fieldnumber  = $parentObject->getId();
50
        $this->fieldname    = $parentObject->FieldName;
51
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
52
        $this->defaultvalue = $parentObject->defaultvalue;
53
        $this->lookuptable  = $parentObject->LookupTable;
54
        if (0 == $this->lookuptable) {
55
            echo "<span style='color: red;'><h3>A lookuptable must be specified for userfield" . $this->fieldnumber . '</h3></span>';
56
        }
57
    }
58
59
    /**
60
     * @return object {@see XoopsFormRadio}
61
     */
62
    public function editField()
63
    {
64
        $radio          = new XoopsFormRadio('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value);
65
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of editField()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
66
        $lcCount        = count($lookupcontents);
67
        for ($i = 0; $i < $lcCount; ++$i) {
68
            $radio->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
69
        }
70
71
        return $radio;
72
    }
73
74
    /**
75
     * @param string $name
76
     *
77
     * @return object {@see XoopsFormRadio)
78
     */
79
    public function newField($name = '')
80
    {
81
        $radio          = new XoopsFormRadio('<b>' . $this->fieldname . '</b>', "{$name}user" . $this->fieldnumber, $value = $this->defaultvalue);
82
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of newField()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
83
        $lcCount        = count($lookupcontents);
84
        for ($i = 0; $i < $lcCount; ++$i) {
85
            $radio->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
86
        }
87
88
        return $radio;
89
    }
90
91
    /**
92
     * @return object {@see XoopsFormLabel}
93
     */
94
    public function viewField()
95
    {
96
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of viewField()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
97
        $lcCount        = count($lookupcontents);
98
        for ($i = 0; $i < $lcCount; ++$i) {
99
            if ($lookupcontents[$i]['id'] == $this->value) {
100
                $choosenvalue = $lookupcontents[$i]['value'];
101
            }
102
        }
103
        $view = new XoopsFormLabel($this->fieldname, $choosenvalue);
0 ignored issues
show
Bug introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
104
105
        return $view;
106
    }
107
108
    /**
109
     *
110
     * @todo error checking
111
     * @return string
112
     */
113 View Code Duplication
    public function showField()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of showField()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
116
        $lcCount        = count($lookupcontents);
117
        for ($i = 0; $i < $lcCount; ++$i) {
118
            if ($lookupcontents[$i]['id'] == $this->value) {
119
                $choosenvalue = $lookupcontents[$i]['value'];
120
            }
121
        }
122
123
        return $this->fieldname . ' : ' . $choosenvalue;
0 ignored issues
show
Bug introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
124
    }
125
126
    /**
127
     * @return mixed
128
     */
129 View Code Duplication
    public function showValue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of showValue()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
132
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
133
            if ($lookupcontents[$i]['id'] == $this->value) {
134
                $choosenvalue = $lookupcontents[$i]['value'];
135
            }
136
        }
137
138
        return $choosenvalue;
0 ignored issues
show
Bug introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
139
    }
140
141
    /**
142
     * @return string HTML <select> for this field
143
     */
144 View Code Duplication
    public function searchField()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $select         = "<select size='1' name='query' style='width: 140px;'>";
147
        $lookupcontents = parent::lookupField($this->fieldnumber);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (lookupField() instead of searchField()). Are you sure this is correct? If so, you might want to change this to $this->lookupField().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
148
        $lcCount        = count($lookupcontents);
149
        for ($i = 0; $i < $lcCount; ++$i) {
150
            $select .= "<option value='" . $lookupcontents[$i]['id'] . "'>" . $lookupcontents[$i]['value'] . '</option>';
151
        }
152
        $select .= '</select>';
153
154
        return $select;
155
    }
156
157
    /**
158
     *
159
     */
160
    public function getSearchString()
161
    {
162
    }
163
}
164