Passed
Pull Request — master (#18)
by Michael
02:01
created

Utility::getSkinInfo()   F

Complexity

Conditions 14
Paths 512

Size

Total Lines 60
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 34
nc 512
nop 3
dl 0
loc 60
rs 2.7777
c 0
b 0
f 0

How to fix   Long Method    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 namespace XoopsModules\Mymenus;
2
3
use Xmf\Request;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use XoopsModules\Mymenus;
5
use XoopsModules\Mymenus\Common;
6
7
/**
8
 * Class Utility
9
 */
10
class Utility
11
{
12
    use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
13
14
    use Common\ServerStats; // getServerStats Trait
15
16
    use Common\FilesManagement; // Files Management Trait
17
18
    //--------------- Custom module methods -----------------------------
19
20
    /**
21
     * @param string $moduleSkin
22
     * @param bool   $useThemeSkin
23
     * @param string $themeSkin
24
     * @return array
25
     */
26
    public static function getSkinInfo($moduleSkin = 'default', $useThemeSkin = false, $themeSkin = '')
27
    {
28
        //    require __DIR__ . '/common.php';
29
        /** @var \XoopsModules\Mymenus\Helper $helper */
30
        $helper = \XoopsModules\Mymenus\Helper::getInstance();
31
        $error   = false;
32
        if ($useThemeSkin) {
33
            $path = 'themes/' . $GLOBALS['xoopsConfig']['theme_set'] . '/menu';
34
            if (!file_exists($GLOBALS['xoops']->path("{$path}/skin_version.php"))) {
35
                $path = 'themes/' . $GLOBALS['xoopsConfig']['theme_set'] . "/modules/{$helper->getDirname()}/skins/{$themeSkin}";
36
                if (!file_exists($GLOBALS['xoops']->path("{$path}/skin_version.php"))) {
37
                    $error = true;
38
                }
39
            }
40
        }
41
42
        if ($error || !$useThemeSkin) {
43
            $path = "modules/{$helper->getDirname()}/skins/{$moduleSkin}";
44
        }
45
46
        $file = $GLOBALS['xoops']->path("{$path}/skin_version.php");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $path does not seem to be defined for all execution paths leading up to this point.
Loading history...
47
        $info = [];
48
49
        if (file_exists($file)) {
50
            require $file;
51
            $info = $skinVersion;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $skinVersion seems to be never defined.
Loading history...
52
        }
53
54
        $info['path'] = $GLOBALS['xoops']->path($path);
55
        $info['url']  = $GLOBALS['xoops']->url($path);
56
57
        if (!isset($info['template'])) {
58
            $info['template'] = $GLOBALS['xoops']->path("modules/{$helper->getDirname()}/templates/static/blocks/mymenus_block.tpl");
59
        } else {
60
            $info['template'] = $GLOBALS['xoops']->path("{$path}/" . $info['template']);
61
        }
62
63
        if (!isset($info['prefix'])) {
64
            $info['prefix'] = $moduleSkin;
65
        }
66
67
        if (isset($info['css'])) {
68
            $info['css'] = (array)$info['css'];
69
            foreach ($info['css'] as $key => $value) {
70
                $info['css'][$key] = $GLOBALS['xoops']->url("{$path}/{$value}");
71
            }
72
        }
73
74
        if (isset($info['js'])) {
75
            $info['js'] = (array)$info['js'];
76
            foreach ($info['js'] as $key => $value) {
77
                $info['js'][$key] = $GLOBALS['xoops']->url("{$path}/{$value}");
78
            }
79
        }
80
81
        if (!isset($info['config'])) {
82
            $info['config'] = [];
83
        }
84
85
        return $info;
86
    }
87
}
88