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

SelectBox::editField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
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
/**
13
 * Class SystemMessage
14
 */
15
class SystemMessage
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...
16
{
17
    /**
18
     * @param $message
19
     */
20
    public function __construct($message)
21
    {
22
        echo '<span style="color: red;"><h3>' . $message . '</h3></span>';
23
    }
24
}
25
26
/**
27
 * Class Animal
28
 */
29
class Animal
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
30
{
31
    /**
32
     * @deprecated
33
     * @param int $animalnumber * @internal param int $id animal ID
34
     */
35
    public function __construct($animalnumber = 0)
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $GLOBALS which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
    {
37
        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...
38
        if ($animalnumber == 0) {
39
            $SQL = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE ID = '1'";
40
        } else {
41
            $SQL = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ID = ' . $animalnumber;
42
        }
43
        $result    = $GLOBALS['xoopsDB']->query($SQL);
44
        $row       = $GLOBALS['xoopsDB']->fetchRow($result);
45
        $numfields = $GLOBALS['xoopsDB']->getFieldsNum($result);
46
        for ($i = 0; $i < $numfields; ++$i) {
47
            $key        = mysqli_fetch_field_direct($result, $i)->name;
48
            $this->$key = $row[$i];
49
        }
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function getNumOfFields()
0 ignored issues
show
Coding Style introduced by
getNumOfFields uses the super-global variable $GLOBALS which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
56
    {
57
        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...
58
        $SQL    = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' ORDER BY `order`';
59
        $fields = array();
60
        $result = $GLOBALS['xoopsDB']->query($SQL);
61
        $count  = 0;
62 View Code Duplication
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
63
            $fields[] = $row['Id'];
64
            ++$count;
65
            $configValues[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$configValues was never initialized. Although not strictly required by PHP, it is generally a good practice to add $configValues = 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...
66
        }
67
        $this->configValues = isset($configValues) ? $configValues : '';
0 ignored issues
show
Bug introduced by
The property configValues 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...
68
        //print_r ($this->configValues); die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
69
        return $fields;
70
    }
71
72
    /**
73
     * @return mixed
74
     */
75
    public function getConfig()
76
    {
77
        return $this->configValues;
78
    }
79
}
80
81
/**
82
 * Class Field
83
 */
84
class Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
85
{
86
    /**
87
     * @param $fieldnumber
88
     * @param $config
89
     */
90
    public function __construct($fieldnumber, $config)
91
    {
92
        //find key where ID = $fieldnumber;
93
        for ($x = 0, $xMax = count($config); $x < $xMax; ++$x) {
94
            if ($config[$x]['Id'] = $fieldnumber) {
95
                foreach ($config[$x] as $key => $values) {
96
                    $this->$key = $values;
97
                }
98
            }
99
        }
100
        $this->id = $fieldnumber;
0 ignored issues
show
Bug introduced by
The property id 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...
101
    }
102
103
    /**
104
     * @return bool
105
     */
106
    public function isActive()
107
    {
108
        $active = $this->getSetting('isActive');
109
        if ($active == '1') {
110
            return true;
111
        }
112
113
        return false;
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    public function inAdvanced()
120
    {
121
        $active = $this->getSetting('ViewInAdvanced');
122
        if ($active == '1') {
123
            return true;
124
        }
125
126
        return false;
127
    }
128
129
    /**
130
     * @return bool
131
     */
132
    public function isLocked()
133
    {
134
        $active = $this->getSetting('locked');
135
        if ($active == '1') {
136
            return true;
137
        }
138
139
        return false;
140
    }
141
142
    /**
143
     * @return bool
144
     */
145
    public function hasSearch()
146
    {
147
        $active = $this->getSetting('HasSearch');
148
        if ($active == '1') {
149
            return true;
150
        }
151
152
        return false;
153
    }
154
155
    /**
156
     * @return bool
157
     */
158
    public function addLitter()
159
    {
160
        $active = $this->getSetting('Litter');
161
        if ($active == '1') {
162
            return true;
163
        }
164
165
        return false;
166
    }
167
168
    /**
169
     * @return bool
170
     */
171
    public function generalLitter()
172
    {
173
        $active = $this->getSetting('Generallitter');
174
        if ($active == '1') {
175
            return true;
176
        }
177
178
        return false;
179
    }
180
181
    /**
182
     * @return bool
183
     */
184
    public function hasLookup()
185
    {
186
        $active = $this->getSetting('LookupTable');
187
        if ($active == '1') {
188
            return true;
189
        }
190
191
        return false;
192
    }
193
194
    /**
195
     * @return string
196
     */
197
    public function getSearchString()
198
    {
199
        return '&amp;o=naam&amp;p';
200
    }
201
202
    /**
203
     * @return bool
204
     */
205
    public function inPie()
206
    {
207
        $active = $this->getSetting('ViewInPie');
208
        if ($active == '1') {
209
            return true;
210
        }
211
212
        return false;
213
    }
214
215
    /**
216
     * @return bool
217
     */
218
    public function inPedigree()
219
    {
220
        $active = $this->getSetting('ViewInPedigree');
221
        if ($active == '1') {
222
            return true;
223
        }
224
225
        return false;
226
    }
227
228
    /**
229
     * @return bool
230
     */
231
    public function inList()
232
    {
233
        $active = $this->getSetting('ViewInList');
234
        if ($active == '1') {
235
            return true;
236
        }
237
238
        return false;
239
    }
240
241
    public function getId()
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...
242
    {
243
        return $this->id;
244
    }
245
246
    /**
247
     * @param $setting
248
     *
249
     * @return mixed
250
     */
251
    public function getSetting($setting)
252
    {
253
        return $this->{$setting};
254
    }
255
256
    /**
257
     * @param $fieldnumber
258
     *
259
     * @return array
260
     */
261 View Code Duplication
    public function lookupField($fieldnumber)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

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

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
262
    {
263
        $ret = array();
264
        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...
265
        $SQL    = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $fieldnumber) . " ORDER BY 'order'";
266
        $result = $GLOBALS['xoopsDB']->query($SQL);
267
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
268
            $ret[] = array('id' => $row['Id'], 'value' => $row['value']);
269
        }
270
        //array_multisort($ret,SORT_ASC);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
271
        return $ret;
272
    }
273
274
    /**
275
     * @return XoopsFormLabel
276
     */
277
    public function viewField()
278
    {
279
        $view = new XoopsFormLabel($this->fieldname, $this->value);
0 ignored issues
show
Bug introduced by
The property fieldname 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...
Bug introduced by
The property value 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...
280
281
        return $view;
282
    }
283
284
    /**
285
     * @return string
286
     */
287
    public function showField()
288
    {
289
        return $this->fieldname . ' : ' . $this->value;
290
    }
291
292
    /**
293
     * @return mixed|string
294
     */
295
    public function showValue()
296
    {
297
        global $myts;
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...
298
299
        return $myts->displayTarea($this->value);
300
        //return $this->value;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
301
    }
302
303
    /**
304
     * @return string
305
     */
306
    public function searchField()
307
    {
308
        return '<input type="text" name="query" size="20">';
309
    }
310
}
311
312
/**
313
 * Class RadioButton
314
 */
315
class RadioButton extends Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
316
{
317
    /**
318
     * @param $parentObject
319
     * @param $animalObject
320
     */
321 View Code Duplication
    public function __construct($parentObject, $animalObject)
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...
322
    {
323
        $this->fieldnumber = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
324
325
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
326
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
327
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
328
        $this->lookuptable  = $parentObject->lookuptable;
0 ignored issues
show
Bug introduced by
The property lookuptable 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...
329
        if ($this->lookuptable == '0') {
330
            new Systemmessage('A lookuptable must be specified for userfield' . $this->fieldnumber);
331
        }
332
    }
333
334
    /**
335
     * @return XoopsFormRadio
336
     */
337
    public function editField()
338
    {
339
        $radio          = new XoopsFormRadio('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value);
340
        $lookupcontents = Field::lookupField($this->fieldnumber);
341
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
342
            $radio->addOption($lookupcontents[$i]['id'], $name = ($lookupcontents[$i]['value'] . '<br />'));
343
        }
344
345
        return $radio;
346
    }
347
348
    /**
349
     * @param string $name
350
     *
351
     * @return XoopsFormRadio
352
     */
353 View Code Duplication
    public function newField($name = '')
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...
354
    {
355
        $radio          = new XoopsFormRadio('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue);
356
        $lookupcontents = Field::lookupField($this->fieldnumber);
357
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
358
            $radio->addOption($lookupcontents[$i]['id'], $name = ($lookupcontents[$i]['value'] . '<br />'));
359
        }
360
361
        return $radio;
362
    }
363
364
    /**
365
     * @return XoopsFormLabel
366
     */
367
    public function viewField()
368
    {
369
        $lookupcontents = Field::lookupField($this->fieldnumber);
370
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
371
            if ($lookupcontents[$i]['id'] == $this->value) {
372
                $choosenvalue = $lookupcontents[$i]['value'];
373
            }
374
        }
375
        $view = new XoopsFormLabel($this->fieldname, $choosenvalue);
0 ignored issues
show
Bug introduced by
The variable $choosenvalue 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...
376
377
        return $view;
378
    }
379
380
    /**
381
     * @return string
382
     */
383 View Code Duplication
    public function showField()
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...
384
    {
385
        $lookupcontents = Field::lookupField($this->fieldnumber);
386
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
387
            if ($lookupcontents[$i]['id'] == $this->value) {
388
                $choosenvalue = $lookupcontents[$i]['value'];
389
            }
390
        }
391
392
        return $this->fieldname . ' : ' . $choosenvalue;
0 ignored issues
show
Bug introduced by
The variable $choosenvalue 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...
393
    }
394
395
    /**
396
     * @return mixed
397
     */
398 View Code Duplication
    public function showValue()
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...
399
    {
400
        $lookupcontents = Field::lookupField($this->fieldnumber);
401
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
402
            if ($lookupcontents[$i]['id'] == $this->value) {
403
                $choosenvalue = $lookupcontents[$i]['value'];
404
            }
405
        }
406
407
        return $choosenvalue;
0 ignored issues
show
Bug introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
408
    }
409
410
    /**
411
     * @return string
412
     */
413 View Code Duplication
    public function searchField()
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...
414
    {
415
        $select         = '<select size="1" name="query" style="width: 140px;">';
416
        $lookupcontents = Field::lookupField($this->fieldnumber);
417
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
418
            $select .= '<option value="' . $lookupcontents[$i]['id'] . '">' . $lookupcontents[$i]['value'] . '</option>';
419
        }
420
        $select .= '</select>';
421
422
        return $select;
423
    }
424
}
425
426
/**
427
 * Class SelectBox
428
 */
429
class SelectBox extends Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
430
{
431
    /**
432
     * @param $parentObject
433
     * @param $animalObject
434
     */
435 View Code Duplication
    public function __construct($parentObject, $animalObject)
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...
436
    {
437
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
438
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
439
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
440
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
441
        $this->lookuptable  = $parentObject->lookuptable;
0 ignored issues
show
Bug introduced by
The property lookuptable 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...
442
        if ($this->lookuptable == '0') {
443
            new Systemmessage('A lookuptable must be specified for userfield' . $this->fieldnumber);
444
        }
445
    }
446
447
    /**
448
     * @return XoopsFormSelect
449
     */
450 View Code Duplication
    public function editField()
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...
451
    {
452
        $select         = new XoopsFormSelect('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value, $size = 1, $multiple = false);
453
        $lookupcontents = Field::lookupField($this->fieldnumber);
454
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
455
            $select->addOption($lookupcontents[$i]['id'], $name = ($lookupcontents[$i]['value'] . '<br />'));
456
        }
457
458
        return $select;
459
    }
460
461
    /**
462
     * @param string $name
463
     *
464
     * @return XoopsFormSelect
465
     */
466 View Code Duplication
    public function newField($name = '')
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...
467
    {
468
        $select         = new XoopsFormSelect('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue, $size = 1, $multiple = false);
469
        $lookupcontents = Field::lookupField($this->fieldnumber);
470
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
471
            $select->addOption($lookupcontents[$i]['id'], $name = ($lookupcontents[$i]['value'] . '<br />'));
472
        }
473
474
        return $select;
475
    }
476
477
    /**
478
     * @return XoopsFormLabel
479
     */
480
    public function viewField()
481
    {
482
        $lookupcontents = Field::lookupField($this->fieldnumber);
483
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
484
            if ($lookupcontents[$i]['id'] == $this->value) {
485
                $choosenvalue = $lookupcontents[$i]['value'];
486
            }
487
        }
488
        $view = new XoopsFormLabel($this->fieldname, $choosenvalue);
0 ignored issues
show
Bug introduced by
The variable $choosenvalue 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...
489
490
        return $view;
491
    }
492
493
    /**
494
     * @return string
495
     */
496 View Code Duplication
    public function showField()
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...
497
    {
498
        $lookupcontents = Field::lookupField($this->fieldnumber);
499
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
500
            if ($lookupcontents[$i]['id'] == $this->value) {
501
                $choosenvalue = $lookupcontents[$i]['value'];
502
            }
503
        }
504
505
        return $this->fieldname . ' : ' . $choosenvalue;
0 ignored issues
show
Bug introduced by
The variable $choosenvalue 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...
506
    }
507
508
    /**
509
     * @return mixed
510
     */
511 View Code Duplication
    public function showValue()
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...
512
    {
513
        $choosenvalue   = '';
514
        $lookupcontents = Field::lookupField($this->fieldnumber);
515
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
516
            if ($lookupcontents[$i]['id'] == $this->value) {
517
                $choosenvalue = $lookupcontents[$i]['value'];
518
            }
519
        }
520
521
        return $choosenvalue;
522
    }
523
524
    /**
525
     * @return string
526
     */
527 View Code Duplication
    public function searchField()
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...
528
    {
529
        $select         = '<select size="1" name="query" style="width: 140px;">';
530
        $lookupcontents = Field::lookupField($this->fieldnumber);
531
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
532
            $select .= '<option value="' . $lookupcontents[$i]['id'] . '">' . $lookupcontents[$i]['value'] . '</option>';
533
        }
534
        $select .= '</select>';
535
536
        return $select;
537
    }
538
}
539
540
/**
541
 * Class TextBox
542
 */
543 View Code Duplication
class TextBox extends Field
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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

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

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
544
{
545
    /**
546
     * @param $parentObject
547
     * @param $animalObject
548
     */
549
    public function __construct($parentObject, $animalObject)
550
    {
551
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
552
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
553
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
554
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
555
        $this->lookuptable  = $parentObject->lookuptable;
0 ignored issues
show
Bug introduced by
The property lookuptable 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...
556
        if ($this->lookuptable == '1') {
557
            new Systemmessage('No lookuptable may be specified for userfield' . $this->fieldnumber);
558
        }
559
        if ($parentObject->ViewInAdvanced == '1') {
560
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be shown in advanced info');
561
        }
562
        if ($parentObject->ViewInPie == '1') {
563
            new Systemmessage('A Pie-chart cannot be specified for userfield' . $this->fieldnumber);
564
        }
565
    }
566
567
    /**
568
     * @return XoopsFormText
569
     */
570
    public function editField()
571
    {
572
        $textbox = new XoopsFormText('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $size = 50, $maxsize = 50, $value = $this->value);
573
574
        return $textbox;
575
    }
576
577
    /**
578
     * @param string $name
579
     *
580
     * @return XoopsFormText
581
     */
582
    public function newField($name = '')
583
    {
584
        $textbox = new XoopsFormText('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $size = 50, $maxsize = 50, $value = $this->defaultvalue);
585
586
        return $textbox;
587
    }
588
589
    /**
590
     * @return string
591
     */
592
    public function getSearchString()
593
    {
594
        return '&amp;o=naam&amp;l=1';
595
    }
596
}
597
598
/**
599
 * Class TextArea
600
 */
601 View Code Duplication
class TextArea extends Field
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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

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

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
602
{
603
    /**
604
     * @param $parentObject
605
     * @param $animalObject
606
     */
607
    public function __construct($parentObject, $animalObject)
608
    {
609
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
610
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
611
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
612
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
613
        if ($parentObject->LookupTable == '1') {
614
            new Systemmessage('No lookuptable may be specified for userfield' . $this->fieldnumber);
615
        }
616
        if ($parentObject->ViewInAdvanced == '1') {
617
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be shown in advanced info');
618
        }
619
        if ($parentObject->ViewInPie == '1') {
620
            new Systemmessage('A Pie-chart cannot be specified for userfield' . $this->fieldnumber);
621
        }
622
    }
623
624
    /**
625
     * @return XoopsFormTextArea
626
     */
627
    public function editField()
628
    {
629
        $textarea = new XoopsFormTextArea('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value, $rows = 5, $cols = 50);
630
631
        return $textarea;
632
    }
633
634
    /**
635
     * @param string $name
636
     *
637
     * @return XoopsFormTextArea
638
     */
639
    public function newField($name = '')
640
    {
641
        $textarea = new XoopsFormTextArea('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue, $rows = 5, $cols = 50);
642
643
        return $textarea;
644
    }
645
646
    /**
647
     * @return string
648
     */
649
    public function getSearchString()
650
    {
651
        return '&amp;o=naam&amp;l=1';
652
    }
653
}
654
655
/**
656
 * Class DataSelect
657
 */
658
class DataSelect extends Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
659
{
660
    /**
661
     * @param $parentObject
662
     * @param $animalObject
663
     */
664
    public function __construct($parentObject, $animalObject)
665
    {
666
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
667
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
668
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
669
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
670
        if ($parentObject->lookuptable == '1') {
671
            new Systemmessage('No lookuptable may be specified for userfield' . $this->fieldnumber);
672
        }
673
        if ($parentObject->ViewInAdvanced == '1') {
674
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be shown in advanced info');
675
        }
676
        if ($parentObject->ViewInPie == '1') {
677
            new Systemmessage('A Pie-chart cannot be specified for userfield' . $this->fieldnumber);
678
        }
679
    }
680
681
    /**
682
     * @return XoopsFormTextDateSelect
683
     */
684
    public function editField()
685
    {
686
        //$textarea = new XoopsFormFile("<b>".$this->fieldname."</b>", $this->fieldname, $maxfilesize = 2000);
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
687
        $textarea = new XoopsFormTextDateSelect('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $size = 15, $this->value);
688
689
        return $textarea;
690
    }
691
692
    /**
693
     * @param string $name
694
     *
695
     * @return XoopsFormTextDateSelect
696
     */
697
    public function newField($name = '')
698
    {
699
        $textarea = new XoopsFormTextDateSelect('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $size = 15, $this->defaultvalue);
700
701
        return $textarea;
702
    }
703
704
    /**
705
     * @return string
706
     */
707
    public function getSearchString()
708
    {
709
        return '&amp;o=naam&amp;l=1';
710
    }
711
}
712
713
/**
714
 * Class UrlField
715
 */
716
class UrlField extends Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
717
{
718
    /**
719
     * @param $parentObject
720
     * @param $animalObject
721
     */
722
    public function __construct($parentObject, $animalObject)
723
    {
724
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
725
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
726
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
727
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
728
        $this->lookuptable  = $parentObject->lookuptable;
0 ignored issues
show
Bug introduced by
The property lookuptable 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...
729
        if ($this->lookuptable == '1') {
730
            new Systemmessage('No lookuptable may be specified for userfield' . $this->fieldnumber);
731
        }
732
        if ($parentObject->ViewInAdvanced == '1') {
733
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be shown in advanced info');
734
        }
735
        if ($parentObject->ViewInPie == '1') {
736
            new Systemmessage('A Pie-chart cannot be specified for userfield' . $this->fieldnumber);
737
        }
738
    }
739
740
    /**
741
     * @return XoopsFormText
742
     */
743
    public function editField()
744
    {
745
        $textbox = new XoopsFormText('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $size = 50, $maxsize = 255, $value = $this->value);
746
747
        return $textbox;
748
    }
749
750
    /**
751
     * @param string $name
752
     *
753
     * @return XoopsFormText
754
     */
755
    public function newField($name = '')
756
    {
757
        $textbox = new XoopsFormText('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $size = 50, $maxsize = 255, $value = $this->defaultvalue);
758
759
        return $textbox;
760
    }
761
762
    /**
763
     * @return XoopsFormLabel
764
     */
765
    public function viewField()
766
    {
767
        $view = new XoopsFormLabel($this->fieldname, '<a href="' . $this->value . '" target=\"_new\">' . $this->value . '</a>');
768
769
        return $view;
770
    }
771
772
    /**
773
     * @return string
774
     */
775
    public function showField()
776
    {
777
        return $this->fieldname . " : <a href=\"" . $this->value . "\" target=\"_new\">" . $this->value . '</a>';
778
    }
779
780
    /**
781
     * @return string
782
     */
783
    public function showValue()
784
    {
785
        return "<a href=\"" . $this->value . "\" target=\"_new\">" . $this->value . '</a>';
786
    }
787
788
    /**
789
     * @return string
790
     */
791
    public function getSearchString()
792
    {
793
        return '&amp;o=naam&amp;l=1';
794
    }
795
}
796
797
/**
798
 * Class Picture
799
 */
800
class Picture extends Field
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
801
{
802
    /**
803
     * @param $parentObject
804
     * @param $animalObject
805
     */
806
    public function __construct($parentObject, $animalObject)
807
    {
808
        $this->fieldnumber  = $parentObject->getId();
0 ignored issues
show
Bug introduced by
The property fieldnumber 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...
809
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname 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...
810
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
0 ignored issues
show
Bug introduced by
The property value 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...
811
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue 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...
812
        $this->lookuptable  = $parentObject->lookuptable;
0 ignored issues
show
Bug introduced by
The property lookuptable 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...
813
        if ($this->lookuptable == '1') {
814
            new Systemmessage('No lookuptable may be specified for userfield' . $this->fieldnumber);
815
        }
816
        if ($parentObject->ViewInAdvanced == '1') {
817
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be shown in advanced info');
818
        }
819
        if ($parentObject->ViewInPie == '1') {
820
            new Systemmessage('A Pie-chart cannot be specified for userfield' . $this->fieldnumber);
821
        }
822
        if ($parentObject->ViewInList == '1') {
823
            new Systemmessage('userfield' . $this->fieldnumber . ' cannot be included in listview');
824
        }
825
        if ($parentObject->HasSearch == '1') {
826
            new Systemmessage('Search cannot be defined for userfield' . $this->fieldnumber);
827
        }
828
    }
829
830
    /**
831
     * @return XoopsFormFile
832
     */
833 View Code Duplication
    public function editField()
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...
834
    {
835
        $picturefield = new XoopsFormFile($this->fieldname, 'user' . $this->fieldnumber, 1024000);
836
        $picturefield->setExtra("size ='50'");
837
838
        return $picturefield;
839
    }
840
841
    /**
842
     * @param string $name
843
     *
844
     * @return XoopsFormFile
845
     */
846 View Code Duplication
    public function newField($name = '')
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...
847
    {
848
        $picturefield = new XoopsFormFile($this->fieldname, $name . 'user' . $this->fieldnumber, 1024000);
849
        $picturefield->setExtra("size ='50'");
850
851
        return $picturefield;
852
    }
853
854
    /**
855
     * @return XoopsFormLabel
856
     */
857
    public function viewField()
858
    {
859
        $view = new XoopsFormLabel($this->fieldname, "<img src=\"assets/images/thumbnails/" . $this->value . "_400.jpeg\">");
860
861
        return $view;
862
    }
863
864
    /**
865
     * @return string
866
     */
867
    public function showField()
868
    {
869
        return "<img src=\"assets/images/thumbnails/" . $this->value . "_150.jpeg\">";
870
    }
871
872
    /**
873
     * @return string
874
     */
875
    public function showValue()
876
    {
877
        return "<img src=\"assets/images/thumbnails/" . $this->value . "_400.jpeg\">";
878
    }
879
}
880
881
/**
882
 * Class SISContext
883
 */
884
class SISContext
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
885
{
886
    private $contexts;
887
    private $depth;
888
889
    /**
890
     * SISContext constructor.
891
     */
892
    public function __construct()
893
    {
894
        $this->contexts = array();
895
        $this->depth    = 0;
896
    }
897
898
    /**
899
     * @param $url
900
     * @param $name
901
     */
902
    public function myGoto($url, $name)
903
    {
904
        $keys = array_keys($this->contexts);
905
        for ($i = 0; $i < $this->depth; ++$i) {
906
            if ($keys[$i] == $name) {
907
                $this->contexts[$name] = $url; // the url might be slightly different
908
                $this->depth           = $i + 1;
909
910
                for ($x = count($this->contexts); $x > $i + 1; $x--) {
911
                    array_pop($this->contexts);
912
                }
913
914
                return;
915
            }
916
        }
917
918
        $this->contexts[$name] = $url;
919
        $this->depth++;
920
    }
921
922
    /**
923
     * @return array
924
     */
925
    public function getAllContexts()
926
    {
927
        return $this->contexts;
928
    }
929
930
    /**
931
     * @return array
932
     */
933
    public function getAllContextNames()
934
    {
935
        return array_keys($this->contexts);
936
    }
937
}
938