Requests::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 16
rs 9.9332
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Songlist;
4
5
use XoopsFormText;
6
use XoopsObject;
7
8
require_once \dirname(__DIR__) . '/include/songlist.object.php';
9
// require_once \dirname(__DIR__) . '/include/songlist.form.php';
10
use  XoopsModules\Songlist\Form\FormController;
11
12
/**
13
 * Class Requests
14
 */
15
class Requests extends XoopsObject
16
{
17
    /**
18
     * Requests constructor.
19
     * @param null $fid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fid is correct as it would always require null to be passed?
Loading history...
20
     */
21
    public function __construct($fid = null)
0 ignored issues
show
Unused Code introduced by
The parameter $fid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
    public function __construct(/** @scrutinizer ignore-unused */ $fid = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        $this->initVar('rid', \XOBJ_DTYPE_INT, 0, false);
24
        $this->initVar('aid', \XOBJ_DTYPE_INT, 0, false);
25
        $this->initVar('artist', \XOBJ_DTYPE_TXTBOX, null, false, 128);
26
        $this->initVar('album', \XOBJ_DTYPE_TXTBOX, null, false, 128);
27
        $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false, 128);
28
        $this->initVar('lyrics', \XOBJ_DTYPE_OTHER, null, false);
29
        $this->initVar('uid', \XOBJ_DTYPE_INT, 0, false);
30
        $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128);
31
        $this->initVar('email', \XOBJ_DTYPE_TXTBOX, null, false, 255);
32
        $this->initVar('songid', \XOBJ_DTYPE_TXTBOX, null, false, 32);
33
        $this->initVar('sid', \XOBJ_DTYPE_INT, 0, false);
34
        $this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
35
        $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
36
    }
37
38
    /**
39
     * @param bool $as_array
40
     * @return array|string
41
     */
42
    public function getForm($as_array = false)
43
    {
44
        return FormController::getFormRequests($this, $as_array);
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function toArray(): array
51
    {
52
        $ret            = parent::toArray();
53
        $form           = $this->getForm(true);
54
        $form['songid'] = new XoopsFormText('', $this->getVar('rid') . '[songid]', 11, 32);
55
        foreach ($form as $key => $element) {
56
            $ret['form'][$key] = $element->render();
57
        }
58
        foreach (['created', 'updated'] as $key) {
59
            if ($this->getVar($key) > 0) {
60
                $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
61
                $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
62
            }
63
        }
64
65
        return $ret;
66
    }
67
}
68