Completed
Pull Request — master (#5)
by Michael
01:37
created

SwDatabase::handlePosts()   F

Complexity

Conditions 12
Paths 896

Size

Total Lines 108

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 896
nop 0
dl 0
loc 108
rs 2.3555
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace XoopsModules\Smallworld;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * SmallWorld
17
 *
18
 * @copyright    The XOOPS Project (https://xoops.org)
19
 * @copyright    2011 Culex
20
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
21
 * @package      SmallWorld
22
 * @since        1.0
23
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
24
 */
25
class SwDatabase
26
{
27
    /**
28
     * getJobsToDiv function
29
     * @param int $id
30
     * @return array
31
     */
32
    public function getJobsToDiv($id)
33
    {
34
        global $xoopsUser, $xoopsDB;
35
        $msg    = [];
36
        $new    = [];
0 ignored issues
show
Unused Code introduced by
$new 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...
37
        $sql    = 'SELECT employer,position,jobstart,jobstop,description  FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'";
38
        $result = $xoopsDB->query($sql);
39
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
40
            $employer    = unserialize($row['employer']);
41
            $position    = unserialize($row['position']);
42
            $jobstart    = unserialize($row['jobstart']);
43
            $jobstop     = unserialize($row['jobstop']);
44
            $description = unserialize($row['description']);
45
        }
46
        $start = 0;
47
        $end   = count($employer) - 1;
0 ignored issues
show
Bug introduced by
The variable $employer 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...
48
        while ($start <= $end) {
49
            $msg[$start]['employer']    = $employer[$start];
50
            $msg[$start]['position']    = $position[$start];
0 ignored issues
show
Bug introduced by
The variable $position 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...
51
            $msg[$start]['jobstart']    = $jobstart[$start];
0 ignored issues
show
Bug introduced by
The variable $jobstart 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...
52
            $msg[$start]['jobstop']     = $jobstop[$start];
0 ignored issues
show
Bug introduced by
The variable $jobstop 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...
53
            $msg[$start]['description'] = $description[$start];
0 ignored issues
show
Bug introduced by
The variable $description 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...
54
            ++$start;
55
        }
56
57
        return $msg;
58
    }
59
60
    /**
61
     * getSchoolToDiv function
62
     * @param int $id
63
     * @return array
64
     */
65
    public function getSchoolToDiv($id)
66
    {
67
        global $xoopsUser, $xoopsDB, $arr7;
68
        $msg    = [];
69
        $sql    = 'SELECT school_type,school,schoolstart,schoolstop FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'";
70
        $result = $xoopsDB->query($sql);
71
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
72
            $school_type = unserialize($row['school_type']);
73
            $school      = unserialize($row['school']);
74
            $schoolstart = unserialize($row['schoolstart']);
75
            $schoolstop  = unserialize($row['schoolstop']);
76
        }
77
        $start = 0;
78
        $end   = count($school_type) - 1;
0 ignored issues
show
Bug introduced by
The variable $school_type 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...
79
        while ($start <= $end) {
80
            $msg[$start]['school_type'] = $school_type[$start];
81
            $msg[$start]['school']      = $arr7[$school[$start]];
0 ignored issues
show
Bug introduced by
The variable $school 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...
82
            $msg[$start]['schoolstart'] = $schoolstart[$start];
0 ignored issues
show
Bug introduced by
The variable $schoolstart 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...
83
            $msg[$start]['schoolstop']  = $schoolstop[$start];
0 ignored issues
show
Bug introduced by
The variable $schoolstop 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...
84
            $start++;
85
        }
86
87
        return $msg;
88
    }
89
90
    /**
91
     * getScreennamesToDiv function
92
     * @param int $id
93
     * @return array
94
     */
95
    public function getScreennamesToDiv($id)
96
    {
97
        global $xoopsUser, $xoopsDB, $arr06;
98
        $msg    = [];
99
        $sql    = 'SELECT screenname_type,screenname FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'";
100
        $result = $xoopsDB->query($sql);
101
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
102
            $screenname_type = unserialize($row['screenname_type']);
103
            $screenname      = unserialize($row['screenname']);
104
        }
105
        $start = 0;
106
        $end   = count($screenname_type) - 1;
0 ignored issues
show
Bug introduced by
The variable $screenname_type 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...
107
        while ($start <= $end) {
108
            $msg[$start]['screenname']      = $screenname_type[$start];
109
            $msg[$start]['screenname_type'] = $arr06[$screenname[$start]];
0 ignored issues
show
Bug introduced by
The variable $screenname 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...
110
            $msg[$start]['link']            = "<span class='smallworld_website'>" . Smallworld_sociallinks($screenname[$start], $msg[$start]['screenname']);
111
            ++$start;
112
        }
113
114
        return $msg;
115
    }
116
117
    /**
118
     * getVar function
119
     * @param int    $id
120
     * @param string $var
121
     * @return array|int
122
     */
123
    public function getVar($id, $var)
124
    {
125
        global $xoopsUser, $xoopsDB;
126
        $sql    = 'SELECT ' . $var . ' FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $id . "'";
127
        $result = $xoopsDB->queryF($sql);
128
        if ($xoopsDB->getRowsNum($result) < 1) {
129
            return 0; //_SMALLWORLD_REPLY_NOTSPECIFIED;
130
        }
131
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
132
            $msg[$var] = $row[$var];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$msg was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msg = 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...
133
        }
134
135
        return $msg[$var];
0 ignored issues
show
Bug introduced by
The variable $msg 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...
136
    }
137
138
    /**
139
     * updateSingleValue function
140
     * @param string $table
141
     * @param int    $userid
142
     * @param string $field
143
     * @param int    $value
144
     */
145
    public function updateSingleValue($table, $userid, $field, $value)
146
    {
147
        global $xoopsUser, $xoopsDB;
148
        $myts   = \MyTextSanitizer::getInstance();
149
        $sql    = 'UPDATE ' . $xoopsDB->prefix($table) . ' SET ' . $field . "='" . $myts->addSlashes($value) . "' WHERE userid='" . (int)$userid . "'";
150
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
151
    }
152
153
    /**
154
     * saveImage function
155
     * @param $values
156
     */
157 View Code Duplication
    public function saveImage($values)
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...
158
    {
159
        global $xoopsUser, $xoopsDB;
160
        $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
161
        $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_images') . ' VALUES (' . $values . ')';
162
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
163
    }
164
165
    /**
166
     * DeleteImage function
167
     * @param int    $userid
168
     * @param string $imagename
169
     */
170 View Code Duplication
    public function DeleteImage($userid, $imagename)
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...
171
    {
172
        global $xoopsUser, $xoopsDB;
173
        $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
174
        $sql    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE imgname = '" . stripslashes($imagename) . "' AND userid='" . $userid . "'";
175
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
176
    }
177
178
    /**
179
     * handlePosts function
180
     */
181
    public function handlePosts()
182
    {
183
        global $xoopsUser, $xoopsDB;
184
        $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
185
        $uid  = $xoopsUser->getVar('uid');
186
        $user = new \XoopsUser($uid);
187
        $img  = new Images();
188
        if ('' == $this->getVar($uid, 'userimage')) {
189
            $avatar = $user->user_avatar();
190
        } else {
191
            $avatar = $this->getVar($uid, 'userimage');
192
        }
193
194
        if ('2' != $_POST['relationship']) {
195
            $partner = Smallworld_sanitize($_POST['partner']);
196
        } else {
197
            $partner = '';
198
        }
199
200
        $regdate                = time();
201
        $username               = $user->uname();
202
        $realname               = Smallworld_sanitize($_POST['realname']);
203
        $gender                 = isset($_POST['gender']) ? $_POST['gender'] : '';
204
        $intingender            = isset($_POST['intingender']) ? Smallworld_sanitize(serialize($_POST['intingender'])) : Smallworld_sanitize(serialize([0 => '3']));
205
        $relationship           = Smallworld_sanitize($_POST['relationship']);
206
        $searchrelat            = isset($_POST['searchrelat']) ? Smallworld_sanitize(serialize($_POST['searchrelat'])) : Smallworld_sanitize(serialize([0 => '0']));
207
        $birthday               = Smallworld_sanitize(Smallworld_euroToUsDate($_POST['birthday']));
208
        $birthplace             = Smallworld_sanitize($_POST['birthplace']);
209
        $birthplace_lat         = Smallworld_sanitize($_POST['birthplace_lat']);
210
        $birthplace_lng         = Smallworld_sanitize($_POST['birthplace_lng']);
211
        $birthplace_country     = Smallworld_sanitize($_POST['birthplace_country']);
212
        $birthplace_country_img = isset($_POST['birthplace_country_img']) ? Smallworld_sanitize($_POST['birthplace_country_img']) : '';
0 ignored issues
show
Unused Code introduced by
$birthplace_country_img 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...
213
        $politic                = Smallworld_sanitize($_POST['politic']);
214
        $religion               = Smallworld_sanitize($_POST['religion']);
215
        $emailtype              = Smallworld_sanitize(serialize($_POST['emailtype']));
216
        $screenname_type        = Smallworld_sanitize(serialize($_POST['screenname_type']));
217
        $screenname             = Smallworld_sanitize(serialize($_POST['screenname']));
218
        $mobile                 = Smallworld_sanitize($_POST['mobile']);
219
        $phone                  = Smallworld_sanitize($_POST['phone']);
220
        $adress                 = Smallworld_sanitize($_POST['adress']);
221
        $present_city           = Smallworld_sanitize($_POST['present_city']);
222
        $present_lat            = Smallworld_sanitize($_POST['present_lat']);
223
        $present_lng            = Smallworld_sanitize($_POST['present_lng']);
224
        $present_country        = Smallworld_sanitize($_POST['present_country']);
225
        $present_country_img    = isset($_POST['present_country_img']) ? Smallworld_sanitize($_POST['present_country_img']) : '';
0 ignored issues
show
Unused Code introduced by
$present_country_img 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...
226
        $website                = Smallworld_sanitize($_POST['website']);
227
        $interests              = Smallworld_sanitize($_POST['interests']);
228
        $music                  = Smallworld_sanitize($_POST['music']);
229
        $tvshow                 = Smallworld_sanitize($_POST['tvshow']);
230
        $movie                  = Smallworld_sanitize($_POST['movie']);
231
        $books                  = Smallworld_sanitize($_POST['books']);
232
        $aboutme                = Smallworld_sanitize($_POST['aboutme']);
233
        $school_type            = Smallworld_sanitize(serialize($_POST['school_type']));
234
        $school                 = Smallworld_sanitize(serialize($_POST['school']));
235
        $schoolstart            = Smallworld_sanitize(serialize($_POST['schoolstart']));
236
        $schoolstop             = Smallworld_sanitize(serialize($_POST['schoolstop']));
237
        $jobemployer            = Smallworld_sanitize(serialize($_POST['employer']));
238
        $jobposition            = Smallworld_sanitize(serialize($_POST['position']));
239
        $jobstart               = Smallworld_sanitize(serialize(Smallworld_YearOfArray($_POST['jobstart'])));
240
        $jobstop                = Smallworld_sanitize(serialize(Smallworld_YearOfArray($_POST['jobstop'])));
241
        $jobdescription         = Smallworld_sanitize(serialize($_POST['description']));
242
243
        $sql = '';
0 ignored issues
show
Unused Code introduced by
$sql 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...
244
245
        if ('edit' === $_POST['function']) {
246
            // Update all values in user_table
247
            $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_user') . ' SET ';
248
            $sql    .= "realname = '" . $realname . "', username= '" . $username . "', userimage = '" . $avatar . "', gender = '" . $gender . "',";
249
            $sql    .= "intingender = '" . $intingender . "',relationship = '" . $relationship . "', partner = '" . $partner . "', searchrelat = '" . $searchrelat . "',";
250
            $sql    .= "birthday = '" . $birthday . "',birthplace = '" . $birthplace . "',birthplace_lat = '" . (float)$birthplace_lat . "',";
251
            $sql    .= "birthplace_lng = '" . (float)$birthplace_lng . "',birthplace_country = '" . $birthplace_country . "',politic = '" . $politic . "',";
252
            $sql    .= "religion = '" . $religion . "',emailtype = '" . $emailtype . "',screenname_type = '" . $screenname_type . "',";
253
            $sql    .= "screenname = '" . $screenname . "',mobile = '" . (float)$mobile . "',phone = '" . (float)$phone . "',adress = '" . $adress . "',";
254
            $sql    .= "present_city = '" . $present_city . "',present_lat = '" . (float)$present_lat . "',present_lng = '" . (float)$present_lng . "',";
255
            $sql    .= "present_country = '" . $present_country . "',website = '" . $website . "',interests = '" . $interests . "',";
256
            $sql    .= "music = '" . $music . "',tvshow = '" . $tvshow . "',movie = '" . $movie . "',";
257
            $sql    .= "books = '" . $books . "',aboutme = '" . $aboutme . "',school_type = '" . $school_type . "',";
258
            $sql    .= "school = '" . $school . "', schoolstart = '" . $schoolstart . "',schoolstop = '" . $schoolstop . "',";
259
            $sql    .= "employer = '" . $jobemployer . "', position = '" . $jobposition . "',jobstart = '" . $jobstart . "',";
260
            $sql    .= "jobstop = '" . $jobstop . "', description = '" . $jobdescription . "' ";
261
            $sql    .= "WHERE userid ='" . (int)$uid . "'";
262
            $result = $xoopsDB->queryF($sql);
263
            if (false === $result) {
264
                die('SQL error:' . $sql . '');
265
            }
266
267
            $this->EditAdmins($uid, $realname, $avatar);
268
            $img->createAlbum($uid);
269
        }
270
271
        if ('save' === $_POST['function']) {
272
            $sql    = 'INSERT INTO '
273
                      . $xoopsDB->prefix('smallworld_user')
274
                      . ' (id, userid, regdate, username, userimage, realname, gender, intingender, relationship, partner, searchrelat, birthday, birthplace, birthplace_lat, birthplace_lng, birthplace_country, politic, religion, emailtype, screenname_type, screenname, mobile, phone, adress, present_city, present_lat, present_lng, present_country, website, interests, music, tvshow, movie, books, aboutme, school_type, school, schoolstart, schoolstop, employer, position, jobstart, jobstop, description, friends, followers, admin_flag) ';
275
            $sql    .= "VALUES ('','" . (int)$uid . "', '" . $regdate . "', '" . $username . "', '" . $avatar . "', '" . $realname . "', '" . $gender . "', '" . $intingender . "', '" . $relationship . "', '" . $partner . "', '" . $searchrelat . "','";
276
            $sql    .= $birthday . "', '" . $birthplace . "', '" . (float)$birthplace_lat . "', '" . (float)$birthplace_lng . "', '" . $birthplace_country . "', '" . $politic . "', '" . $religion . "','";
277
            $sql    .= $emailtype . "', '" . $screenname_type . "', '" . $screenname . "', '" . (float)$mobile . "', '" . (float)$phone . "', '" . $adress . "', '" . $present_city . "', '" . (float)$present_lat . "','";
278
            $sql    .= (float)$present_lng . "', '" . $present_country . "', '" . $website . "', '" . $interests . "', '" . $music . "', '" . $tvshow . "', '" . $movie . "', '" . $books . "', '" . $aboutme . "', '";
279
            $sql    .= $school_type . "', '" . $school . "', '" . $schoolstart . "', '" . $schoolstop . "', '" . $jobemployer . "', '" . $jobposition . "', '" . $jobstart . "', '" . $jobstop . "', '" . $jobdescription . "', ";
280
            $sql    .= "'0', '0', '0')";
281
            $result = $xoopsDB->queryF($sql);
282
            if (false === $result) {
283
                die('SQL error:' . $sql . '');
284
            }
285
            $this->SetAdmins($uid, $username, $realname, $avatar);
286
            $img->createAlbum($uid);
287
        }
288
    }
289
290
    /**
291
     * SetAdmins function
292
     * @param int    $userID
293
     * @param string $username
294
     * @param string $realname
295
     * @param mixed  $avatar
296
     */
297
    public function SetAdmins($userID, $username, $realname, $avatar)
298
    {
299
        global $xoopsDB, $xoopsUser;
300
        $ip     = $_SERVER['REMOTE_ADDR'];
301
        $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_admin') . ' (id,userid,username, realname,userimage,ip,complaint,inspect_start, ' . "inspect_stop) VALUES ('', '" . $userID . "', '" . $username . "','" . $realname . "', '" . $avatar . "','" . $ip . "','0','0','0')";
302
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
303
    }
304
305
    /**
306
     * EditAdmins function
307
     * @param int    $userID
308
     * @param string $realname
309
     * @param mixed  $avatar
310
     */
311
    public function EditAdmins($userID, $realname, $avatar)
312
    {
313
        global $xoopsDB;
314
        $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . " SET realname = '" . $realname . "', userimage = '" . $avatar . "' WHERE userid = '" . (int)$userID . "'";
315
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
316
    }
317
318
    /**
319
     * alreadycomplaint function
320
     * - Check if user has already sent complaint
321
     * @param string $msg
322
     * @param int    $by
323
     * @param int    $against
324
     * @return int
325
     */
326
    public function alreadycomplaint($msg, $by, $against)
327
    {
328
        global $xoopsDB;
329
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_complaints') . " WHERE byuser_id = '" . (int)$by . "' AND owner = '" . (int)$against . "' AND link = '" . addslashes($msg) . "'";
330
        $result = $xoopsDB->queryF($sql);
331
        $i      = $xoopsDB->getRowsNum($result);
332
        if ($i < 1) {
333
            $query  = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_complaints') . " (complaint_id,link,byuser_id,owner) VALUES ('', '" . addslashes($msg) . "', '" . (int)$by . "', '" . (int)$against . "')";
334
            $result = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
335
        }
336
337
        return $i;
338
    }
339
340
    /**
341
     * updateComplaint function
342
     * @param int $userID
343
     */
344
    public function updateComplaint($userID)
345
    {
346
        global $xoopsDB;
347
        $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . ' SET complaint = complaint + 1 ' . "WHERE userid = '" . (int)$userID . "'";
348
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
349
    }
350
351
    /**
352
     * updateInspection function
353
     * @param int   $userID
354
     * @param int   $start
355
     * @param int stop
356
     * @param mixed $stop
357
     */
358
    public function updateInspection($userID, $start, $stop)
0 ignored issues
show
Unused Code introduced by
The parameter $start 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...
359
    {
360
        global $xoopsDB;
361
        $newstop = $time() + $stop;
0 ignored issues
show
Bug introduced by
The variable $time 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...
362
        $sql     = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . " SET inspect_start = '" . $time() . "', instect_stop = '" . $newstop . "' WHERE userid ='" . (int)$userID . "'";
363
        $result  = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
364
    }
365
366
    /**
367
     * handleImageEdit function
368
     */
369
    public function handleImageEdit()
370
    {
371
        global $xoopsDB;
372
        for ($i = 0, $iMax = count($_POST['id']); $i < $iMax; ++$i) {
373
            $id     = (int)$_POST['id'][$i];
374
            $desc   = $_POST['imgdesc'][$i];
375
            $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_images') . " SET `desc` = '" . addslashes($desc) . "' WHERE `id`='" . $id . "'";
376
            $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
377
        }
378
    }
379
380
    /**
381
     * updateInspection function
382
     * - insert aplication for friendship into db or delete if denied
383
     * @param int $status
384
     * @param int $friendid
385
     * @param int $userid
386
     */
387
    public function toogleFriendInvite($status, $friendid, $userid)
388
    {
389
        global $xoopsDB;
390
        if (0 == $status) {
391
            $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_friends') . " (id,me,you,status,date) VALUES ('', '" . $userid . "', '" . $friendid . "', '1', UNIX_TIMESTAMP())";
392
            $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
393
        }
394 View Code Duplication
        if ($status > 0) {
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...
395
            $sql     = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$friendid . "' AND you = '" . (int)$userid . "'";
396
            $sql2    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'";
397
            $result  = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
398
            $result2 = $xoopsDB->queryF($sql2);
0 ignored issues
show
Unused Code introduced by
$result2 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...
399
400
            // Since friendship is canceled also following is deleted
401
            $this->toogleFollow(1, $userid, $friendid);
402
        }
403
    }
404
405
    /**
406
     * toogleFollow function
407
     * - Insert following to db or delete if requested
408
     * @param int $following
409
     * @param int $myUid
410
     * @param int $friend
411
     */
412
    public function toogleFollow($following, $myUid, $friend)
413
    {
414
        global $xoopsDB;
415
        if (0 == $following) {
416
            $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_followers') . " (id,me,you,status,date) VALUES ('', '" . $myUid . "', '" . $friend . "', '1', UNIX_TIMESTAMP())";
417
            $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
418
        }
419
        if ($following > 0) {
420
            $sql     = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE you = '" . (int)$friend . "'";
421
            $sql     .= " AND me = '" . (int)$myUid . "'";
422
            $sql2    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$friend . "'";
423
            $sql2    .= " AND you = '" . (int)$myUid . "'";
424
            $result2 = $xoopsDB->queryF($sql2);
0 ignored issues
show
Unused Code introduced by
$result2 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...
425
        }
426
    }
427
428
    /**
429
     * SetFriendshitStat function
430
     * @param int $stat
431
     * @param int $myUid
432
     * @param int $friend
433
     */
434
    public function SetFriendshitStat($stat, $myUid, $friend)
435
    {
436
        global $xoopsDB;
437
        if (1 == $stat) {
438
            $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_friends') . " SET status = '2' WHERE `me` = '" . $friend . "' AND `you` = '" . $myUid . "'";
439
            $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
440
            $query  = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_friends') . " (id,me,you,status,date) VALUES ('', '" . $myUid . "', '" . $friend . "', '2', UNIX_TIMESTAMP())";
441
            $result = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
442
        }
443 View Code Duplication
        if ($stat < 0) {
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...
444
            $sql     = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$friend . "' AND you = '" . (int)$myUid . "'";
445
            $sql2    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$friend . "' AND me = '" . (int)$myUid . "'";
446
            $result  = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
447
            $result2 = $xoopsDB->queryF($sql2);
0 ignored issues
show
Unused Code introduced by
$result2 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...
448
        }
449
    }
450
451
    /**
452
     * deleteWallMsg function
453
     * @param int $id
454
     * @param int $smallworld_msg_id
455
     * @return true
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

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...
456
     */
457
    public function deleteWallMsg($id, $smallworld_msg_id)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
458
    {
459
        global $xoopsDB;
460
        $query   = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE msg_id = '" . $smallworld_msg_id . "'";
461
        $result  = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
462
        $query2  = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE msg_id_fk = '" . $smallworld_msg_id . "'";
463
        $result2 = $xoopsDB->queryF($query2);
0 ignored issues
show
Unused Code introduced by
$result2 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...
464
        //delete votes
465
        $query3  = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE msg_id = '" . $smallworld_msg_id . "'";
466
        $result3 = $xoopsDB->queryF($query3);
0 ignored issues
show
Unused Code introduced by
$result3 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...
467
468
        return true;
469
    }
470
471
    /**
472
     * deleteWallComment function
473
     * - Delete Comments
474
     * @param int $smallworld_com_id
475
     * @return true
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

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...
476
     */
477 View Code Duplication
    public function deleteWallComment($smallworld_com_id)
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...
478
    {
479
        global $xoopsDB;
480
        $query   = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE com_id = '" . $smallworld_com_id . "'";
481
        $result  = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
482
        $query2  = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE com_id = '" . $smallworld_com_id . "'";
483
        $result2 = $xoopsDB->queryF($query2);
0 ignored issues
show
Unused Code introduced by
$result2 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...
484
485
        return true;
486
    }
487
488
    /**
489
     * CountUsersRates function
490
     * - Delete Comments
491
     * @param int    $userid
492
     * @param string $val
493
     * @return int
494
     */
495 View Code Duplication
    public function CountUsersRates($userid, $val)
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...
496
    {
497
        global $xoopsUser, $xoopsDB;
498
        $query  = 'Select SUM(' . $val . ') as sum from ' . $xoopsDB->prefix('smallworld_vote') . " where owner = '" . $userid . "'";
499
        $result = $xoopsDB->queryF($query);
500
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
501
            $sum = $row['sum'];
502
        }
503
        if ('' == $sum) {
0 ignored issues
show
Bug introduced by
The variable $sum 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...
504
            $sum = '0';
505
        }
506
507
        return $sum;
508
    }
509
510
    /**
511
     * deleteAccount function
512
     * - Delete user account and associate rows across tables
513
     * @param int $userid
514
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|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...
515
     */
516 View Code Duplication
    public function deleteAccount($userid)
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...
517
    {
518
        global $xoopsDB, $xoopsUser;
519
        $user     = new \XoopsUser($userid);
520
        $username = $user->uname();
521
        $sql01    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_admin') . " WHERE userid = '" . $userid . "'";
522
        $sql02    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "'";
523
        $sql03    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'";
524
        $sql04    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'";
525
        $sql05    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'";
526
        $sql06    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "'";
527
        $sql07    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userid . "'";
528
        $sql08    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE user_id = '" . $userid . "'";
529
        $sql09    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_complaints') . " WHERE owner = '" . $userid . "' OR byuser_id = '" . $userid . "'";
530
        $sql10    = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_settings') . " WHERE userid = '" . $userid . "'";
531
532
        $result01 = $xoopsDB->queryF($sql01);
0 ignored issues
show
Unused Code introduced by
$result01 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...
533
        $result02 = $xoopsDB->queryF($sql02);
0 ignored issues
show
Unused Code introduced by
$result02 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...
534
        $result03 = $xoopsDB->queryF($sql03);
0 ignored issues
show
Unused Code introduced by
$result03 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...
535
        $result04 = $xoopsDB->queryF($sql04);
0 ignored issues
show
Unused Code introduced by
$result04 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...
536
        $result05 = $xoopsDB->queryF($sql05);
0 ignored issues
show
Unused Code introduced by
$result05 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...
537
        $result06 = $xoopsDB->queryF($sql06);
0 ignored issues
show
Unused Code introduced by
$result06 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...
538
        $result07 = $xoopsDB->queryF($sql07);
0 ignored issues
show
Unused Code introduced by
$result07 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...
539
        $result08 = $xoopsDB->queryF($sql08);
0 ignored issues
show
Unused Code introduced by
$result08 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...
540
        $result09 = $xoopsDB->queryF($sql09);
0 ignored issues
show
Unused Code introduced by
$result09 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...
541
        $result10 = $xoopsDB->queryF($sql10);
0 ignored issues
show
Unused Code introduced by
$result10 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...
542
        // Remove picture dir
543
        $dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/';
544
        $this->smallworld_remDir($userid, $dirname, $empty = false);
545
        echo $username . _AM_SMALLWORLD_ADMIN_USERDELETEDALERT;
546
    }
547
548
    /**
549
     * SmallworldDeleteDirectory function
550
     * - Delete images from users on delete
551
     * @param int $userid
552
     * @return true
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

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...
553
     */
554
    public function SmallworldDeleteDirectory($userid)
555
    {
556
        $dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/';
557
        if (is_dir($dirname)) {
558
            $dir_handle = opendir($dirname);
559
        }
560
        if (!$dir_handle) {
0 ignored issues
show
Bug introduced by
The variable $dir_handle 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...
561
            return false;
562
        }
563
        while (false !== ($file = readdir($dir_handle))) {
564 View Code Duplication
            if ('.' !== $file && '..' !== $file) {
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...
565
                if (!is_dir($dirname . '/' . $file)) {
566
                    unlink($dirname . '/' . $file);
567
                } else {
568
                    $this->SmallworldDeleteDirectory($dirname . '/' . $file);
569
                }
570
            }
571
        }
572
        closedir($dir_handle);
573
        rmdir($dirname);
574
575
        return true;
576
    }
577
578
    /**
579
     * smallworld_remDir function
580
     * - Remove user image dir in uploads.
581
     * @param int         $userid
582
     * @param string|bool $directory
583
     * @param bool|int    $empty
584
     * @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...
585
     */
586 View Code Duplication
    public function smallworld_remDir($userid, $directory, $empty = false)
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...
587
    {
588
        if ('' != $userid) {
589
            if ('/' === mb_substr($directory, -1)) {
590
                $directory = mb_substr($directory, 0, -1);
591
            }
592
593
            if (!file_exists($directory) || !is_dir($directory)) {
594
                return false;
595
            } elseif (!is_readable($directory)) {
596
                return false;
597
            }
598
            $directoryHandle = opendir($directory);
599
            while (false !== ($contents = readdir($directoryHandle))) {
600
                if ('.' !== $contents && '..' !== $contents) {
601
                    $path = $directory . '/' . $contents;
602
                    if (is_dir($path)) {
603
                        $this->smallworld_remDir($userid, $path);
604
                    } else {
605
                        unlink($path);
606
                    }
607
                }
608
            }
609
            closedir($directoryHandle);
610
            if (false === $empty) {
611
                if (!rmdir($directory)) {
612
                    return false;
613
                }
614
            }
615
616
            return true;
617
        }
618
    }
619
620
    /**
621
     * Update private settings
622
     * @param int id ($userid)
623
     * @param string posts (serialized values)
624
     * @param mixed $id
625
     * @param mixed $posts
626
     */
627
    public function saveSettings($id, $posts)
628
    {
629
        global $xoopsDB;
630
        $sql    = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$id . '';
631
        $result = $xoopsDB->queryF($sql);
632
        $i      = $xoopsDB->getRowsNum($result);
633
        if ($i > 0) {
634
            $sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_settings') . " SET value = '" . $posts . "' WHERE userid = " . (int)$id . '';
635
        } else {
636
            $sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_settings') . " (id,userid,value) VALUES ('', '" . $id . "', '" . $posts . "')";
637
        }
638
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
639
        $this->GetSettings($id);
640
    }
641
642
    /**
643
     * Retrieve private settings
644
     * @param int userid
645
     * @param mixed $userid
646
     * @return string serialized string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

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...
647
     */
648
    public function GetSettings($userid)
649
    {
650
        global $xoopsDB;
651
        $sql    = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid . '';
652
        $result = $xoopsDB->queryF($sql);
653
        $i      = $xoopsDB->getRowsNum($result);
654
        if ($i < 1) {
655
            $posts = serialize(
656
                [
657
                    'posts'    => 0,
658
                    'comments' => 0,
659
                    'notify'   => 1,
660
                ]
661
            );
662
            $this->saveSettings($userid, $posts);
663
            $this->GetSettings($userid);
664
        } else {
665
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
666
                $data = $row['value'];
667
            }
668
669
            return json_encode(unserialize(stripslashes($data)));
0 ignored issues
show
Bug introduced by
The variable $data 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...
670
        }
671
    }
672
}
673