Completed
Push — master ( 871d94...af939e )
by Michael
03:14
created

virtual.php ➔ virt()   F

Complexity

Conditions 24
Paths > 20000

Size

Total Lines 162
Code Lines 95

Duplication

Lines 62
Ratio 38.27 %

Importance

Changes 0
Metric Value
cc 24
eloc 95
nc 45360
nop 0
dl 62
loc 162
rs 2
c 0
b 0
f 0

How to fix   Long Method    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
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 34 and the first side effect is on line 4.

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
4
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
6
$moduleDirName = basename(__DIR__);
7
xoops_loadLanguage('main', $moduleDirName);
8
xoops_load('PedigreeAnimal', $moduleDirName);
9
xoops_load('XoopsRequest');
10
11
// Include any common code for this module.
12
require_once(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php');
13
14
$xoopsOption['template_main'] = 'pedigree_virtual.tpl';
15
16
include $GLOBALS['xoops']->path('/header.php');
17
$xoopsTpl->assign('page_title', 'Pedigree database - Virtual Mating');
18
19
//create function variable from url
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
//if (isset($_GET['f'])) {
21
//    $f = $_GET['f'];
22
//}
23
//if (!isset($f)) {
24
$f = XoopsRequest::getString('f', '', 'get');
25
26
if (empty($f)) {
27
    virt();
28
} elseif ($f === 'dam') {
29
    dam();
30
} elseif ($f === 'check') {
31
    check();
32
}
33
34
function virt()
0 ignored issues
show
Coding Style introduced by
virt uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
35
{
36
    global $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
37
38
    //get module configuration
39
    $moduleHandler = xoops_getHandler('module');
40
    $module        = $moduleHandler->getByDirname('pedigree');
41
    $configHandler = xoops_getHandler('config');
42
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
43
44
    //    if (isset($_GET['st'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
    //        $st = $_GET['st'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
    //    } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
    //        $st = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
    //    }
49
    //    if (isset($_GET['l'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
    //        $l = $_GET['l'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
    //    } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
    //        $l = 'A';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
    //    }
54
    $st = XoopsRequest::getInt('st', 0, 'get');
55
    $l  = XoopsRequest::getString('l', 'a', 'get');
56
57
    $xoopsTpl->assign('sire', '1');
58
    //create list of males dog to select from
59
    $perp = $moduleConfig['perpage'];
60
    //count total number of dogs
61
    $numdog = 'SELECT count(d.id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') //            . " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%'";
62
              . " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $GLOBALS['xoopsDB']->escape($l) . "%'";
63
    $numres = $GLOBALS['xoopsDB']->query($numdog);
64
    //total number of dogs the query will find
65
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
66
    //total number of pages
67
    $numpages = floor($numresults / $perp) + 1;
68
    if (($numpages * $perp) == ($numresults + $perp)) {
69
        --$numpages;
70
    }
71
    //find current page
72
    $cpage = floor($st / $perp) + 1;
73
    //create alphabet
74
    $pages = '';
75
    for ($i = 65; $i <= 90; ++$i) {
76
        if ($l == chr($i)) {
77
            $pages .= "<b><a href=\"virtual.php?r=1&st=0&l=" . chr($i) . "\">" . chr($i) . '</a></b>&nbsp;';
78 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
79
            $pages .= "<a href=\"virtual.php?r=1&st=0&l=" . chr($i) . "\">" . chr($i) . '</a>&nbsp;';
80
        }
81
    }
82
    $pages .= '-&nbsp;';
83
    $pages .= "<a href=\"virtual.php?r=1&st=0&l=Ã…\">Ã…</a>&nbsp;";
84
    $pages .= "<a href=\"virtual.php?r=1&st=0&l=Ö\">Ö</a>&nbsp;";
85
    $pages .= '<br />';
86
    //create previous button
87
    if ($numpages > 1) {
88
        if ($cpage > 1) {
89
            $pages .= "<a href=\"virtual.php?r=1&&l=" . $l . 'st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
90
        }
91
    }
92
    //create numbers
93
    for ($x = 1; $x < ($numpages + 1); ++$x) {
94
        //create line break after 20 number
95
        if (($x % 20) == 0) {
96
            $pages .= '<br />';
97
        }
98
        if ($x != $cpage) {
99
            $pages .= "<a href=\"virtual.php?r=1&l=" . $l . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
100
        } else {
101
            $pages .= $x . '&nbsp;&nbsp';
102
        }
103
    }
104
    //create next button
105
    if ($numpages > 1) {
106
        if ($cpage < $numpages) {
107
            $pages .= "<a href=\"virtual.php?r=1&l=" . $l . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
108
        }
109
    }
110
111
    //query
112
    $queryString = 'SELECT d.*, d.id AS d_id, d.naam AS d_naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%' ORDER BY d.naam LIMIT " . $st . ', ' . $perp;
113
    $result      = $GLOBALS['xoopsDB']->query($queryString);
114
115
    $animal = new PedigreeAnimal();
116
    //test to find out how many user fields there are...
117
    $fields       = $animal->getNumOfFields();
118
    $numofcolumns = 1;
119
    $columns[]    = array('columnname' => 'Name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
120 View Code Duplication
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
121
        $userField   = new Field($fields[$i], $animal->getConfig());
122
        $fieldType   = $userField->getSetting('FieldType');
123
        $fieldObject = new $fieldType($userField, $animal);
124
        //create empty string
125
        $lookupvalues = '';
126
        if ($userField->isActive() && $userField->inList()) {
127
            if ($userField->hasLookup()) {
128
                $lookupvalues = $userField->lookupField($fields[$i]);
129
                //debug information
130
                //print_r($lookupvalues);
131
            }
132
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
133
            ++$numofcolumns;
134
            unset($lookupvalues);
135
        }
136
    }
137
138 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
139
        //create picture information
140
        if ($row['foto'] != '') {
141
            $camera = " <img src=\"assets/images/dog-icon25.png\">";
142
        } else {
143
            $camera = '';
144
        }
145
        $name = stripslashes($row['d_naam']) . $camera;
146
        //empty array
147
        unset($columnvalue);
148
        //fill array
149
        for ($i = 1; $i < $numofcolumns; ++$i) {
150
            $x = $columns[$i]['columnnumber'];
151
            //echo $x."columnnumber";
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
152
            if (is_array($columns[$i]['lookupval'])) {
153
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
154
                    if ($keyvalue['id'] == $row['user' . $x]) {
155
                        //echo "key:".$row['user5']."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
156
                        $value = $keyvalue['value'];
157
                    }
158
                }
159
                //debug information
160
                ///echo $columns[$i]['columnname']."is an array !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
161
            } //format value - cant use object because of query count
162
            elseif (0 === strpos($row['user' . $x], 'http://')) {
163
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
164
            } else {
165
                $value = $row['user' . $x];
166
            }
167
            $columnvalue[] = array('value' => $value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columnvalue was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columnvalue = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $value 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...
168
            unset($value);
169
        }
170
        $dogs[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
171
            'id'          => $row['d_id'],
172
            'name'        => $name,
173
            'gender'      => '<img src="assets/images/male.gif">',
174
            'link'        => "<a href=\"virtual.php?f=dam&selsire=" . $row['d_id'] . "\">" . $name . '</a>',
175
            'colour'      => '',
176
            'number'      => '',
177
            'usercolumns' => isset($columnvalue) ? $columnvalue : 0
178
        );
179
    }
180
181
    //add data to smarty template
182
    //assign dog
183
    if (isset($dogs)) {
184
        $xoopsTpl->assign('dogs', $dogs);
185
    }
186
    $xoopsTpl->assign('columns', $columns);
187
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
188
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
189
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $moduleConfig['father'])));
190
    $xoopsTpl->assign('pages', $pages);
191
192
    $xoopsTpl->assign('virtualtitle', strtr(_MA_PEDIGREE_VIRUTALTIT, array('[mother]' => $moduleConfig['mother'])));
193
    $xoopsTpl->assign('virtualstory', strtr(_MA_PEDIGREE_VIRUTALSTO, array('[mother]' => $moduleConfig['mother'], '[father]' => $moduleConfig['father'], '[children]' => $moduleConfig['children'])));
194
    $xoopsTpl->assign('nextaction', '<b>' . strtr(_MA_PEDIGREE_VIRT_SIRE, array('[father]' => $moduleConfig['father'])) . '</b>');
195
}
196
197
function dam()
0 ignored issues
show
Best Practice introduced by
The function dam() has been defined more than once; this definition is ignored, only the first definition in add_dog.php (L426-611) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Coding Style introduced by
dam uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
dam uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
198
{
199
    global $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
200
    $pages = '';
201
202
    //get module configuration
203
    $moduleHandler = xoops_getHandler('module');
204
    $module        = $moduleHandler->getByDirname('pedigree');
205
    $configHandler = xoops_getHandler('config');
206
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
207
208
    if (isset($_GET['st'])) {
209
        $st = $_GET['st'];
210
    } else {
211
        $st = 0;
212
    }
213
    if (isset($_GET['l'])) {
214
        $l = $_GET['l'];
215
    } else {
216
        $l = 'A';
217
    }
218
    $selsire = $_GET['selsire'];
219
220
    $xoopsTpl->assign('sire', '1');
221
    //create list of males dog to select from
222
    $perp = $moduleConfig['perpage'];
223
    //count total number of dogs
224
    $numdog = 'SELECT count(d.id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') //  . " f ON f.id = d.father WHERE d.roft = '1' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%'";
225
              . " f ON f.id = d.father WHERE d.roft = '1' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $GLOBALS['xoopsDB']->escape($l) . "%'";
226
227
    $numres = $GLOBALS['xoopsDB']->query($numdog);
228
    //total number of dogs the query will find
229
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
230
    //total number of pages
231
    $numpages = floor($numresults / $perp) + 1;
232
    if (($numpages * $perp) == ($numresults + $perp)) {
233
        --$numpages;
234
    }
235
    //find current page
236
    $cpage = floor($st / $perp) + 1;
237
    //create the alphabet
238
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=a\">A</a>&nbsp;";
239
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=b\">B</a>&nbsp;";
240
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=c\">C</a>&nbsp;";
241
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=d\">D</a>&nbsp;";
242
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=e\">E</a>&nbsp;";
243
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=f\">F</a>&nbsp;";
244
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=g\">G</a>&nbsp;";
245
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=h\">H</a>&nbsp;";
246
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=i\">I</a>&nbsp;";
247
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=j\">J</a>&nbsp;";
248
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=k\">K</a>&nbsp;";
249
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=l\">L</a>&nbsp;";
250
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=m\">M</a>&nbsp;";
251
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=n\">N</a>&nbsp;";
252
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=o\">O</a>&nbsp;";
253
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=p\">P</a>&nbsp;";
254
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=q\">Q</a>&nbsp;";
255
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=r\">R</a>&nbsp;";
256
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=s\">S</a>&nbsp;";
257
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=t\">T</a>&nbsp;";
258
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=u\">U</a>&nbsp;";
259
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=v\">V</a>&nbsp;";
260
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=w\">W</a>&nbsp;";
261
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=x\">X</a>&nbsp;";
262
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=y\">Y</a>&nbsp;";
263
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=z\">Z</a>&nbsp;";
264
    $pages .= '-&nbsp;';
265
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=Ã…\">Ã…</a>&nbsp;";
266
    $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=Ö\">Ö</a>&nbsp;";
267
    //create linebreak
268
    $pages .= '<br />';
269
    //create previous button
270
    if ($numpages > 1) {
271
        if ($cpage > 1) {
272
            $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . '&l=' . $l . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
273
        }
274
    }
275
    //create numbers
276
    for ($x = 1; $x < ($numpages + 1); ++$x) {
277
        //create line break after 20 number
278
        if (($x % 20) == 0) {
279
            $pages .= '<br />';
280
        }
281
        if ($x != $cpage) {
282
            $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . '&l=' . $l . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
283
        } else {
284
            $pages .= $x . '&nbsp;&nbsp';
285
        }
286
    }
287
    //create next button
288
    if ($numpages > 1) {
289
        if ($cpage < $numpages) {
290
            $pages .= "<a href=\"virtual.php?f=dam&selsire=" . $selsire . '&l=' . $l . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
291
        }
292
    }
293
294
    //query
295
    $queryString = 'SELECT d.*, d.id AS d_id, d.naam AS d_naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " f ON f.id = d.father WHERE d.roft = '1' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%' ORDER BY d.naam LIMIT " . $st . ', ' . $perp;
296
    $result      = $GLOBALS['xoopsDB']->query($queryString);
297
298
    $animal = new PedigreeAnimal();
299
    //test to find out how many user fields there are...
300
    $fields       = $animal->getNumOfFields();
301
    $numofcolumns = 1;
302
    $columns[]    = array('columnname' => 'Name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
303 View Code Duplication
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
304
        $userField   = new Field($fields[$i], $animal->getConfig());
305
        $fieldType   = $userField->getSetting('FieldType');
306
        $fieldObject = new $fieldType($userField, $animal);
307
        //create empty string
308
        $lookupvalues = '';
309
        if ($userField->isActive() && $userField->inList()) {
310
            if ($userField->hasLookup()) {
311
                $lookupvalues = $userField->lookupField($fields[$i]);
312
                //debug information
313
                //print_r($lookupvalues);
314
            }
315
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
316
            ++$numofcolumns;
317
            unset($lookupvalues);
318
        }
319
    }
320
321 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
322
        //create picture information
323
        if ($row['foto'] != '') {
324
            $camera = " <img src=\"assets/images/dog-icon25.png\">";
325
        } else {
326
            $camera = '';
327
        }
328
        $name = stripslashes($row['d_naam']) . $camera;
329
        //empty array
330
        unset($columnvalue);
331
        //fill array
332
        for ($i = 1; $i < $numofcolumns; ++$i) {
333
            $x = $columns[$i]['columnnumber'];
334
            //echo $x."columnnumber";
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
335
            if (is_array($columns[$i]['lookupval'])) {
336
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
337
                    if ($keyvalue['id'] == $row['user' . $x]) {
338
                        //echo "key:".$row['user5']."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
339
                        $value = $keyvalue['value'];
340
                    }
341
                }
342
                //debug information
343
                ///echo $columns[$i]['columnname']."is an array !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
344
            } //format value - cant use object because of query count
345
            elseif (0 === strpos($row['user' . $x], 'http://')) {
346
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
347
            } else {
348
                $value = $row['user' . $x];
349
            }
350
            $columnvalue[] = array('value' => $value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columnvalue was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columnvalue = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $value 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...
351
            unset($value);
352
        }
353
        $dogs[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
354
            'id'          => $row['d_id'],
355
            'name'        => $name,
356
            'gender'      => '<img src="assets/images/female.gif">',
357
            'link'        => "<a href=\"virtual.php?f=check&selsire=" . $selsire . '&seldam=' . $row['d_id'] . "\">" . $name . '</a>',
358
            'colour'      => '',
359
            'number'      => '',
360
            'usercolumns' => isset($columnvalue) ? $columnvalue : 0
361
        );
362
    }
363
364
    //add data to smarty template
365
    //assign dog
366
    $xoopsTpl->assign('dogs', $dogs);
0 ignored issues
show
Bug introduced by
The variable $dogs 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...
367
    $xoopsTpl->assign('columns', $columns);
368
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
369
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
370
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELDAM, array('[mother]' => $moduleConfig['mother'])));
371
    $xoopsTpl->assign('pages', $pages);
372
373
    $xoopsTpl->assign('virtualtitle', _MA_PEDIGREE_VIRUTALTIT);
374
    $xoopsTpl->assign('virtualstory', strtr(_MA_PEDIGREE_VIRUTALSTO, array('[mother]' => $moduleConfig['mother'], '[father]' => $moduleConfig['father'], '[children]' => $moduleConfig['children'])));
375
    $xoopsTpl->assign('nextaction', '<b>' . strtr(_MA_PEDIGREE_VIRT_DAM, array('[mother]' => $moduleConfig['mother'])) . '</b>');
376
377
    //find father
378
    $query  = 'SELECT ID, NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ID=' . $selsire;
379
    $result = $GLOBALS['xoopsDB']->query($query);
380 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
381
        $vsire = stripslashes($row['NAAM']);
382
    }
383
    $xoopsTpl->assign('virtualsiretitle', strtr(_MA_PEDIGREE_VIRTUALSTIT, array('[father]' => $moduleConfig['father'])));
384
    $xoopsTpl->assign('virtualsire', $vsire);
0 ignored issues
show
Bug introduced by
The variable $vsire 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...
385
}
386
387
function check()
0 ignored issues
show
Coding Style introduced by
check uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Best Practice introduced by
The function check() has been defined more than once; this definition is ignored, only the first definition in add_breeder.php (L27-47) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Coding Style introduced by
check uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
388
{
389
    global $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
390
391
    //get module configuration
392
    $moduleHandler = xoops_getHandler('module');
393
    $module        = $moduleHandler->getByDirname('pedigree');
394
    $configHandler = xoops_getHandler('config');
395
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
396
397
    if (isset($_GET['selsire'])) {
398
        $selsire = $_GET['selsire'];
399
    }
400
    if (isset($_GET['seldam'])) {
401
        $seldam = $_GET['seldam'];
402
    }
403
404
    $xoopsTpl->assign('virtualtitle', _MA_PEDIGREE_VIRUTALTIT);
405
    $xoopsTpl->assign('virtualstory', strtr(_MA_PEDIGREE_VIRUTALSTO, array('[mother]' => $moduleConfig['mother'], '[father]' => $moduleConfig['father'], '[children]' => $moduleConfig['children'])));
406
    //find father
407
    $query  = 'SELECT ID, NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ID=' . $selsire;
0 ignored issues
show
Bug introduced by
The variable $selsire 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...
408
    $result = $GLOBALS['xoopsDB']->query($query);
409 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
410
        $vsire = stripslashes($row['NAAM']);
411
    }
412
    $xoopsTpl->assign('virtualsiretitle', strtr(_MA_PEDIGREE_VIRTUALSTIT, array('[father]' => $moduleConfig['father'])));
413
    $xoopsTpl->assign('virtualsire', $vsire);
0 ignored issues
show
Bug introduced by
The variable $vsire 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...
414
    //find mother
415
    $query  = 'SELECT ID, NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ID=' . $seldam;
0 ignored issues
show
Bug introduced by
The variable $seldam 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...
416
    $result = $GLOBALS['xoopsDB']->query($query);
417 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
418
        $vdam = stripslashes($row['NAAM']);
419
    }
420
    $xoopsTpl->assign('virtualdamtitle', strtr(_MA_PEDIGREE_VIRTUALDTIT, array('[mother]' => $moduleConfig['mother'])));
421
    $xoopsTpl->assign('virtualdam', $vdam);
0 ignored issues
show
Bug introduced by
The variable $vdam 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...
422
423
    $xoopsTpl->assign('form', "<a href=\"coi.php?s=" . $selsire . '&d=' . $seldam . "&dogid=&detail=1\">" . _MA_PEDIGREE_VIRTUALBUT . '</a>');
424
}
425
426
//footer
427
include $GLOBALS['xoops']->path('footer.php');
428