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 ( 79d14a...755201 )
by gyeong-won
14:31
created

communicationModel   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 373
Duplicated Lines 10.99 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 55
c 1
b 1
f 0
lcom 1
cbo 2
dl 41
loc 373
rs 6.8

12 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
C getConfig() 0 37 7
B getGrantArray() 0 32 6
C checkGrant() 0 41 16
C getSelectedMessage() 0 50 13
A getNewMessage() 0 21 2
B getMessages() 0 34 3
A getFriends() 0 18 1
A isAddedFriend() 12 12 1
A getFriendGroupInfo() 12 12 1
A getFriendGroups() 17 17 2
A isFriend() 0 17 2

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 communicationModel 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 communicationModel, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @class  communicationModel
6
 * @author NAVER ([email protected])
7
 * communication module of the Model class
8
 */
9
class communicationModel extends communication
10
{
11
12
	/**
13
	 * Initialization
14
	 * @return void
15
	 */
16
	function init()
17
	{
18
19
	}
20
21
	/**
22
	 * get the configuration
23
	 * @return object config of communication module
24
	 */
25
	function getConfig()
26
	{
27
		$oModuleModel = getModel('module');
28
		$communication_config = $oModuleModel->getModuleConfig('communication');
29
30
		if(!is_object($communication_config))
31
		{
32
			$communication_config = new stdClass();
33
		}
34
35
		if(!$communication_config->skin)
36
		{
37
			$communication_config->skin = 'default';
38
		}
39
40
		if(!$communication_config->colorset)
41
		{
42
			$communication_config->colorset = 'white';
43
		}
44
45
		if(!$communication_config->editor_skin)
46
		{
47
			$communication_config->editor_skin = 'ckeditor';
48
		}
49
50
		if(!$communication_config->mskin)
51
		{
52
			$communication_config->mskin = 'default';
53
		}
54
		
55
		if(!$communication_config->grant_write)
56
		{
57
			$communication_config->grant_write = array('default_grant'=>'member');
58
		}
59
60
		return $communication_config;
61
	}
62
63
	/**
64
	  * @brief get grant array for insert to database. table module_config's config field 
65
	  * @param string $default
66
	  * @param array $group
67
	  * @return array
68
	  */
69
	function getGrantArray($default, $group)
70
	{
71
		$grant = array();
72
		if($default!="")
73
		{
74
			switch($default)
75
			{
76
				case "-2":
77
					$grant = array("default_grant"=>"site");
78
					break;
79
				case "-3":
80
					$grant = array("default_grant"=>"manager");
81
					break;
82
				default :
83
					$grant = array("default_grant"=>"member");
84
					break;
85
			}
86
		} 
87
		else if(is_array($group)) 
88
		{
89
			$oMemberModel = getModel('member');
90
			$group_list = $oMemberModel->getGroups($this->site_srl);
0 ignored issues
show
Bug introduced by
The property site_srl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
91
92
			$group_grant = array();
93
			foreach($group as $group_srl)
94
			{
95
				$group_grant[$group_srl] = $group_list[$group_srl]->title;
96
			}
97
			$grant = array('group_grant'=>$group_grant);
98
		} 
99
		return $grant;
100
	}
101
102
	/**
103
	  * @brief check member's grant
104
	  * @param object $member_info
0 ignored issues
show
Bug introduced by
There is no parameter named $member_info. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
105
	  * @param array $arrGrant
106
	  * @return boolean
107
	  */
108
	function checkGrant($arrGrant)
109
	{
110
		if(!$arrGrant)
0 ignored issues
show
Bug Best Practice introduced by
The expression $arrGrant of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
111
			return false;
112
113
		$logged_info = Context::get('logged_info');
114
		if(!$logged_info)
115
			return false;
116
117
		if($logged_info->is_admin == "Y")
118
			return true;
119
120
		if($arrGrant['default_grant'])
121
		{
122
			if($arrGrant['default_grant'] == "member" && $logged_info)
123
				return true;
124
125
			if($arrGrant['default_grant'] == "site" && $this->site_srl == $logged_info->site_srl)
126
				return true;
127
128
			if($arrGrant['default_grant'] == "manager" && $logged_info->is_admin == "Y")
129
				return true;
130
		}
131
132
		if($arrGrant['group_grant'])
133
		{
134
			$group_grant = $arrGrant['group_grant'];
135
			if(!is_array($group_grant))
136
				return false;
137
138
			foreach($logged_info->group_list as $group_srl=>$title)
139
			{
140
				if(isset($group_grant[$group_srl])&&$group_grant[$group_srl]==$title)
141
					return true;
142
			}
143
144
		}
145
146
		return false;
147
148
	}
149
150
	/**
151
	 * get the message contents
152
	 * @param int $message_srl
153
	 * @param array $columnList
154
	 * @return object message information
155
	 */
156
	function getSelectedMessage($message_srl, $columnList = array())
157
	{
158
		$logged_info = Context::get('logged_info');
159
160
		$args = new stdClass();
161
		$args->message_srl = $message_srl;
162
		$output = executeQuery('communication.getMessage', $args, $columnList);
163
164
		$message = $output->data;
165
		if(!$message)
166
		{
167
			return;
168
		}
169
170
		// get recipient's information if it is a sent message
171
		$oMemberModel = getModel('member');
172
173
		if($message->sender_srl == $logged_info->member_srl && $message->message_type == 'S')
174
		{
175
			$member_info = $oMemberModel->getMemberInfoByMemberSrl($message->receiver_srl);
176
		}
177
		// get sendor's information if it is a received/archived message
178
		else
179
		{
180
			$member_info = $oMemberModel->getMemberInfoByMemberSrl($message->sender_srl);
181
		}
182
183
		if($member_info)
184
		{
185
			foreach($member_info as $key => $val)
186
			{
187
				if($key === 'title') continue;
188
				if($key === 'content') continue;
189
				if($key === 'sender_srl') continue;
190
				if($key === 'password') continue;
191
				if($key === 'regdate') continue;
192
193
				$message->{$key} = $val;
194
			}
195
		}
196
197
		// change the status if is a received and not yet read message
198
		if($message->message_type == 'R' && $message->readed != 'Y')
199
		{
200
			$oCommunicationController = getController('communication');
201
			$oCommunicationController->setMessageReaded($message_srl);
0 ignored issues
show
Bug introduced by
The method setMessageReaded() does not exist on ModuleObject. Did you maybe mean setMessage()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
202
		}
203
204
		return $message;
205
	}
206
207
	/**
208
	 * get a new message
209
	 * @param array $columnList
210
	 * @return object message information
211
	 */
212
	function getNewMessage($columnList = array())
213
	{
214
		$logged_info = Context::get('logged_info');
215
216
		$args = new stdClass();
217
		$args->receiver_srl = $logged_info->member_srl;
218
		$args->readed = 'N';
219
220
		$output = executeQuery('communication.getNewMessage', $args, $columnList);
221
		if(!count($output->data))
222
		{
223
			return;
224
		}
225
226
		$message = array_pop($output->data);
227
228
		$oCommunicationController = getController('communication');
229
		$oCommunicationController->setMessageReaded($message->message_srl);
0 ignored issues
show
Bug introduced by
The method setMessageReaded() does not exist on ModuleObject. Did you maybe mean setMessage()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
230
231
		return $message;
232
	}
233
234
	/**
235
	 * get a message list
236
	 * @param string $message_type (R: Received Message, S: Sent Message, T: Archive)
237
	 * @param array $columnList
238
	 * @return Object
239
	 */
240
	function getMessages($message_type = "R", $columnList = array())
241
	{
242
		$logged_info = Context::get('logged_info');
243
		$args = new stdClass();
244
245
		switch($message_type)
246
		{
247
			case 'R' :
248
				$args->member_srl = $logged_info->member_srl;
249
				$args->message_type = 'R';
250
				$query_id = 'communication.getReceivedMessages';
251
				break;
252
253
			case 'T' :
254
				$args->member_srl = $logged_info->member_srl;
255
				$args->message_type = 'T';
256
				$query_id = 'communication.getStoredMessages';
257
				break;
258
259
			default :
260
				$args->member_srl = $logged_info->member_srl;
261
				$args->message_type = 'S';
262
				$query_id = 'communication.getSendedMessages';
263
				break;
264
		}
265
266
		// Other variables
267
		$args->sort_index = 'message.list_order';
268
		$args->page = Context::get('page');
269
		$args->list_count = 20;
270
		$args->page_count = 10;
271
		
272
		return executeQuery($query_id, $args, $columnList);
273
	}
274
275
	/**
276
	 * Get a list of friends
277
	 * @param int $friend_group_srl (default 0)
278
	 * @param array $columnList
279
	 * @return Object
280
	 */
281
	function getFriends($friend_group_srl = 0, $columnList = array())
282
	{
283
		$logged_info = Context::get('logged_info');
284
285
		$args = new stdClass();
286
		$args->friend_group_srl = $friend_group_srl;
287
		$args->member_srl = $logged_info->member_srl;
288
289
		// Other variables
290
		$args->page = Context::get('page');
291
		$args->sort_index = 'friend.list_order';
292
		$args->list_count = 10;
293
		$args->page_count = 10;
294
295
		$output = executeQuery('communication.getFriends', $args, $columnList);
296
		
297
		return $output;
298
	}
299
300
	/**
301
	 * check if a friend is already added
302
	 * @param int $member_srl
303
	 * @return int
304
	 */
305 View Code Duplication
	function isAddedFriend($member_srl)
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...
306
	{
307
		$logged_info = Context::get('logged_info');
308
309
		$args = new stdClass();
310
		$args->member_srl = $logged_info->member_srl;
311
		$args->target_srl = $member_srl;
312
		
313
		$output = executeQuery('communication.isAddedFriend', $args);
314
315
		return $output->data->count;
316
	}
317
318
	/**
319
	 * Get a group of friends
320
	 * @param int $friend_group_srl
321
	 * @return object
322
	 */
323 View Code Duplication
	function getFriendGroupInfo($friend_group_srl)
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...
324
	{
325
		$logged_info = Context::get('logged_info');
326
327
		$args = new stdClass();
328
		$args->member_srl = $logged_info->member_srl;
329
		$args->friend_group_srl = $friend_group_srl;
330
331
		$output = executeQuery('communication.getFriendGroup', $args);
332
		
333
		return $output->data;
334
	}
335
336
	/**
337
	 * Get a list of groups
338
	 * @return array
339
	 */
340 View Code Duplication
	function getFriendGroups()
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...
341
	{
342
		$logged_info = Context::get('logged_info');
343
344
		$args = new stdClass();
345
		$args->member_srl = $logged_info->member_srl;
346
347
		$output = executeQueryArray('communication.getFriendGroups', $args);
348
349
		$group_list = $output->data;
350
		if(!$group_list)
351
		{
352
			return;
353
		}
354
		
355
		return $group_list;
356
	}
357
358
	/**
359
	 * check whether to be added in the friend list
360
	 * @param int $target_srl 
361
	 * @return boolean (true : friend, false : not friend) 
362
	 */
363
	function isFriend($target_srl)
364
	{
365
		$logged_info = Context::get('logged_info');
366
367
		$args = new stdClass();
368
		$args->member_srl = $target_srl;
369
		$args->target_srl = $logged_info->member_srl;
370
371
		$output = executeQuery('communication.isAddedFriend', $args);
372
373
		if($output->data->count)
374
		{
375
			return TRUE;
376
		}
377
378
		return FALSE;
379
	}
380
381
}
382
/* End of file communication.model.php */
383
/* Location: ./modules/comment/communication.model.php */
384