Completed
Push — master ( 37052f...d19713 )
by Michael
02:03
created

InstructionUtility   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getItemIds() 0 17 4
A getWysiwygForm() 0 15 1
B cleanVars() 0 16 6
1
<?php
2
3
use Xmf\Request;
4
5
require_once __DIR__ . '/common/traitversionchecks.php';
6
require_once __DIR__ . '/common/traitserverstats.php';
7
require_once __DIR__ . '/common/traitfilesmgmt.php';
8
9
require_once __DIR__ . '/../include/common.php';
10
11
/**
12
 * Class InstructionUtility
13
 */
14
class InstructionUtility
15
{
16
    use VersionChecks; //checkVerXoops, checkVerPhp Traits
17
18
    use ServerStats; // getServerStats Trait
19
20
    use FilesManagement; // Files Management Trait
21
22
    // Права
23
    public static function getItemIds($permtype = 'instruction_view')
24
    {
25
        //global $xoopsUser;
26
        static $permissions = [];
27
        // Если есть в статике
28
        if (is_array($permissions) && array_key_exists($permtype, $permissions)) {
29
            return $permissions[$permtype];
30
        }
31
        // Находим из базы
32
        $moduleHandler          = xoops_getHandler('module');
33
        $instrModule            = $moduleHandler->getByDirname('instruction');
34
        $groups                 = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
35
        $gpermHandler           = xoops_getHandler('groupperm');
36
        $categories             = $gpermHandler->getItemIds($permtype, $groups, $instrModule->getVar('mid'));
37
        $permissions[$permtype] = $categories;
38
        return $categories;
39
    }
40
41
    // Редактор
42
    public static function getWysiwygForm($caption, $name, $value = '')
43
    {
44
        $editor                   = false;
0 ignored issues
show
Unused Code introduced by
$editor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
        $editor_configs           = [];
46
        $editor_configs['name']   = $name;
47
        $editor_configs['value']  = $value;
48
        $editor_configs['rows']   = 35;
49
        $editor_configs['cols']   = 60;
50
        $editor_configs['width']  = '100%';
51
        $editor_configs['height'] = '350px';
52
        $editor_configs['editor'] = strtolower(xoops_getModuleOption('form_options', 'instruction'));
53
54
        $editor = new XoopsFormEditor($caption, $name, $editor_configs);
55
        return $editor;
56
    }
57
58
    // Получение значения переменной, переданной через GET или POST запрос
59
    public static function cleanVars(&$global, $key, $default = '', $type = 'int')
60
    {
61
        switch ($type) {
62
            case 'string':
63
                $ret = isset($global[$key]) ? $global[$key] : $default;
64
                break;
65
            case 'int':
66
            default:
67
                $ret = isset($global[$key]) ? (int)$global[$key] : (int)$default;
68
                break;
69
        }
70
        if (false === $ret) {
71
            return $default;
72
        }
73
        return $ret;
74
    }
75
}
76