GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( d80144...902697 )
by gyeong-won
12:23
created

memberAdminModel   B

Complexity

Total Complexity 54

Size/Duplication

Total Lines 299
Duplicated Lines 12.37 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 37
loc 299
rs 7.0642
c 0
b 0
f 0
wmc 54
lcom 1
cbo 4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
F getMemberList() 12 108 29
A getSiteMemberList() 0 10 1
A getSiteAdminMemberSrls() 0 13 4
A getMemberAdminColorset() 15 21 3
A getMemberCountByDate() 10 10 3
A getMemberGroupMemberCountByDate() 0 9 3
B getMemberAdminInsertJoinForm() 0 35 5
B getMemberAdminIPCheck() 0 9 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like memberAdminModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use memberAdminModel, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  memberAdminModel
5
 * @author NAVER ([email protected])
6
 * admin model class of member module
7
 */
8
class memberAdminModel extends member
9
{
10
	/**
11
	 * info of member
12
	 * @var object
13
	 */
14
	var $member_info = NULL;
15
16
	/**
17
	 * info of member groups
18
	 * @var array
19
	 */
20
	var $member_groups = NULL;
21
22
	/**
23
	 * info of sign up form
24
	 * @var array
25
	 */
26
	var $join_form_list = NULL;
27
28
	/**
29
	 * Initialization
30
	 * @return void
31
	 */
32
	function init()
33
	{
34
	}
35
36
	/**
37
	 * Get a member list
38
	 * 
39
	 * @return object|array (object : when member count is 1, array : when member count is more than 1)
40
	 */
41
	function getMemberList()
42
	{
43
		// Search option
44
		$args = new stdClass();
45
		$args->is_admin = Context::get('is_admin')=='Y'?'Y':'';
46
		$args->is_denied = Context::get('is_denied')=='Y'?'Y':'';
47
		$args->selected_group_srl = Context::get('selected_group_srl');
48
49
		$filter = Context::get('filter_type');
50
		switch($filter)
51
		{
52
			case 'super_admin' : $args->is_admin = 'Y';break;
53
			case 'site_admin' : $args->member_srls = $this->getSiteAdminMemberSrls();break;
54
			case 'enable' : $args->is_denied = 'N';break;
55
			case 'disable' : $args->is_denied = 'Y';break;
56
		}
57
58
		$search_target = trim(Context::get('search_target'));
59
		$search_keyword = trim(Context::get('search_keyword'));
60
61
		if($search_target && $search_keyword)
62
		{
63
			switch($search_target)
64
			{
65 View Code Duplication
				case 'user_id' :
66
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
67
					$args->s_user_id = $search_keyword;
68
					break;
69 View Code Duplication
				case 'user_name' :
70
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
71
					$args->s_user_name = $search_keyword;
72
					break;
73
				case 'nick_name' :
74
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
75
					$args->s_nick_name = $search_keyword;
76
					$args->html_nick_name = htmlspecialchars($search_keyword, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
77
					break;
78 View Code Duplication
				case 'email_address' :
79
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
80
					$args->s_email_address = $search_keyword;
81
					break;
82
				case 'regdate' :
83
					$args->s_regdate = preg_replace("/[^0-9]/","",$search_keyword);
84
					break;
85
				case 'regdate_more' :
86
					$args->s_regdate_more = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
87
					break;
88
				case 'regdate_less' :
89
					$args->s_regdate_less = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
90
					break;
91
				case 'last_login' :
92
					$args->s_last_login = preg_replace("/[^0-9]/","",$search_keyword);
93
					//$args->s_last_login = $search_keyword;
94
					break;
95
				case 'last_login_more' :
96
					$args->s_last_login_more = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
97
					break;
98
				case 'last_login_less' :
99
					$args->s_last_login_less = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
100
					break;
101
				case 'birthday' :
102
					$args->s_birthday = preg_replace("/[^0-9]/","",$search_keyword);
103
					break;
104
				case 'extra_vars' :
105
					$args->s_extra_vars = $search_keyword;
106
					break;
107
			}
108
		}
109
110
		// Change the query id if selected_group_srl exists (for table join)
111
		$sort_order = Context::get('sort_order');
112
		$sort_index = Context::get('sort_index');
113
		if(!$sort_index)
114
		{
115
			$sort_index = "list_order";
116
		}
117
118
		if(!$sort_order)
119
		{
120
			$sort_order = 'asc';
121
		}
122
123
		if($sort_order != 'asc')
124
		{
125
			$sort_order = 'desc';
126
		}
127
128
		if($args->selected_group_srl)
129
		{
130
			$query_id = 'member.getMemberListWithinGroup';
131
			$args->sort_index = "member.".$sort_index;
132
		}
133
		else
134
		{
135
			$query_id = 'member.getMemberList';
136
			$args->sort_index = $sort_index; 
137
		}
138
139
		$args->sort_order = $sort_order;
140
		Context::set('sort_order', $sort_order);
141
		// Other variables
142
		$args->page = Context::get('page');
143
		$args->list_count = 40;
144
		$args->page_count = 10;
145
		$output = executeQuery($query_id, $args);
146
147
		return $output;
148
	}
149
150
	/**
151
	 * Get a memebr list for each site
152
	 * 
153
	 * @param int $site_srl
154
	 * @param int $page
155
	 *
156
	 * @return array
157
	 */
158
	function getSiteMemberList($site_srl, $page = 1)
159
	{
160
		$args->site_srl = $site_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
161
		$args->page = $page;
162
		$args->list_count = 40;
163
		$args->page_count = 10;
164
		$query_id = 'member.getSiteMemberList';
165
		$output = executeQueryArray($query_id, $args);
166
		return $output;
167
	}
168
169
	/**
170
	 * Get member_srls lists about site admins
171
	 * 
172
	 * @return array 
173
	 */
174
	function getSiteAdminMemberSrls()
175
	{
176
		$output = executeQueryArray('member.getSiteAdminMemberSrls');
177
		if(!$output->toBool() || !$output->data) return array();
178
179
		$member_srls = array();
180
		foreach($output->data as $member_info)
181
		{
182
			$member_srls[] = $member_info->member_srl;
183
		}
184
185
		return $member_srls;
186
	}
187
188
	/**
189
	 * Return colorset list of a skin in the member module
190
	 * 
191
	 * @return void 
192
	 */
193
	function getMemberAdminColorset()
194
	{
195
		$skin = Context::get('skin');
196 View Code Duplication
		if(!$skin) $tpl = "";
197
		else
198
		{
199
			$oModuleModel = getModel('module');
200
			$skin_info = $oModuleModel->loadSkinInfo($this->module_path, $skin);
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
201
			Context::set('skin_info', $skin_info);
202
203
			$oModuleModel = getModel('module');
204
			$config = $oModuleModel->getModuleConfig('member');
205
			if(!$config->colorset) $config->colorset = "white";
206
			Context::set('config', $config);
207
208
			$oTemplate = &TemplateHandler::getInstance();
209
			$tpl = $oTemplate->compile($this->module_path.'tpl', 'new_colorset_list');
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
210
		}
211
212
		$this->add('tpl', $tpl);
213
	}
214
215
216
	/**
217
	 * Return member count with date
218
	 * 
219
	 * @param string $date
220
	 *
221
	 * @return int
222
	 */
223 View Code Duplication
	public function getMemberCountByDate($date = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
224
	{
225
		$args = new stdClass();
226
		if($date) $args->regDate = date('Ymd', strtotime($date));
227
228
		$output = executeQuery('member.getMemberCountByDate', $args);
229
		if(!$output->toBool()) return 0;
230
231
		return $output->data->count;
232
	}
233
234
	/**
235
	 * Return site join member count with date
236
	 *
237
	 * @param string $date
238
	 *
239
	 * @return int
240
	 */
241
	function getMemberGroupMemberCountByDate($date = '')
242
	{
243
		if($date) $args->regDate = date('Ymd', strtotime($date));
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
244
245
		$output = executeQuery('member.getMemberGroupMemberCountByDate', $args);
246
		if(!$output->toBool()) return 0;
247
248
		return count($output->data);
249
	}
250
251
	/**
252
	 * Return add join Form
253
	 *
254
	 * @return void
255
	 */
256
	function getMemberAdminInsertJoinForm()
257
	{
258
		$member_join_form_srl = Context::get('member_join_form_srl');
259
260
		$args = new stdClass();
261
		$args->member_join_form_srl = $member_join_form_srl;
262
		$output = executeQuery('member.getJoinForm', $args);
263
264
		if($output->toBool() && $output->data)
265
		{
266
			$formInfo = $output->data;
267
			$default_value = $formInfo->default_value;
268
			if($default_value)
269
			{
270
				$default_value = unserialize($default_value);
271
				Context::set('default_value', $default_value);
272
			}
273
			Context::set('formInfo', $output->data);
274
		}
275
276
		$oMemberModel = getModel('member');
277
		$config = $oMemberModel->getMemberConfig();
278
		foreach($config->signupForm as $item) 
279
		{
280
			$list[] = $item->name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
281
		}
282
283
		$id_list = implode(',',$list);
0 ignored issues
show
Bug introduced by
The variable $list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
284
		Context::set('id_list',$id_list);
285
286
		$oTemplate = &TemplateHandler::getInstance();
287
		$tpl = $oTemplate->compile($this->module_path.'tpl', 'insert_join_form');
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
288
289
		$this->add('tpl', str_replace("\n"," ",$tpl));
290
	}
291
292
	/**
293
	 * check allowed target ip address when  login for admin. 
294
	 *
295
	 * @return boolean (true : allowed, false : refuse)
296
	 */
297
	function getMemberAdminIPCheck()
298
	{
299
		$db_info = Context::getDBInfo();
300
		$admin_ip_list = $db_info->admin_ip_list;
301
		if(!$admin_ip_list) return true;
302
		if(!is_array($admin_ip_list)) $admin_ip_list = explode(',',$admin_ip_list);
303
		if(!count($admin_ip_list) || IpFilter::filter($admin_ip_list)) return true;
304
		else return false;
305
	}
306
}
307
/* End of file member.admin.model.php */
308
/* Location: ./modules/member/member.admin.model.php */
309