Completed
Pull Request — master (#1)
by
unknown
02:00
created

wflLists::wflLists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 8
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Class: wflLists
4
 * $Id: wfl_list.php v 1.00 21 June 2005 John N Exp $
5
 * Module: WF-Links
6
 * Version: v1.0.3
7
 * Release Date: 21 June 2005
8
 * Developer: John N
9
 * Team: WF-Projects
10
 * Licence: GNU
11
 */
12
13
class wflLists
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
{
15
    var $value;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $value.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
16
    var $selected;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $selected.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
17
    var $path='uploads';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $path.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
18
    var $size;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $size.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
19
    var $emptyselect;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $emptyselect.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
20
    var $type;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $type.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
21
    var $prefix;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $prefix.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
22
    var $suffix;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $suffix.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
23
24
    function __construct($path="uploads", $value = null, $selected='', $size = 1, $emptyselect = 0, $type = 0, $prefix='', $suffix='')
0 ignored issues
show
Unused Code introduced by
The parameter $prefix 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...
Unused Code introduced by
The parameter $suffix 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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
    {
26
        $this -> value = $value;
27
        $this -> selection = $selected;
0 ignored issues
show
Bug introduced by
The property selection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
        $this -> path = $path;
29
        $this -> size = intval($size);
30
        $this -> emptyselect = ($emptyselect) ? 0 : 1;
31
        $this -> type = $type;
32
    }
33
34 View Code Duplication
    function &getarray($this_array) {
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...
35
        $ret="<select size='" . $this -> size() . "' name='$this->value()'>";
36
        if ($this -> emptyselect) {
37
            $ret .= "<option value='" . $this -> value() . "'>----------------------</option>";
38
        }
39
        foreach ($this_array as $content) {
40
            $opt_selected="";
41
42
            if ($content[0] == $this -> selected()) {
43
                $opt_selected="selected='selected'";
44
            }
45
            $ret .= "<option value='" . $content . "' $opt_selected>" . $content . "</option>";
46
        }
47
        $ret .= "</select>";
48
49
        return $ret;
50
    }
51
52
    /**
53
     * Private to be called by other parts of the class
54
     */
55
    function &getDirListAsArray($dirname) {
56
        $dirlist = array();
57
        if (is_dir($dirname) && $handle = opendir($dirname)) {
58
            while (false !== ($file = readdir($handle))) {
59
                if (!preg_match("/^[.]{1,2}$/", $file)) {
60
                    if (strtolower($file) != 'cvs' && is_dir($dirname . $file)) {
61
                        $dirlist[$file] = $file;
62
                    }
63
                }
64
            }
65
            closedir($handle);
66
67
            reset($dirlist);
68
        }
69
70
        return $dirlist;
71
    }
72
73
    function &getListTypeAsArray($dirname, $type='', $prefix="", $noselection = 1) {
74
75
        $filelist = array();
76
        switch (trim($type)) {
77
            case "images":
78
                $types="[.gif|.jpg|.png]";
79
                if ($noselection)
80
                    $filelist[""]=_AM_WFL_SHOWNOIMAGE;
81
                break;
82
            case "html":
83
                $types="[.htm|.html|.xhtml|.php|.php3|.phtml|.txt]";
84
                if ($noselection)
85
                    $filelist[""]="No Selection";
86
                break;
87
            default:
88
                $types="";
89
                if ($noselection)
90
                    $filelist[""]="No Selected File";
91
                break;
92
        }
93
94
        if (substr($dirname, -1) == '/') {
95
            $dirname = substr($dirname, 0, -1);
96
        }
97
98
        if (is_dir($dirname) && $handle = opendir($dirname)) {
99
            while (false !== ($file = readdir($handle))) {
100
                if (!preg_match("/^[.]{1,2}$/", $file) && preg_match("/$types$/i", $file) && is_file($dirname . '/' . $file)) {
101
                    if (strtolower($file) == "blank.gif")
102
                        Continue;
103
                    $file = $prefix . $file;
104
                    $filelist[$file] = $file;
105
                }
106
            }
107
            closedir($handle);
108
            asort($filelist);
109
            reset($filelist);
110
        }
111
112
        return $filelist;
113
    }
114
115
    function &getForum( $type = 1, $selected ) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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

Loading history...
116
        global $xoopsDB;
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...
117
        switch ( xoops_trim( $type ) ) {
118
            case 2:
119
                $sql = "SELECT id, name FROM " . $xoopsDB->prefix( "ibf_forums" ) . " ORDER BY id";
120
                break;
121
            case 3:
122
                $sql = "SELECT forum_id, forum_name FROM " . $xoopsDB->prefix( "pbb_forums" ) . " ORDER BY forum_id";
123
                break;
124
            case 4:
125
                $sql = "SELECT forum_id, forum_name FROM " . $xoopsDB -> prefix('bbex_forums') . " ORDER BY forum_id";
126
                break;
127
            case 1:
128
            case 0:
129
            default:
130
                $sql = "SELECT forum_id, forum_name FROM " . $xoopsDB->prefix( "bb_forums" ) . " ORDER BY forum_id";
131
                break;
132
        }
133
        $result = $xoopsDB->query( $sql );
134
135
        $noforum = ( defined( '_WFL_NO_FORUM' ) ) ? _WFL_NO_FORUM : _AM_WFL_NO_FORUM;
136
137
        echo "<select size='1' name='forumid'>";
138
        echo "<option value='0'>" . $noforum . "</option>";
139 View Code Duplication
        while (list($forum_id, $forum_name ) = $xoopsDB -> fetchRow($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
140
            $opt_selected = "";
141
            if ($forum_id == $selected) {
142
                $opt_selected = "selected='selected'";
143
            }
144
            echo "<option value='" . $forum_id . "' $opt_selected>" . $forum_name . "</option>";
145
        }
146
        echo "</select>";
147
148
           return $forum_array;
0 ignored issues
show
Bug introduced by
The variable $forum_array 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...
149
    }
150
151
    function value()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
152
    {
153
        return $this->value;
154
    }
155
156
    function selected()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
157
    {
158
        return $this->selected;
159
    }
160
161
    function paths()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
162
    {
163
        return $this->path;
164
    }
165
166
    function size()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
167
    {
168
        return $this->size;
169
    }
170
171
    function emptyselect()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
172
    {
173
        return $this->emptyselect;
174
    }
175
176
    function type()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
177
    {
178
        return $this->type;
179
    }
180
181
    function prefix()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
182
    {
183
        return $this->prefix;
184
    }
185
186
    function suffix()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
187
    {
188
        return $this->suffix;
189
    }
190
}
191