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

PedigreeUtilities::getCurrentPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
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 24 and the first side effect is on line 10.

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
 * Created by PhpStorm.
5
 * User: Mamba
6
 * Date: 2014-11-19
7
 * Time: 3:05
8
 */
9
10
$moduleDirName = basename(dirname(__DIR__));
11
require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/include/class_field.php');
12
require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/include/config.php');
13
xoops_load('PedigreeAnimal', $moduleDirName);
14
15
//get module configuration
16
$moduleHandler = xoops_getHandler('module');
17
$module        = $moduleHandler->getByDirname($moduleDirName);
18
$configHandler = xoops_getHandler('config');
19
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
20
21
/**
22
 * Class PedigreeUtilities
23
 */
24
class PedigreeUtilities
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...
25
{
26
27
    /**
28
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
29
     *
30
     * @param string $folder The full path of the directory to check
31
     *
32
     * @return void
33
     */
34
    public static function prepareFolder($folder)
35
    {
36
        //        $filteredFolder = XoopsFilterInput::clean($folder, 'PATH');
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
37
        if (!is_dir($folder)) {
38
            mkdir($folder);
39
            file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
40
        }
41
        //        chmod($filteredFolder, 0777);
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...
42
    }
43
44
    /**
45
     * @param $columncount
46
     *
47
     * @return string
48
     */
49
    public static function sortTable($columncount)
50
    {
51
        $ttemp = '';
52
        if ($columncount > 1) {
53
            for ($t = 1; $t < $columncount; ++$t) {
54
                $ttemp .= "'S',";
55
            }
56
            $tsarray = "initSortTable('Result', Array({$ttemp}'S'));";
57
        } else {
58
            $tsarray = "initSortTable('Result',Array('S'));";
59
        }
60
61
        return $tsarray;
62
    }
63
64
    /**
65
     * @param $num
66
     *
67
     * @return string
68
     */
69
    public static function uploadPicture($num)
0 ignored issues
show
Coding Style introduced by
uploadPicture 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...
Coding Style introduced by
uploadPicture uses the super-global variable $_POST 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...
70
    {
71
        $max_imgsize       = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000;
72
        $max_imgwidth      = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500;
73
        $max_imgheight     = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000;
74
        $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
75
        //    $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% 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...
76
        $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images';
77
        include_once $GLOBALS['xoops']->path('class/uploader.php');
78
        $field = $_POST['xoops_upload_file'][$num];
79
        if (!empty($field) || $field != '') {
80
            $uploader = new XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight);
81
            $uploader->setPrefix('img');
82
            if ($uploader->fetchMedia($field) && $uploader->upload()) {
83
                $photo = $uploader->getSavedFileName();
84
            } else {
85
                echo $uploader->getErrors();
86
            }
87
            createThumbs($photo);
0 ignored issues
show
Bug introduced by
The variable $photo 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...
88
89
            return $photo;
90
        }
91
    }
92
93
    /**
94
     * @param $filename
95
     *
96
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
97
     */
98
    public static function createThumbs($filename)
0 ignored issues
show
Coding Style introduced by
createThumbs 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...
99
    {/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
100
    require_once('phpthumb/phpthumb.class.php');
101
    $thumbnail_widths = array(150, 400);
102
    foreach ($thumbnail_widths as $thumbnail_width) {
103
        $phpThumb = new phpThumb();
104
        // set data
105
        $phpThumb->setSourceFilename('images/' . $filename);
106
        $phpThumb->w                    = $thumbnail_width;
107
        $phpThumb->config_output_format = 'jpeg';
108
        // generate & output thumbnail
109
        $output_filename = 'images/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
110
        if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
111
            if ($output_filename) {
112
                if ($phpThumb->RenderToFile($output_filename)) {
113
                    // do something on success
114
                    //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
115
                } else {
116
                    echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
117
                }
118
            }
119
        } else {
120
            echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
121
        }
122
        unset($phpThumb);
123
    }
124
125
    return true;
126
127
    */
128
129
        // load the image
130
        require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php');
131
        $thumbnail_widths = array(150, 400);
132
133
        // indicate a target image
134
        // note that there's no extra property to set in order to specify the target
135
        // image's type -simply by writing '.jpg' as extension will instruct the script
136
        // to create a 'jpg' file
137
        $config_output_format = 'jpeg';
138
139
        // create a new instance of the class
140
        $image = new Zebra_Image();
141
        // indicate a source image (a GIF, PNG or JPEG file)
142
        $image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}";
143
144
        foreach ($thumbnail_widths as $thumbnail_width) {
145
146
            // generate & output thumbnail
147
            $output_filename    = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . basename($filename) . "_{$thumbnail_width}.{$config_output_format}";
148
            $image->target_path = $output_filename;
149
            // since in this example we're going to have a jpeg file, let's set the output
150
            // image's quality
151
            $image->jpeg_quality = 100;
152
            // some additional properties that can be set
153
            // read about them in the documentation
154
            $image->preserve_aspect_ratio  = true;
155
            $image->enlarge_smaller_images = true;
156
            $image->preserve_time          = true;
157
158
            // resize the image to exactly 100x100 pixels by using the "crop from center" method
159
            // (read more in the overview section or in the documentation)
160
            //  and if there is an error, check what the error is about
161
            if (!$image->resize($thumbnail_width, 0)) {
162
                // if there was an error, let's see what the error is about
163
                switch ($image->error) {
164
165
                    case 1:
166
                        echo 'Source file could not be found!';
167
                        break;
168
                    case 2:
169
                        echo 'Source file is not readable!';
170
                        break;
171
                    case 3:
172
                        echo 'Could not write target file!';
173
                        break;
174
                    case 4:
175
                        echo 'Unsupported source file format!';
176
                        break;
177
                    case 5:
178
                        echo 'Unsupported target file format!';
179
                        break;
180
                    case 6:
181
                        echo 'GD library version does not support target file format!';
182
                        break;
183
                    case 7:
184
                        echo 'GD library is not installed!';
185
                        break;
186
                    case 8:
187
                        echo '"chmod" command is disabled via configuration!';
188
                        break;
189
                }
190
191
                // if no errors
192
            } else {
193
                echo 'Success!';
194
            }
195
196
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
197
                    if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
198
                        if ($output_filename) {
199
                            if ($phpThumb->RenderToFile($output_filename)) {
200
                                // do something on success
201
                                //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
202
                            } else {
203
                                echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
204
                            }
205
                        }
206
                    } else {
207
                        echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
208
                    }
209
     */
210
        }
211
212
        unset($image);
213
    }
214
215
    /**
216
     * @param $string
217
     *
218
     * @return string
219
     */
220
    public static function unHtmlEntities($string)
221
    {
222
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
223
        $trans_tbl = array_flip($trans_tbl);
224
225
        return strtr($string, $trans_tbl);
226
    }
227
228
    /**
229
     * @param $oid
230
     * @param $gender
231
     *
232
     * @return null
233
     */
234
    public static function pups($oid, $gender)
0 ignored issues
show
Coding Style introduced by
pups 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...
235
    {
236
        global $numofcolumns, $nummatch, $pages, $columns, $dogs;
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...
237
        $content = '';
0 ignored issues
show
Unused Code introduced by
$content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
238
        if ($gender == 0) {
239
            $sqlquery = 'SELECT d.id as d_id, d.naam as d_naam, d.roft as d_roft, d.* FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.id LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.id where d.father=' . $oid . ' order by d.naam';
240 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...
241
            $sqlquery = 'SELECT d.id as d_id, d.naam as d_naam, d.roft as d_roft, d.* FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.id LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.id where d.mother=' . $oid . ' order by d.naam';
242
        }
243
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
244
        $nummatch    = $GLOBALS['xoopsDB']->getRowsNum($queryresult);
245
246
        $animal = new PedigreeAnimal();
247
        //test to find out how many user fields there are...
248
        $fields       = $animal->getNumOfFields();
249
        $numofcolumns = 1;
250
        $columns[]    = array('columnname' => 'Name');
251 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...
252
            $userField   = new Field($fields[$i], $animal->getConfig());
253
            $fieldType   = $userField->getSetting('FieldType');
254
            $fieldObject = new $fieldType($userField, $animal);
255
            //create empty string
256
            $lookupvalues = '';
257
            if ($userField->isActive() && $userField->inList()) {
258
                if ($userField->hasLookup()) {
259
                    $lookupvalues = $userField->lookupField($fields[$i]);
260
                    //debug information
261
                    //print_r($lookupvalues);
262
                }
263
                $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
264
                ++$numofcolumns;
265
                unset($lookupvalues);
266
            }
267
        }
268
269 View Code Duplication
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
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...
270
            if ($rowres['d_roft'] == '0') {
271
                $gender = "<img src=\"assets/images/male.gif\">";
272
            } else {
273
                $gender = "<img src=\"assets/images/female.gif\">";
274
            }
275
            $name = stripslashes($rowres['d_naam']);
276
            //empty array
277
            unset($columnvalue);
278
            //fill array
279
            for ($i = 1; $i < $numofcolumns; ++$i) {
280
                $x = $columns[$i]['columnnumber'];
281
                if (is_array($columns[$i]['lookupval'])) {
282
                    foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
283
                        if ($keyvalue['id'] == $rowres['user' . $x]) {
284
                            $value = $keyvalue['value'];
285
                        }
286
                    }
287
                    //debug information
288
                    ///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...
289
                } //format value - cant use object because of query count
290
                elseif (0 === strpos($rowres['user' . $x], 'http://')) {
291
                    $value = "<a href=\"" . $rowres['user' . $x] . "\">" . $rowres['user' . $x] . '</a>';
292
                } else {
293
                    $value = $rowres['user' . $x];
294
                }
295
                $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...
296
            }
297
            $dogs[] = array(
298
                'id'          => $rowres['d_id'],
299
                'name'        => $name,
300
                'gender'      => $gender,
301
                'link'        => "<a href=\"dog.php?id=" . $rowres['d_id'] . "\">" . $name . '</a>',
302
                'colour'      => '',
303
                'number'      => '',
304
                'usercolumns' => $columnvalue
0 ignored issues
show
Bug introduced by
The variable $columnvalue 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...
305
            );
306
        }
307
308
        return null;
309
    }
310
311
    /**
312
     * @param $oid
313
     * @param $pa
314
     * @param $ma
315
     *
316
     * @return null
317
     */
318
    public static function bas($oid, $pa, $ma)
0 ignored issues
show
Coding Style introduced by
bas 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...
319
    {
320
        global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1;
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...
321
        if ($pa == '0' && $ma == '0') {
322
            $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where father = ' . $pa . ' and mother = ' . $ma . ' and ID != ' . $oid . " and father != '0' and mother !='0' order by NAAM";
323
        } else {
324
            $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where father = ' . $pa . ' and mother = ' . $ma . ' and ID != ' . $oid . ' order by NAAM';
325
        }
326
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
327
        $nummatch1   = $GLOBALS['xoopsDB']->getRowsNum($queryresult);
328
329
        $animal = new PedigreeAnimal();
330
        //test to find out how many user fields there are...
331
        $fields        = $animal->getNumOfFields();
332
        $numofcolumns1 = 1;
333
        $columns1[]    = array('columnname' => 'Name');
334 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...
335
            $userField   = new Field($fields[$i], $animal->getConfig());
336
            $fieldType   = $userField->getSetting('FieldType');
337
            $fieldObject = new $fieldType($userField, $animal);
338
            //create empty string
339
            $lookupvalues = '';
340
            if ($userField->isActive() && $userField->inList()) {
341
                if ($userField->hasLookup()) {
342
                    $lookupvalues = $userField->lookupField($fields[$i]);
343
                    //debug information
344
                    //print_r($lookupvalues);
345
                }
346
                $columns1[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
347
                ++$numofcolumns1;
348
                unset($lookupvalues);
349
            }
350
        }
351
352 View Code Duplication
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
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...
353
            if (0 == $rowres['roft']) {
354
                $gender = "<img src='assets/images/male.gif'>";
355
            } else {
356
                $gender = "<img src='assets/images/female.gif'>";
357
            }
358
            $name = stripslashes($rowres['NAAM']);
359
            //empty array
360
            //        unset($columnvalue1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
361
            $columnvalue1 = array();
362
            //fill array
363
            for ($i = 1; $i < $numofcolumns1; ++$i) {
364
                $x = $columns1[$i]['columnnumber'];
365
                if (is_array($columns1[$i]['lookupval'])) {
366
                    foreach ($columns1[$i]['lookupval'] as $key => $keyvalue) {
367
                        if ($keyvalue['id'] == $rowres['user' . $x]) {
368
                            $value = $keyvalue['value'];
369
                        }
370
                    }
371
                    //debug information
372
                    ///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...
373
                } //format value - cant use object because of query count
374
                elseif (0 === strpos($rowres['user' . $x], 'http://')) {
375
                    $value = "<a href=\"" . $rowres['user' . $x] . "\">" . $rowres['user' . $x] . '</a>';
376
                } else {
377
                    $value = $rowres['user' . $x];
378
                }
379
                $columnvalue1[] = array('value' => $value);
0 ignored issues
show
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...
380
            }
381
            $dogs1[] = array(
382
                'id'          => $rowres['Id'],
383
                'name'        => $name,
384
                'gender'      => $gender,
385
                'link'        => "<a href=\"dog.php?id=" . $rowres['Id'] . "\">" . $name . '</a>',
386
                'colour'      => '',
387
                'number'      => '',
388
                'usercolumns' => $columnvalue1
389
            );
390
        }
391
392
        return null;
393
    }
394
395
    /**
396
     * @param $oid
397
     * @param $breeder
398
     *
399
     * @return string
400
     */
401
    public static function breederof($oid, $breeder)
0 ignored issues
show
Coding Style introduced by
breederof 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...
402
    {
403
        $content = '';
404
405 View Code Duplication
        if (0 == $breeder) {
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...
406
            $sqlquery = 'SELECT ID, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_owner = '" . $oid . "' order by NAAM";
407
        } else {
408
            $sqlquery = 'SELECT ID, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_breeder = '" . $oid . "' order by NAAM";
409
        }
410
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
411
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
412
            if ($rowres['roft'] == '0') {
413
                $gender = "<img src=\"assets/images/male.gif\">";
414
            } else {
415
                $gender = "<img src=\"assets/images/female.gif\">";
416
            }
417
            $link = "<a href=\"dog.php?id=" . $rowres['Id'] . "\">" . stripslashes($rowres['NAAM']) . '</a>';
418
            $content .= $gender . ' ' . $link . '<br />';
419
        }
420
421
        return $content;
422
    }
423
424
    /**
425
     * @param $oid
426
     *
427
     * @return string
428
     */
429 View Code Duplication
    public static function getName($oid)
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...
Coding Style introduced by
getName 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...
430
    {
431
        $oid         = (int)$oid;
432
        $sqlquery    = 'SELECT NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE ID = '{$oid}'";
433
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
434
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
435
            $an = stripslashes($rowres['NAAM']);
436
        }
437
438
        return $an;
0 ignored issues
show
Bug introduced by
The variable $an 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...
439
    }
440
441
    /**
442
     * @param $PA
443
     */
444
    public static function showParent($PA)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Coding Style introduced by
showParent 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...
445
    {
446
        $sqlquery    = 'SELECT NAAM from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID='" . $PA . "'";
447
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
448
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
449
            $result = $rowres['NAAM'];
450
        }
451
        if (isset($result)) {
452
            return $result;
453
        } else {
454
            return;
455
        }
456
    }
457
458
    /**
459
     * @param $naam_hond
460
     *
461
     * @return mixed
462
     */
463 View Code Duplication
    public static function findId($naam_hond)
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...
Coding Style introduced by
findId 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...
464
    {
465
        $sqlquery    = 'SELECT ID from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where NAAM= '$naam_hond'";
466
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
467
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
468
            $result = $rowres['Id'];
469
        }
470
471
        return $result;
0 ignored issues
show
Bug introduced by
The variable $result 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...
472
    }
473
474
    /**
475
     * @param $result
476
     * @param $prefix
477
     * @param $link
478
     * @param $element
479
     */
480
    public static function createList($result, $prefix, $link, $element)
0 ignored issues
show
Coding Style introduced by
createList 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...
481
    {
482
        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...
483
        $animal = new PedigreeAnimal();
484
        //test to find out how many user fields there are...
485
        $fields       = $animal->getNumOfFields();
486
        $numofcolumns = 1;
487
        $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...
488 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...
489
            $userField   = new Field($fields[$i], $animal->getConfig());
490
            $fieldType   = $userField->getSetting('FieldType');
491
            $fieldObject = new $fieldType($userField, $animal);
492
            if ($userField->isActive() && $userField->inList()) {
493
                if ($userField->hasLookup()) {
494
                    $id = $userField->getId();
495
                    $q  = $userField->lookupField($id);
496
                } else {
497
                    $q = '';
498
                }
499
                $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookuparray' => $q);
500
                ++$numofcolumns;
501
            }
502
        }
503
504
        //add preliminary row to array if passed
505
        if (is_array($prefix)) {
506
            $dogs[] = $prefix;
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...
507
        }
508
509
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
510
            //reset $gender
511
            $gender = '';
512
            if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof XoopsUser) && ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true == $modadmin)) {
0 ignored issues
show
Bug introduced by
The variable $modadmin does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
513
                $gender = "<a href='dog.php?id={$row['Id']}'><img src='images/edit.gif' alt='" . _EDIT . "'></a>
514
                     . <a href='delete.php?id={$row['Id']}'><img src='images/delete.gif' alt='" . _DELETE . "'></a>";
515
            }
516
517
            $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif';
518
            $gender .= "<img src='assets/images/{$genImg}'>";
519
520
            if ('' != $row['foto']) {
521
                $camera = " <img src=\"assets/images/dog-icon25.png\">";
522
            } else {
523
                $camera = '';
524
            }
525
            $name = stripslashes($row['NAAM']) . $camera;
526
            unset($columnvalue);
527
528
            //fill array
529
            for ($i = 1; $i < $numofcolumns; ++$i) {
530
                $x           = $columns[$i]['columnnumber'];
531
                $lookuparray = $columns[$i]['lookuparray'];
532
                if (is_array($lookuparray)) {
533
                    for ($index = 0, $indexMax = count($lookuparray); $index < $indexMax; ++$index) {
534
                        if ($lookuparray[$index]['id'] == $row['user' . $x]) {
535
                            //echo "<h1>".$lookuparray[$index]['id']."</h1>";
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...
536
                            $value = $lookuparray[$index]['value'];
537
                        }
538
                    }
539
                } //format value - cant use object because of query count
540
                elseif (0 === strpos($row['user' . $x], 'http://')) {
541
                    $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
542
                } else {
543
                    $value = $row['user' . $x];
544
                }
545
                $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...
546
                unset($value);
547
            }
548
549
            $linkto = "<a href=\"" . $link . $row[$element] . "\">" . $name . '</a>';
550
            //create array
551
            $dogs[] = array('id' => $row['Id'], 'name' => $name, 'gender' => $gender, 'link' => $linkto, 'colour' => '', 'number' => '', 'usercolumns' => $columnvalue);
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...
Bug introduced by
The variable $columnvalue 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...
552
        }
553
554
        //add data to smarty template
555
        //assign dog
556
        $xoopsTpl->assign('dogs', $dogs);
557
        $xoopsTpl->assign('columns', $columns);
558
        $xoopsTpl->assign('numofcolumns', $numofcolumns);
559
        $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
560
    }
561
562
    /***************Blocks**************
563
     *
564
     * @param $cats
565
     *
566
     * @return string
567
     */
568
    public static function animal_block_addCatSelect($cats)
569
    {
570
        if (is_array($cats)) {
571
            $cat_sql = '(' . current($cats);
572
            array_shift($cats);
573
            foreach ($cats as $cat) {
574
                $cat_sql .= ',' . $cat;
575
            }
576
            $cat_sql .= ')';
577
        }
578
579
        return $cat_sql;
0 ignored issues
show
Bug introduced by
The variable $cat_sql 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...
580
    }
581
582
    /**
583
     * @deprecated
584
     * @param        $global
585
     * @param        $key
586
     * @param string $default
587
     * @param string $type
588
     *
589
     * @return mixed|string
590
     */
591
    public static function animal_CleanVars(&$global, $key, $default = '', $type = 'int')
592
    {
593
        switch ($type) {
594
            case 'string':
595
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
596
                break;
597
            case 'int':
598
            default:
599
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
600
                break;
601
        }
602
        if ($ret === false) {
603
            return $default;
604
        }
605
606
        return $ret;
607
    }
608
609
    /**
610
     * @param $content
611
     */
612 View Code Duplication
    public static function animal_meta_keywords($content)
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...
613
    {
614
        global $xoopsTpl, $xoTheme;
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...
615
        $myts    = MyTextSanitizer::getInstance();
616
        $content = $myts->undoHtmlSpecialChars($myts->sanitizeForDisplay($content));
617
        if (isset($xoTheme) && is_object($xoTheme)) {
618
            $xoTheme->addMeta('meta', 'keywords', strip_tags($content));
619
        } else {    // Compatibility for old Xoops versions
620
            $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content));
621
        }
622
    }
623
624
    /**
625
     * @param $content
626
     */
627 View Code Duplication
    public static function animal_meta_description($content)
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...
628
    {
629
        global $xoopsTpl, $xoTheme;
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...
630
        $myts    = MyTextSanitizer::getInstance();
631
        $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
632
        if (isset($xoTheme) && is_object($xoTheme)) {
633
            $xoTheme->addMeta('meta', 'description', strip_tags($content));
634
        } else {    // Compatibility for old Xoops versions
635
            $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
636
        }
637
    }
638
639
    /**
640
     * Verify that a mysql table exists
641
     *
642
     * @package       pedigree
643
     * @author        Hervé Thouzard (http://www.herve-thouzard.com)
644
     * @copyright (c) Hervé Thouzard
645
     */
646
    //function tableExists($tablename)
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...
647
    //{
648
    //
649
    //  $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
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...
650
    //  return($GLOBALS['xoopsDB']->getRowsNum($result) > 0);
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...
651
    //}
652
653
    /**
654
     * Create download by letter choice bar/menu
655
     * updated starting from this idea http://xoops.org/modules/news/article.php?storyid=6497
656
     *
657
     * @param $myObject
658
     * @param $activeObject
659
     * @param $criteria
660
     * @param $name
661
     * @param $file
662
     * @param $file2
663
     * @return string html
664
     *
665
     * @access  public
666
     * @author  luciorota
667
     */
668
    public static function lettersChoice($myObject, $activeObject, $criteria, $name, $file, $file2)
0 ignored issues
show
Unused Code introduced by
The parameter $criteria is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
lettersChoice 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...
669
    {
670
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
671
        $pedigree = PedigreePedigree::getInstance();
672
        xoops_load('XoopsLocal');
673
674
        $criteria = $pedigree->getHandler('tree')->getActiveCriteria();
675
        $criteria->setGroupby('UPPER(LEFT(NAAM,1))');
676
        $countsByLetters = $pedigree->getHandler('tree')->getCounts($criteria);
677
        // Fill alphabet array
678
        $alphabet       = XoopsLocal::getAlphabet();
679
        $alphabet_array = array();
680
        foreach ($alphabet as $letter) {
681
            $letter_array = array();
682
            if (isset($countsByLetters[$letter])) {
683
                $letter_array['letter'] = $letter;
684
                $letter_array['count']  = $countsByLetters[$letter];
685
                //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $pedigree->getModule()->dirname() . "/viewcat.php?list={$letter}";
686
                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $pedigree->getModule()->dirname() . "/result.php?f=NAAM&amp;l=1&amp;w={$letter}%25&amp;o=NAAM";
687
            } else {
688
                $letter_array['letter'] = $letter;
689
                $letter_array['count']  = 0;
690
                $letter_array['url']    = '';
691
            }
692
            $alphabet_array[$letter] = $letter_array;
693
            unset($letter_array);
694
        }
695
        // Render output
696
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
697
            include_once $GLOBALS['xoops']->path('class/theme.php');
698
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
699
        }
700
        require_once $GLOBALS['xoops']->path('class/template.php');
701
        $letterschoiceTpl          = new XoopsTpl();
702
        $letterschoiceTpl->caching = false; // Disable cache
703
        $letterschoiceTpl->assign('alphabet', $alphabet_array);
704
        $html = $letterschoiceTpl->fetch('db:' . $pedigree->getModule()->dirname() . '_common_letterschoice.tpl');
705
        unset($letterschoiceTpl);
706
        return $html;
707
*/
708
709
        //        $pedigree = PedigreePedigree::getInstance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
710
        xoops_load('XoopsLocal');
711
712
        $criteria = $myObject->getHandler($activeObject)->getActiveCriteria();
713
        $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))');
714
        $countsByLetters = $myObject->getHandler($activeObject)->getCounts($criteria);
715
        // Fill alphabet array
716
        $alphabet       = XoopsLocal::getAlphabet();
717
        $alphabet_array = array();
718
        foreach ($alphabet as $letter) {
719
            $letter_array = array();
720
            if (isset($countsByLetters[$letter])) {
721
                $letter_array['letter'] = $letter;
722
                $letter_array['count']  = $countsByLetters[$letter];
723
                //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $pedigree->getModule()->dirname() . "/viewcat.php?list={$letter}";
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
724
                //                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&amp;l=1&amp;w={$letter}%25&amp;o=".$name;
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
725
                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $file2;
726
            } else {
727
                $letter_array['letter'] = $letter;
728
                $letter_array['count']  = 0;
729
                $letter_array['url']    = '';
730
            }
731
            $alphabet_array[$letter] = $letter_array;
732
            unset($letter_array);
733
        }
734
        // Render output
735 View Code Duplication
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
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...
736
            include_once $GLOBALS['xoops']->path('class/theme.php');
737
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
738
        }
739
        require_once $GLOBALS['xoops']->path('class/template.php');
740
        $letterschoiceTpl          = new XoopsTpl();
741
        $letterschoiceTpl->caching = false; // Disable cache
742
        $letterschoiceTpl->assign('alphabet', $alphabet_array);
743
        $html = $letterschoiceTpl->fetch('db:' . $myObject->getModule()->dirname() . '_common_letterschoice.tpl');
744
        unset($letterschoiceTpl);
745
        return $html;
746
    }
747
748
    /**
749
     * @return bool
750
     */
751
    public static function userIsAdmin()
0 ignored issues
show
Coding Style introduced by
userIsAdmin 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...
752
    {
753
        $pedigree = PedigreePedigree::getInstance();
754
755
        static $pedigree_isAdmin;
756
757
        if (isset($pedigree_isAdmin)) {
758
            return $pedigree_isAdmin;
759
        }
760
761
        if (!$GLOBALS['xoopsUser']) {
762
            $pedigree_isAdmin = false;
763
        } else {
764
            $pedigree_isAdmin = $GLOBALS['xoopsUser']->isAdmin($pedigree->getModule()->getVar('mid'));
765
        }
766
767
        return $pedigree_isAdmin;
768
    }
769
770
    public static function getXoopsCpHeader()
771
    {
772
        xoops_cp_header();
773
    }
774
775
    /**
776
     * @param bool $withLink
777
     *
778
     * @return string
779
     */
780
    public static function getModuleName($withLink = true)
781
    {
782
        $pedigree = PedigreePedigree::getInstance();
783
784
        $pedigreeModuleName = $pedigree->getModule()->getVar('name');
785
        if (!$withLink) {
786
            return $pedigreeModuleName;
787
        } else {
788
            return '<a href="' . PEDIGREE_URL . '/">{$pedigreeModuleName}</a>';
789
        }
790
    }
791
792
    /**
793
     * Detemines if a table exists in the current db
794
     *
795
     * @param string $table the table name (without XOOPS prefix)
796
     *
797
     * @return bool True if table exists, false if not
798
     *
799
     * @access public
800
     * @author xhelp development team
801
     */
802
    public static function hasTable($table)
0 ignored issues
show
Coding Style introduced by
hasTable 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...
803
    {
804
        $bRetVal = false;
805
        //Verifies that a MySQL table exists
806
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
807
        $realName           = $GLOBALS['xoopsDB']->prefix($table);
808
809
        $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
810
        $ret = $GLOBALS['xoopsDB']->queryF($sql);
811
812
        while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) {
813
            if ($m_table == $realName) {
814
                $bRetVal = true;
815
                break;
816
            }
817
        }
818
        $GLOBALS['xoopsDB']->freeRecordSet($ret);
819
820
        return $bRetVal;
821
    }
822
823
    /**
824
     * Gets a value from a key in the xhelp_meta table
825
     *
826
     * @param string $key
827
     *
828
     * @return string $value
829
     *
830
     * @access public
831
     * @author xhelp development team
832
     */
833
    public static function getMeta($key)
0 ignored issues
show
Coding Style introduced by
getMeta 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...
834
    {
835
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
836
        $sql                = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key));
837
        $ret                = $GLOBALS['xoopsDB']->query($sql);
838
        if (!$ret) {
839
            $value = false;
840
        } else {
841
            list($value) = $GLOBALS['xoopsDB']->fetchRow($ret);
842
        }
843
844
        return $value;
845
    }
846
847
    /**
848
     * Sets a value for a key in the xhelp_meta table
849
     *
850
     * @param string $key
851
     * @param string $value
852
     *
853
     * @return bool true if success, false if failure
854
     *
855
     * @access public
856
     * @author xhelp development team
857
     */
858
    public static function setMeta($key, $value)
0 ignored issues
show
Coding Style introduced by
setMeta 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...
859
    {
860
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
861
        if (false !== ($ret = PedigreeUtilities::getMeta($key))) {
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
862
            $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key));
863
        } else {
864
            $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value));
865
        }
866
        $ret = $GLOBALS['xoopsDB']->queryF($sql);
867
        if (!$ret) {
868
            return false;
869
        }
870
871
        return true;
872
    }
873
874
    /**
875
     * @param     $name
876
     * @param     $value
877
     * @param int $time
878
     */
879
    public static function setCookieVar($name, $value, $time = 0)
880
    {
881
        if ($time == 0) {
882
            $time = time() + 3600 * 24 * 365;
883
            //$time = '';
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...
884
        }
885
        setcookie($name, $value, $time, '/');
886
    }
887
888
    /**
889
     * @param        $name
890
     * @param string $default
891
     *
892
     * @return string
893
     */
894
    public static function getCookieVar($name, $default = '')
0 ignored issues
show
Coding Style introduced by
getCookieVar uses the super-global variable $_COOKIE 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...
895
    {
896
        if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
897
            return $_COOKIE[$name];
898
        } else {
899
            return $default;
900
        }
901
    }
902
903
    /**
904
     * @return array
905
     */
906
    public static function getCurrentUrls()
0 ignored issues
show
Coding Style introduced by
getCurrentUrls uses the super-global variable $_SERVER 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...
907
    {
908
        $http        = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://';
909
        $phpSelf     = $_SERVER['PHP_SELF'];
910
        $httpHost    = $_SERVER['HTTP_HOST'];
911
        $queryString = $_SERVER['QUERY_STRING'];
912
913
        if ($queryString != '') {
914
            $queryString = '?' . $queryString;
915
        }
916
917
        $currentURL = $http . $httpHost . $phpSelf . $queryString;
918
919
        $urls                = array();
920
        $urls['http']        = $http;
921
        $urls['httphost']    = $httpHost;
922
        $urls['phpself']     = $phpSelf;
923
        $urls['querystring'] = $queryString;
924
        $urls['full']        = $currentURL;
925
926
        return $urls;
927
    }
928
929
    /**
930
     * @return mixed
931
     */
932
    public static function getCurrentPage()
933
    {
934
        $urls = PedigreeUtilities::getCurrentUrls();
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
935
936
        return $urls['full'];
937
    }
938
939
    /**
940
     * @param array $errors
941
     *
942
     * @return string
943
     */
944
    public static function formatErrors($errors = array())
945
    {
946
        $ret = '';
947
        foreach ($errors as $key => $value) {
948
            $ret .= "<br /> - {$value}";
949
        }
950
951
        return $ret;
952
    }
953
954
}
955