Rld   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
B cleanVarsForDB() 0 19 9
A getInstance() 0 9 2
A __construct() 0 10 1
1
<?php
2
3
namespace XoopsModules\Xooghost;
4
5
/**
6
 * Xooghost module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
use Xoops\Core\Request;
22
23
/**
24
 * Class XooghostRld
25
 */
26
class Rld extends \XoopsObject
27
{
28
    // constructor
29
30
    public function __construct()
31
    {
32
        $this->initVar('xooghost_rld_id', XOBJ_DTYPE_INT, 0, true, 5);
33
        $this->initVar('xooghost_rld_page', XOBJ_DTYPE_INT, 1, false, 5);
34
        $this->initVar('xooghost_rld_uid', XOBJ_DTYPE_INT, 0, true, 5);
35
        $this->initVar('xooghost_rld_time', XOBJ_DTYPE_INT, time(), true, 10);
36
        $this->initVar('xooghost_rld_ip', XOBJ_DTYPE_TXTBOX, '0.0.0.0', true, 15);
37
        $this->initVar('xooghost_rld_rates', XOBJ_DTYPE_INT, 0, true, 5);
38
        $this->initVar('xooghost_rld_like', XOBJ_DTYPE_INT, 0, true, 1);
39
        $this->initVar('xooghost_rld_dislike', XOBJ_DTYPE_INT, 0, true, 1);
40
    }
41
42
    /**
43
     * @return mixed
44
     */
45
    public static function getInstance()
46
    {
47
        static $instance;
48
        if (!isset($instance)) {
49
            $class = __CLASS__;
50
            $instance = new $class();
51
        }
52
53
        return $instance;
54
    }
55
56
    public function cleanVarsForDB()
57
    {
58
        $system = \System::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $system is dead and can be removed.
Loading history...
59
        foreach (parent::getValues() as $k => $v) {
60
            if ('dohtml' !== $k) {
61
                if (XOBJ_DTYPE_STIME == $this->vars[$k]['data_type'] || XOBJ_DTYPE_MTIME == $this->vars[$k]['data_type'] || XOBJ_DTYPE_LTIME == $this->vars[$k]['data_type']) {
62
                    //                    $value = $system->cleanVars($_POST[$k], 'date', date('Y-m-d'), 'date') + $system->cleanVars($_POST[$k], 'time', date('u'), 'int');
63
                    //TODO should we use here getString??
64
                    $value = Request::getArray('date', date('Y-m-d'), 'POST')[$k] + Request::getArray('time', date('u'), 'POST')[$k];
65
                    $this->setVar($k, isset($_POST[$k]) ? $value : $v);
66
                } elseif (XOBJ_DTYPE_INT == $this->vars[$k]['data_type']) {
67
                    $value = Request::getInt($k, $v, 'POST'); //$system->cleanVars($_POST, $k, $v, 'int');
68
                    $this->setVar($k, $value);
69
                } elseif (XOBJ_DTYPE_ARRAY == $this->vars[$k]['data_type']) {
70
                    $value = Request::getArray($k, $v, 'POST'); // $system->cleanVars($_POST, $k, $v, 'array');
71
                    $this->setVar($k, $value);
72
                } else {
73
                    $value = Request::getString($k, $v, 'POST'); //$system->cleanVars($_POST, $k, $v, 'string');
74
                    $this->setVar($k, $value);
75
                }
76
            }
77
        }
78
    }
79
}
80