Completed
Branch master (9dda00)
by Michael
04:54 queued 02:33
created

functions.time.php ➔ newbbSinceSelectBox()   C

Complexity

Conditions 10
Paths 13

Size

Total Lines 58
Code Lines 38

Duplication

Lines 12
Ratio 20.69 %

Importance

Changes 0
Metric Value
cc 10
eloc 38
nc 13
nop 1
dl 12
loc 58
rs 6.6515
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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * NewBB 5.0x,  the forum module for XOOPS project
4
 *
5
 * @copyright      XOOPS Project (http://xoops.org)
6
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
7
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since          4.00
9
 * @package        module::newbb
10
 */
11
12
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
14
defined('NEWBB_FUNCTIONS_INI') || include_once __DIR__ . '/functions.ini.php';
15
define('NEWBB_FUNCTIONS_TIME_LOADED', true);
16
17
if (!defined('NEWBB_FUNCTIONS_TIME')) {
18
    define('NEWBB_FUNCTIONS_TIME', 1);
19
20
    /**
21
     * Function to convert UNIX time to formatted time string
22
     * @param         $time
23
     * @param  string $format
24
     * @param  string $timeoffset
25
     * @return string
26
     */
27
    function newbbFormatTimestamp($time, $format = 'c', $timeoffset = '')
28
    {
29
        xoops_loadLanguage('locale');
30
        $newbbConfig = newbbLoadConfig();
31
32
        $format = strtolower($format);
33
        if ($format === 'reg' || $format === '') {
34
            $format = 'c';
35
        }
36
        if (($format === 'custom' || $format === 'c') && !empty($newbbConfig['formatTimestamp_custom'])) {
37
            $format = $newbbConfig['formatTimestamp_custom'];
38
        }
39
40
        return XoopsLocal::formatTimestamp($time, $format, $timeoffset);
41
    }
42
43
    /**
44
     * @param  int $selected
45
     * @return string
46
     */
47
    function newbbSinceSelectBox($selected = 100)
48
    {
49
        $newbbConfig = newbbLoadConfig();
50
        // irmtfan - new method to get user inputs
51
        preg_match_all('/-?\d+/', $newbbConfig['since_options'], $match);
52
        $select_array = array_unique($match[0]);
53
        //$select_array = explode(',', $newbbConfig['since_options']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
        //$select_array = array_map('trim', $select_array);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        // irmtfan - if the array is empty do not show selection box
56
        if (!(bool)$select_array) {
57
            $since = $newbbConfig['since_default'];
58
            switch ($since) {
59
                case 0:
60
                    $forum_since = _MD_NEWBB_BEGINNING;
61
                    break;
62
                case 365:
63
                    $forum_since = _MD_NEWBB_THELASTYEAR;
64
                    break;
65 View Code Duplication
                default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
                    if ($since > 0) {
67
                        $forum_since = sprintf(_MD_NEWBB_FROMLASTDAYS, $since);
68
                    } else {
69
                        $forum_since = sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since));
70
                    }
71
            }
72
73
            return $forum_since;
74
        }
75
        $forum_selection_since = '<select class="form-control" name="since" id="since">';
76
        // irmtfan no option when no selected value
77
        $forum_selection_since .= '<option value="">--------</option>';
78
        foreach ($select_array as $since) {
79
            $forum_selection_since .= '<option value="' . $since . '"' . (($selected == $since) ? ' selected="selected"' : '') . '>';
80
            // START irmtfan functional since 0 and 365
81
            switch ($since) {
82
                case 0:
83
                    $forum_selection_since .= _MD_NEWBB_BEGINNING;
84
                    break;
85
                case 365:
86
                    $forum_selection_since .= _MD_NEWBB_THELASTYEAR;
87
                    break;
88 View Code Duplication
                default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
                    if ($since > 0) {
90
                        $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTDAYS, $since);
91
                    } else {
92
                        $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since));
93
                    }
94
            }
95
            // END irmtfan functional since 0 and 365
96
            $forum_selection_since .= '</option>';
97
        }
98
        // irmtfan remove hardcodes
99
        //$forum_selection_since .= '<option value="365"'.(($selected === 365) ? ' selected="selected"' : '').'>'._MD_NEWBB_THELASTYEAR.'</option>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
100
        //$forum_selection_since .= '<option value="0"'.(($selected === 0) ? ' selected="selected"' : '').'>'._MD_NEWBB_BEGINNING.'</option>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
        $forum_selection_since .= '</select>';
102
103
        return $forum_selection_since;
104
    }
105
106
    /**
107
     * @param  int $since
108
     * @return int
109
     */
110
    function newbbGetSinceTime($since = 100)
111
    {
112
        // irmtfan bad coding
113
        //if ($since==1000) return 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
114
        if ($since > 0) {
115
            return (int)$since * 24 * 3600;
116
        } else {
117
            return (int)abs($since) * 3600;
118
        }
119
    }
120
}
121