functions.php ➔ alumni_convertorderbyout()   F
last analyzed

Complexity

Conditions 13
Paths 4096

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 26
nc 4096
nop 1
dl 0
loc 41
rs 2.7716
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 21.

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

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

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

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * Alumni module for Xoops
13
 *
14
 * @copyright       XOOPS Project https://xoops.org/
15
 * @license         GPL 2.0 or later
16
 * @package         alumni
17
 * @since           2.6.x
18
 * @author          John Mordo (jlm69)
19
 */
20
21
$moduleDirName = basename(dirname(__DIR__));
22
23
$xoops          = Xoops::getInstance();
24
$listingHandler = $xoops->getModuleHandler('listing', 'alumni');
25
26 View Code Duplication
function alumni_ShowImg()
0 ignored issues
show
Coding Style introduced by
function alumni_ShowImg() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Duplication introduced by
This function 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...
27
{
28
    global $moduleDirName;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

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

1. Pass all data via parameters

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

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

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

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
30
    echo "<script type=\"text/javascript\">\n";
31
    echo "<!--\n\n";
32
    echo "function showimage() {\n";
33
    echo "if (!document.images)\n";
34
    echo "return\n";
35
    echo "document.images.avatar.src=\n";
36
    echo "'" . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n";
37
    echo "}\n\n";
38
    echo "//-->\n";
39
    echo "</script>\n";
40
}
41
42 View Code Duplication
function alumni_ShowImg2()
0 ignored issues
show
Coding Style introduced by
function alumni_ShowImg2() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Duplication introduced by
This function 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...
43
{
44
    global $moduleDirName;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

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

1. Pass all data via parameters

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

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

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

    public function myFunction() {
        // Do something
    }
}
Loading history...
45
46
    echo "<script type=\"text/javascript\">\n";
47
    echo "<!--\n\n";
48
    echo "function showimage2() {\n";
49
    echo "if (!document.images)\n";
50
    echo "return\n";
51
    echo "document.images.scphoto.src=\n";
52
    echo "'" . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/schools/' + document.imcat.scphoto.options[document.imcat.scphoto.selectedIndex].value\n";
53
    echo "}\n\n";
54
    echo "//-->\n";
55
    echo "</script>\n";
56
}
57
58
//Reusable Link Sorting Functions
59
/**
60
 * @param $orderby
61
 * @return string
62
 */
63
function alumni_convertorderbyin($orderby)
0 ignored issues
show
Coding Style introduced by
function alumni_convertorderbyin() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
64
{
65
    switch (trim($orderby)) {
66
        case 'nameA':
67
            $orderby = 'lname ASC';
68
            break;
69
        case 'schoolA':
70
            $orderby = 'school ASC';
71
            break;
72
        case 'studiesA':
73
            $orderby = 'studies ASC';
74
            break;
75
        case 'yearA':
76
            $orderby = 'year ASC';
77
            break;
78
        case 'dateA':
79
            $orderby = 'date ASC';
80
            break;
81
        case 'viewA':
82
            $orderby = 'view ASC';
83
            break;
84
        case 'nameD':
85
            $orderby = 'lname DESC';
86
            break;
87
        case 'schoolD':
88
            $orderby = 'school DESC';
89
            break;
90
        case 'studiesD':
91
            $orderby = 'studies DESC';
92
            break;
93
        case 'yearD':
94
            $orderby = 'year DESC';
95
            break;
96
        case 'viewD':
97
            $orderby = 'view DESC';
98
            break;
99
        case 'dateD':
100
        default:
101
            $orderby = 'date DESC';
102
            break;
103
    }
104
105
    return $orderby;
106
}
107
108
/**
109
 * @param $orderby
110
 * @return string
111
 */
112
function alumni_convertorderbytrans($orderby)
0 ignored issues
show
Coding Style introduced by
function alumni_convertorderbytrans() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
113
{
114
    global $main_lang;
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

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

1. Pass all data via parameters

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

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

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

    public function myFunction() {
        // Do something
    }
}
Loading history...
115
116
    if ('view ASC' === $orderby) {
117
        $orderbyTrans = '' . constant($main_lang . '_POPULARITYLTOM') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
118
    }
119
    if ('view DESC' === $orderby) {
120
        $orderbyTrans = '' . constant($main_lang . '_POPULARITYMTOL') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
121
    }
122
    if ('lname ASC' === $orderby) {
123
        $orderbyTrans = '' . constant($main_lang . '_NAMEATOZ') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
124
    }
125
    if ('lname DESC' === $orderby) {
126
        $orderbyTrans = '' . constant($main_lang . '_NAMEZTOA') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
127
    }
128
    if ('school ASC' === $orderby) {
129
        $orderbyTrans = '' . constant($main_lang . '_SCHOOLATOZ') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
130
    }
131
    if ('school DESC' === $orderby) {
132
        $orderbyTrans = '' . constant($main_lang . '_SCHOOLZTOA') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
133
    }
134
    if ('studies ASC' === $orderby) {
135
        $orderbyTrans = '' . constant($main_lang . '_STUDIESATOZ') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
136
    }
137
    if ('studies DESC' === $orderby) {
138
        $orderbyTrans = '' . constant($main_lang . '_STUDIESZTOA') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
139
    }
140
    if ('year ASC' === $orderby) {
141
        $orderbyTrans = '' . constant($main_lang . '_YEAROLD') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
142
    }
143
    if ('year DESC' === $orderby) {
144
        $orderbyTrans = '' . constant($main_lang . '_YEARNEW') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
145
    }
146
    if ('date ASC' === $orderby) {
147
        $orderbyTrans = '' . constant($main_lang . '_DATEOLD') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
148
    }
149
    if ('date DESC' === $orderby) {
150
        $orderbyTrans = '' . constant($main_lang . '_DATENEW') . '';
0 ignored issues
show
Coding Style introduced by
$main_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
151
    }
152
153
    return $orderbyTrans;
0 ignored issues
show
Bug introduced by
The variable $orderbyTrans 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...
154
}
155
156
/**
157
 * @param $orderby
158
 * @return string
159
 */
160
function alumni_convertorderbyout($orderby)
0 ignored issues
show
Coding Style introduced by
function alumni_convertorderbyout() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
161
{
162
    if ('lname ASC' === $orderby) {
163
        $orderby = 'nameA';
164
    }
165
    if ('school ASC' === $orderby) {
166
        $orderby = 'schoolA';
167
    }
168
    if ('studies ASC' === $orderby) {
169
        $orderby = 'studiesA';
170
    }
171
    if ('year ASC' === $orderby) {
172
        $orderby = 'yearA';
173
    }
174
    if ('date ASC' === $orderby) {
175
        $orderby = 'dateA';
176
    }
177
    if ('view ASC' === $orderby) {
178
        $orderby = 'viewA';
179
    }
180
    if ('lname DESC' === $orderby) {
181
        $orderby = 'nameD';
182
    }
183
    if ('school DESC' === $orderby) {
184
        $orderby = 'schoolD';
185
    }
186
    if ('studies DESC' === $orderby) {
187
        $orderby = 'studiesD';
188
    }
189
    if ('year DESC' === $orderby) {
190
        $orderby = 'yearD';
191
    }
192
    if ('date DESC' === $orderby) {
193
        $orderby = 'dateD';
194
    }
195
    if ('view DESC' === $orderby) {
196
        $orderby = 'viewD';
197
    }
198
199
    return $orderby;
200
}
201