Passed
Push — master ( 22887c...b0a7cb )
by Michael
04:05 queued 02:12
created

Blanguage::prepareVars()   C

Complexity

Conditions 17
Paths 28

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 17
eloc 27
nc 28
nop 0
dl 0
loc 33
rs 5.2166
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace XoopsModules\Xlanguage;
4
5
/**
6
 * xLanguage module (eXtensible Language Management For XOOPS)
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      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
17
 * @package      xlanguage
18
 * @since        2.0
19
 * @author       D.J.(phppp) [email protected]
20
 **/
21
22
use XoopsModules\Xlanguage;
23
24
//require(XOOPS_ROOT_PATH."/class/xoopslists.php");
25
//require(XOOPS_ROOT_PATH.'/modules/xlanguage/include/vars.php');
26
//require(XOOPS_ROOT_PATH.'/modules/xlanguage/class/Utility.php');
27
28
/**
29
 * Class Blanguage
30
 */
31
class Blanguage extends \XoopsObject
32
{
33
    public $isBase = false;
34
    public $db;
35
    public $table;
36
37
    /**
38
     * Blanguage constructor.
39
     * @param bool $isBase
40
     */
41
    public function __construct($isBase = false)
42
    {
43
        $this->isBase = $isBase;
44
        $this->db    = \XoopsDatabaseFactory::getDatabaseConnection();
45
        $this->table = $this->db->prefix('xlanguage_base');
46
        $this->initVar('lang_id', XOBJ_DTYPE_INT);
47
        $this->initVar('weight', XOBJ_DTYPE_INT);
48
        $this->initVar('lang_name', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('lang_desc', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('lang_code', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('lang_charset', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('lang_image', XOBJ_DTYPE_TXTBOX);
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function prepareVars()
59
    {
60
        foreach ($this->vars as $k => $v) {
61
            $cleanv = $this->cleanVars[$k];
62
            switch ($v['data_type']) {
63
                case XOBJ_DTYPE_TXTBOX:
64
                case XOBJ_DTYPE_TXTAREA:
65
                case XOBJ_DTYPE_SOURCE:
66
                case XOBJ_DTYPE_EMAIL:
67
                    $cleanv = $v['changed'] ? $cleanv : '';
68
                    if (!isset($v['not_gpc']) || !$v['not_gpc']) {
69
                        $cleanv = $this->db->quoteString($cleanv);
70
                    }
71
                    break;
72
                case XOBJ_DTYPE_INT:
73
                    $cleanv = $v['changed'] ? (int)$cleanv : 0;
74
                    break;
75
                case XOBJ_DTYPE_ARRAY:
76
                    $cleanv = $v['changed'] ? $cleanv : serialize([]);
77
                    break;
78
                case XOBJ_DTYPE_STIME:
79
                case XOBJ_DTYPE_MTIME:
80
                case XOBJ_DTYPE_LTIME:
81
                    $cleanv = $v['changed'] ? $cleanv : 0;
82
                    break;
83
                default:
84
                    break;
85
            }
86
            $this->cleanVars[$k] = &$cleanv;
87
            unset($cleanv);
88
        }
89
90
        return true;
91
    }
92
93
    public function setBase()
94
    {
95
        $this->isBase = true;
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public function hasBase()
102
    {
103
        return $this->isBase;
104
    }
105
}
106