waiting_get_plugin_info()   B
last analyzed

Complexity

Conditions 11
Paths 16

Size

Total Lines 63
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 43
nc 16
nop 2
dl 0
loc 63
rs 7.3166
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 declare(strict_types=1);
2
/*
3
 ------------------------------------------------------------------------
4
 XOOPS - PHP Content Management System
5
 Copyright (c) 2000 XOOPS.org
6
 <https://xoops.org>
7
 ------------------------------------------------------------------------
8
 This program is free software; you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation; either version 2 of the License, or
11
 (at your option) any later version.
12
13
 You may not change or alter any portion of this comment or credits
14
 of supporting developers from this source code or any supporting
15
 source code which is considered copyrighted (c) material of the
16
 original comment or credit authors.
17
18
 This program is distributed in the hope that it will be useful,
19
 but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 GNU General Public License for more details.
22
23
 You should have received a copy of the GNU General Public License
24
 along with this program; if not, write to the Free Software
25
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
26
 ------------------------------------------------------------------------
27
 */
28
29
/**
30
 * Module: Waiting
31
 *
32
 * @param mixed $dirname
33
 * @param mixed $language
34
 * @author          XOOPS Module Development Team
35
 * @copyright       {@link https://xoops.org 2001-2016 XOOPS Project}
36
 * @license         {@link https://www.fsf.org/copyleft/gpl.html GNU public license}
37
 * @link            https://xoops.org XOOPS
38
 * @category        Module
39
 */
40
41
/**
42
 * @param         $dirname
43
 * @param string  $language
44
 * @return array
45
 */
46
function waiting_get_plugin_info($dirname, $language = 'english')
47
{
48
    // get $mytrustdirname for D3 modules
49
    $mytrustdirname = '';
50
    if (defined('XOOPS_TRUST_PATH') && is_file(XOOPS_ROOT_PATH . '/modules/' . $dirname . '/mytrustdirname.php')) {
51
        @require XOOPS_ROOT_PATH . '/modules/' . $dirname . '/mytrustdirname.php';
52
    }
53
54
    $module_plugin_file   = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/include/waiting.plugin.php';
55
    $d3module_plugin_file = XOOPS_TRUST_PATH . '/modules/' . $mytrustdirname . '/include/waiting.plugin.php';
56
    $builtin_plugin_file  = XOOPS_ROOT_PATH . '/modules/waiting/plugins/' . $dirname . '.php';
57
58
    if (file_exists($module_plugin_file)) {
59
        // module side (1st priority)
60
        $lang_files    = [
61
            XOOPS_ROOT_PATH . "/modules/$dirname/language/$language/waiting.php",
62
            XOOPS_ROOT_PATH . "/modules/$dirname/language/english/waiting.php",
63
        ];
64
        $langfile_path = '';
65
        foreach ($lang_files as $lang_file) {
66
            if (file_exists($lang_file)) {
67
                $langfile_path = $lang_file;
68
                break;
69
            }
70
        }
71
        $ret = [
72
            'plugin_path'   => $module_plugin_file,
73
            'langfile_path' => $langfile_path,
74
            'func'          => 'b_waiting_' . $dirname,
75
            'type'          => 'module',
76
        ];
77
    } elseif (!empty($mytrustdirname) && file_exists($d3module_plugin_file)) {
0 ignored issues
show
introduced by
The condition empty($mytrustdirname) is always true.
Loading history...
78
        // D3 module's plugin under xoops_trust_path (2nd priority)
79
        $lang_files    = [
80
            XOOPS_TRUST_PATH . "/modules/$mytrustdirname/language/$language/waiting.php",
81
            XOOPS_TRUST_PATH . "/modules/$mytrustdirname/language/english/waiting.php",
82
        ];
83
        $langfile_path = '';
84
        foreach ($lang_files as $lang_file) {
85
            if (file_exists($lang_file)) {
86
                $langfile_path = $lang_file;
87
                break;
88
            }
89
        }
90
        $ret = [
91
            'plugin_path'   => $d3module_plugin_file,
92
            'langfile_path' => $langfile_path,
93
            'func'          => 'b_waiting_' . $mytrustdirname,
94
            'type'          => 'module (D3)',
95
        ];
96
    } elseif (file_exists($builtin_plugin_file)) {
97
        // built-in plugin under modules/waiting (3rd priority)
98
        $ret = [
99
            'plugin_path'   => $builtin_plugin_file,
100
            'langfile_path' => '',
101
            'func'          => 'b_waiting_' . $dirname,
102
            'type'          => 'Waiting',
103
        ];
104
    } else {
105
        $ret = [];
106
    }
107
108
    return $ret;
109
}
110