Extras::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Songlist;
4
5
/**
6
 * Class Extras
7
 */
8
class Extras extends \XoopsObject
9
{
10
    public $handler;
11
12
    /**
13
     * Extras constructor.
14
     * @param $fields
15
     */
16
    public function __construct($fields)
17
    {
18
        $this->initVar('sid', \XOBJ_DTYPE_INT, null, true);
19
        $this->init($fields);
20
    }
21
22
    /**
23
     * Initiate variables
24
     * @param array $fields field information array of {@link \XoopsObjectsField} objects
25
     */
26
    public function init($fields): void
27
    {
28
        if ($fields && \is_array($fields)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $fields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
29
            foreach (\array_keys($fields) as $key) {
30
                $this->initVar($key, $fields[$key]->getVar('field_valuetype'), $fields[$key]->getVar('field_default', 'n'), $fields[$key]->getVar('field_required'), $fields[$key]->getVar('field_maxlength'));
31
            }
32
        }
33
    }
34
}
35