Passed
Push — master ( 74af7c...7f0364 )
by Michael
02:20
created

membersonline_edit()   F

Complexity

Conditions 13
Paths 4096

Size

Total Lines 71
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 13
eloc 51
c 2
b 0
f 0
nc 4096
nop 1
dl 0
loc 71
rs 2.45

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
2
//  Author: SMD & Trabis
3
//  URL: http://www.xoopsmalaysia.org  & http://www.xuups.com
4
//  E-Mail: [email protected]  & [email protected]
5
6
if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
7
8
function show_membersonline_block($options) {
9
    global $xoopsConfig, $xoopsUser, $xoopsModule, $xoopsDB, $_SERVER;
10
11
    /* @var XoopsOnlineHandler $online_handler */
12
    $online_handler = xoops_getHandler('online');
13
    // set gc probabillity to 10% for now..
14
    if (mt_rand(1, 100) < 11) {
15
        $online_handler->gc(300);
16
    }
17
    if (is_object($xoopsUser)) {
18
        $uid   = $xoopsUser->getVar('uid');
19
		$name = $xoopsUser->getVar('name');
20
		if ($options[4]=='1' && $name!='')
21
		  {
22
        $uname = $xoopsUser->getVar('name');
23
		  }
24
		else {
25
		$uname = $xoopsUser->getVar('uname');
26
		}			
27
28
	} else {
29
        $uid   = 0;
30
        $uname = '';	
31
   	    $name = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
32
    }
33
    $requestIp = \Xmf\IPAddress::fromRequest()->asReadable();
34
    $requestIp = (false === $requestIp) ? '0.0.0.0' : $requestIp;
0 ignored issues
show
introduced by
The condition false === $requestIp is always false.
Loading history...
35
    if (is_object($xoopsModule)) {
36
        $online_handler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), $requestIp);
37
    } else {
38
        $online_handler->write($uid, $uname, time(), 0, $requestIp);
39
    }
40
    $onlines = $online_handler->getAll();
41
    if (!empty($onlines)) {
42
        $total   = count($onlines);
43
		$block   = array();
44
        $guests  = 0;
45
        $membersname = '';
46
		$membersavatar = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $membersavatar is dead and can be removed.
Loading history...
47
		$avatar = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $avatar is dead and can be removed.
Loading history...
48
		$uid = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $uid is dead and can be removed.
Loading history...
49
        $name = '';
50
        
51
		for ($i = 0; $i < $total; ++$i) {
52
			  if ($onlines[$i]['online_uid'] == 0) {
53
                    $onlineUsers[$i]['user'] = '';
54
                } else {
55
                    $onlineUsers[$i]['user'] =  new XoopsUser($onlines[$i]['online_uid']);
56
                }
57
			 if (is_object($onlineUsers[$i]['user'])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $onlineUsers does not seem to be defined for all execution paths leading up to this point.
Loading history...
58
					$block['avatar'] = $onlineUsers[$i]['user']->getVar('user_avatar');
59
                    $block['uid']= $onlineUsers[$i]['user']->getVar('uid');
60
					
61
					$realname     = $onlineUsers[$i]['user']->getVar('name');
62
					if ('1' == $options[5] && '' != $realname) {
63
					$block['name'] = $onlineUsers[$i]['user']->getVar('name');
64
					} else {
65
					$block['name'] = $onlineUsers[$i]['user']->getVar('uname');
66
					}
67
					}
68
				
69
            if ($onlines[$i]['online_uid'] > 0) {
70
				$membersname .= '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>, ';
71
            } else {
72
                ++$guests;
73
            }
74
        }
75
        $block['online_total'] = sprintf(_ONLINEPHRASE, $total);
76
        if (is_object($xoopsModule)) {
77
            $mytotal = $online_handler->getCount(new Criteria('online_module', $xoopsModule->getVar('mid')));
78
            $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')';
79
        }
80
        // Membership Statistic
81
        $member_handler =xoops_gethandler('member');
82
        $today = formatTimestamp(time());
0 ignored issues
show
Unused Code introduced by
The assignment to $today is dead and can be removed.
Loading history...
83
        $level_criteria = new Criteria('level', 0, '>');
84
        $criteria = new CriteriaCompo($level_criteria);
85
        $criteria24 = new CriteriaCompo($level_criteria);
86
        $criteria48 = new CriteriaCompo($level_criteria);
87
        $total_active_users = $member_handler->getUserCount($level_criteria);
0 ignored issues
show
Bug introduced by
The method getUserCount() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
        /** @scrutinizer ignore-call */ 
88
        $total_active_users = $member_handler->getUserCount($level_criteria);
Loading history...
88
        //Fixing stats for last 24 and 48 hours
89
        $users_reg_24 = $member_handler->getUserCount($criteria24->add(new Criteria('user_regdate', (mktime(0,0,0)-(24*3600)), '>=')),'AND');
90
        $users_reg_48 = $member_handler->getUserCount($criteria48->add(new Criteria('user_regdate', (mktime(0,0,0)-(48*3600)), '>=')),'AND');
91
        $limit = 1;
92
        $criteria->setOrder('DESC');
93
        $criteria->setSort('user_regdate');
94
        $criteria->setLimit($limit);
95
  
96
		// data
97
        $block['activeusers'] = $total_active_users;
98
        $block['todayreg'] = $users_reg_24;
99
        $block['yesterdayreg'] = $users_reg_48 - $users_reg_24;
100
		$block['total_online']	= sprintf(_MB_XOOPSMEMBERS_TOTALONLINE, $total); 
101
		$block['online_members'] = $total - $guests  . ' ' . _MB_XOOPSMEMBERS_MEMBERS . ' ' . _MB_XOOPSMEMBERS_CURRENTONLINE;
102
        $block['online_guests']  = $guests . ' ' . _MB_XOOPSMEMBERS_GUESTS . ' ' . _MB_XOOPSMEMBERS_AND;
103
			
104
  	
105
		$block['showonlinemember'] = $options[0];
106
	    $block['showonlinename'] = $options[1];
107
		$block['showonlineavatar'] = $options[2];
108
		$block['showonlinepopup'] = $options[3];
109
	    $block['showtotalonline'] = $options[4];
110
		$block['userealname'] = $options[5];
111
		$block['memberdisplay'] = $options[6];
112
113
        return $block;
114
	} else {
115
		return false;
116
	}
117
}
118
119
function membersonline_edit($options) {
120
	
121
	$form = _MB_XOOPSMEMBERS_SHOWONLINEMEMBER."&nbsp;";
122
	if ( $options[0] == 1 ) {
123
		$chk = " checked='checked'";
124
	}
125
	$form .= "<input type='radio' name='options[0]' value='1'".$chk." />&nbsp;"._YES."";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $chk does not seem to be defined for all execution paths leading up to this point.
Loading history...
126
	$chk = "";
127
	if ( $options[0] == 0 ) {
128
		$chk = " checked='checked'";
129
	}
130
	$form .= "&nbsp;<input type='radio' name='options[0]' value='0'".$chk." />"._NO."<br />";
131
132
	$form .= _MB_XOOPSMEMBERS_SHOWONLINENAME."&nbsp;";
133
	if ( $options[1] == 1 ) {
134
		$chk = " checked='checked'";
135
	}
136
	$form .= "<input type='radio' name='options[1]' value='1'".$chk." />&nbsp;"._YES."";
137
	$chk = "";
138
	if ( $options[1] == 0 ) {
139
		$chk = " checked='checked'";
140
	}
141
	$form .= "&nbsp;<input type='radio' name='options[1]' value='0'".$chk." />"._NO."<br />";
142
143
	$form .= _MB_XOOPSMEMBERS_SHOWONLINEAVATAR."&nbsp;";
144
	if ( $options[2] == 1 ) {
145
		$chk = " checked='checked'";
146
	}
147
	$form .= "<input type='radio' name='options[2]' value='1'".$chk." />&nbsp;"._YES."";
148
	$chk = "";
149
	if ( $options[2] == 0 ) {
150
		$chk = " checked='checked'";
151
	}
152
	$form .= "&nbsp;<input type='radio' name='options[2]' value='0'".$chk." />"._NO."<br />";
153
154
	$form .= _MB_XOOPSMEMBERS_SHOWONLINEPOPUP."&nbsp;";
155
	if ( $options[3] == 1 ) {
156
		$chk = " checked='checked'";
157
	}
158
	$form .= "<input type='radio' name='options[3]' value='1'".$chk." />&nbsp;"._YES."";
159
	$chk = "";
160
	if ( $options[3] == 0 ) {
161
		$chk = " checked='checked'";
162
	}
163
	$form .= "&nbsp;<input type='radio' name='options[3]' value='0'".$chk." />"._NO."<br />";
164
165
	$form .= _MB_XOOPSMEMBERS_SHOWTOTALONLINE."&nbsp;";
166
	if ( $options[4] == 1 ) {
167
		$chk = " checked='checked'";
168
	}
169
	$form .= "<input type='radio' name='options[4]' value='1'".$chk." />&nbsp;"._YES."";
170
	$chk = "";
171
	if ( $options[4] == 0 ) {
172
		$chk = " checked='checked'";
173
	}
174
	$form .= "&nbsp;<input type='radio' name='options[4]' value='0'".$chk." />"._NO."<br />";
175
176
	$form .= _MB_XOOPSMEMBERS_USEREALNAME."&nbsp;";
177
	if ( $options[5] == 1 ) {
178
		$chk = " checked='checked'";
179
	}
180
	$form .= "<input type='radio' name='options[5]' value='1'".$chk." />&nbsp;"._YES."";
181
	$chk = "";
182
	if ( $options[5] == 0 ) {
183
		$chk = " checked='checked'";
184
	}
185
	$form .= "&nbsp;<input type='radio' name='options[5]' value='0'".$chk." />"._NO."<br />";
186
	
187
	$form .= _MB_XOOPSMEMBERS_MEMBERDISPLAY."&nbsp;";
188
	$form .= "<input type='text' name='options[6]' value='".$options[6]."'/>";
189
	return $form;
190
}
191
192
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
193