Completed
Push — master ( 382ca7...8138ff )
by Michael
02:05
created

Utility::cleanVars()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 12
nop 4
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php namespace Xoopsmodules\instruction;
2
3
use Xmf\Request;
4
use Xoopsmodules\instruction\common;
5
6
require_once __DIR__ . '/common/VersionChecks.php';
7
require_once __DIR__ . '/common/ServerStats.php';
8
require_once __DIR__ . '/common/FilesManagement.php';
9
10
require_once __DIR__ . '/../include/common.php';
11
12
/**
13
 * Class Utility
14
 */
15
class Utility
16
{
17
    use common\VersionChecks; //checkVerXoops, checkVerPhp Traits
18
19
    use common\ServerStats; // getServerStats Trait
20
21
    use common\FilesManagement; // Files Management Trait
22
23
    // Права
24
    /**
25
     * @param string $permtype
26
     * @return mixed
27
     */
28
    public static function getItemIds($permtype = 'instruction_view')
29
    {
30
        //global $xoopsUser;
31
        static $permissions = [];
32
        // Если есть в статике
33
        if (is_array($permissions) && array_key_exists($permtype, $permissions)) {
34
            return $permissions[$permtype];
35
        }
36
        // Находим из базы
37
        $moduleHandler          = xoops_getHandler('module');
38
        $instrModule            = $moduleHandler->getByDirname('instruction');
39
        $groups                 = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40
        $gpermHandler           = xoops_getHandler('groupperm');
41
        $categories             = $gpermHandler->getItemIds($permtype, $groups, $instrModule->getVar('mid'));
42
        $permissions[$permtype] = $categories;
43
        return $categories;
44
    }
45
46
    // Редактор
47
48
    /**
49
     * @param        $caption
50
     * @param        $name
51
     * @param string $value
52
     * @return bool|\XoopsFormEditor
53
     */
54
    public static function getWysiwygForm($caption, $name, $value = '')
55
    {
56
        $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...
57
        $editor_configs           = [];
58
        $editor_configs['name']   = $name;
59
        $editor_configs['value']  = $value;
60
        $editor_configs['rows']   = 35;
61
        $editor_configs['cols']   = 60;
62
        $editor_configs['width']  = '100%';
63
        $editor_configs['height'] = '350px';
64
        $editor_configs['editor'] = strtolower(xoops_getModuleOption('form_options', 'instruction'));
65
66
        $editor = new \XoopsFormEditor($caption, $name, $editor_configs);
67
        return $editor;
68
    }
69
}
70