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 ( 1b6b0f...a12690 )
by gyeong-won
12:41
created

pointController::triggerDeleteDocument()   C

Complexity

Conditions 11
Paths 13

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 11
eloc 22
c 1
b 1
f 0
nc 13
nop 1
dl 0
loc 36
rs 5.2653

How to fix   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
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  pointController
5
 * @author NAVER ([email protected])
6
 * @brief Controller class of point modules
7
 */
8
class pointController extends point
9
{
10
	/**
11
	 * @brief Initialization
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * @brief Membership point application trigger
19
	 */
20
	function triggerInsertMember(&$obj)
21
	{
22
		// Get the point module information
23
		$oModuleModel = getModel('module');
24
		$config = $oModuleModel->getModuleConfig('point');
25
		// Get the member_srl of the newly registered member
26
		$member_srl = $obj->member_srl;
27
		// Get the points of the member
28
		$oPointModel = getModel('point');
29
		$cur_point = $oPointModel->getPoint($member_srl, true);
30
31
		$point = $config->signup_point;
32
		// Increase the point
33
		$cur_point += $point;
34
		$this->setPoint($member_srl,$cur_point, 'signup');
35
36
		return new Object();
37
	}
38
39
	/**
40
	 * @brief A trigger to add points to the member for login
41
	 */
42
	function triggerAfterLogin(&$obj)
43
	{
44
		$member_srl = $obj->member_srl;
45
		if(!$member_srl) return new Object();
46
		// If the last login is not today, give the points
47
		if(substr($obj->last_login,0,8)==date("Ymd")) return new Object();
48
		// Get the point module information
49
		$oModuleModel = getModel('module');
50
		$config = $oModuleModel->getModuleConfig('point');
51
		// Get the points of the member
52
		$oPointModel = getModel('point');
53
		$cur_point = $oPointModel->getPoint($member_srl, true);
54
55
		$point = $config->login_point;
56
		// Increase the point
57
		$cur_point += $point;
58
		$this->setPoint($member_srl,$cur_point);
59
60
		return new Object();
61
	}
62
63
	/**
64
	 * @brief A trigger to add points to the member for creating a post
65
	 */
66
	function triggerInsertDocument(&$obj)
67
	{
68
		$oDocumentModel = getModel('document');
69
		if($obj->status != $oDocumentModel->getConfigStatus('temp'))
70
		{
71
			$module_srl = $obj->module_srl;
72
			$member_srl = $obj->member_srl;
73
			if(!$module_srl || !$member_srl) return new Object();
74
			// The fix to disable giving points for saving the document temporarily
75
			if($module_srl == $member_srl) return new Object();
76
			// Get the point module information
77
			$oModuleModel = getModel('module');
78
			$config = $oModuleModel->getModuleConfig('point');
79
			$module_config = $oModuleModel->getModulePartConfig('point',$module_srl);
80
			// Get the points of the member
81
			$oPointModel = getModel('point');
82
			$cur_point = $oPointModel->getPoint($member_srl, true);
83
84
			$point = $module_config['insert_document'];
85
			if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document;
86
			$cur_point += $point;
87
			// Add points for attaching a file
88
			$point = $module_config['upload_file'];
89
			if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
90
			if($obj->uploaded_count) $cur_point += $point * $obj->uploaded_count;
91
			// Increase the point
92
			$this->setPoint($member_srl,$cur_point);
93
		}
94
95
		return new Object();
96
	}
97
98
	/**
99
	 * @brief The trigger to give points for normal saving the temporarily saved document
100
	 * Temporary storage at the point in 1.2.3 changed to avoid payment
101
	 */
102
	function triggerUpdateDocument(&$obj)
103
	{
104
		$oDocumentModel = getModel('document');
105
		$document_srl = $obj->document_srl;
106
		$oDocument = $oDocumentModel->getDocument($document_srl);
107
108
		// if status is TEMP or PUBLIC... give not point, only status is empty
109
		if($oDocument->get('status') == $oDocumentModel->getConfigStatus('temp') && $obj->status != $oDocumentModel->getConfigStatus('temp'))
110
		{
111
			$oModuleModel = getModel('module');
112
113
			// Get the point module information
114
			$config = $oModuleModel->getModuleConfig('point');
115
			$module_config = $oModuleModel->getModulePartConfig('point',$obj->module_srl);
116
			// Get the points of the member
117
			$oPointModel = getModel('point');
118
			$cur_point = $oPointModel->getPoint($oDocument->get('member_srl'), true);
119
120
			$point = $module_config['insert_document'];
121
			if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document;
122
			$cur_point += $point;
123
			// Add points for attaching a file
124
			$point = $module_config['upload_file'];
125
			if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
126
			if($obj->uploaded_count) $cur_point += $point * $obj->uploaded_count;
127
			// Increase the point
128
			$this->setPoint($oDocument->get('member_srl'), $cur_point);
129
		}
130
131
		return new Object();
132
	}
133
134
	/**
135
	 * @brief The trigger which deducts the points related to post comments before deleting the post itself
136
	 */
137
	function triggerBeforeDeleteDocument(&$obj)
138
	{
139
		$document_srl = $obj->document_srl;
140
		$member_srl = $obj->member_srl;
141
142
		$oDocumentModel = getModel('document');
143
		$oDocument = $oDocumentModel->getDocument($document_srl);
144
		if(!$oDocument->isExists()) return new Object();
145
		// Get the point module information
146
		$oModuleModel = getModel('module');
147
		$config = $oModuleModel->getModuleConfig('point');
148
		$module_config = $oModuleModel->getModulePartConfig('point',$oDocument->get('module_srl'));
149
		// The process related to clearing the post comments
150
		$comment_point = $module_config['insert_comment'];
151
		if(strlen($comment_point) == 0 && !is_int($comment_point)) $comment_point = $config->insert_comment;
152
		// If there are comment points, attempt to deduct
153
		if($comment_point>0) return new Object();
154
		// Get all the comments related to this post
155
		$cp_args = new stdClass();
156
		$cp_args->document_srl = $document_srl;
157
		$output = executeQueryArray('point.getCommentUsers', $cp_args);
158
		// Return if there is no object
159
		if(!$output->data) return new Object();
160
		// Organize the member number
161
		$member_srls = array();
162
		$cnt = count($output->data);
163
		for($i=0;$i<$cnt;$i++)
164
		{
165
			if($output->data[$i]->member_srl<1) continue;
166
			$member_srls[abs($output->data[$i]->member_srl)] = $output->data[$i]->count;
167
		}
168
		// Remove the member number who has written the original post
169
		if($member_srl) unset($member_srls[abs($member_srl)]);
170
		if(!count($member_srls)) return new Object();
171
		// Remove all the points for each member
172
		$oPointModel = getModel('point');
173
		// Get the points
174
		$point = $module_config['download_file'];
0 ignored issues
show
Unused Code introduced by
$point is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
175
		foreach($member_srls as $member_srl => $cnt)
176
		{
177
			$cur_point = $oPointModel->getPoint($member_srl, true);
178
			$cur_point -= $cnt * $comment_point;
179
			$this->setPoint($member_srl,$cur_point);
180
		}
181
182
		return new Object();
183
	}
184
185
	/**
186
	 * @brief A trigger to give points for deleting the post
187
	 */
188
	function triggerDeleteDocument(&$obj)
189
	{
190
		$oDocumentModel = getModel('document');
191
		
192
		if($obj->status != $oDocumentModel->getConfigStatus('temp'))
193
		{
194
			$module_srl = $obj->module_srl;
195
			$member_srl = $obj->member_srl;
196
			// The process related to clearing the post object
197
			if(!$module_srl || !$member_srl) return new Object();
198
			// Run only when logged in
199
			$logged_info = Context::get('logged_info');
200
			if(!$logged_info->member_srl) return new Object();
201
			// Get the points of the member
202
			$oPointModel = getModel('point');
203
			$cur_point = $oPointModel->getPoint($member_srl, true);
204
			// Get the point module information
205
			$oModuleModel = getModel('module');
206
			$config = $oModuleModel->getModuleConfig('point');
207
			$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
208
	
209
			$point = $module_config['insert_document'];
210
			if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document;
211
			// if the point is set to decrease when writing a document, make sure it does not increase the points when deleting an article
212
			if($point < 0) return new Object();
213
			$cur_point -= $point;
214
			// Add points related to deleting an attachment
215
			$point = $module_config['upload_file'];
216
			if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
217
			if($obj->uploaded_count) $cur_point -= $point * $obj->uploaded_count;
218
			// Increase the point
219
			$this->setPoint($member_srl,$cur_point);
220
		}
221
222
		return new Object();
223
	}
224
225
	/**
226
	 * @brief A trigger which gives points for entering a comment
227
	 */
228
	function triggerInsertComment(&$obj)
229
	{
230
		$module_srl = $obj->module_srl;
231
		$member_srl = $obj->member_srl;
232
		if(!$module_srl || !$member_srl) return new Object();
233
		// Do not increase the points if the member is the author of the post
234
		$document_srl = $obj->document_srl;
235
		$oDocumentModel = getModel('document');
236
		$oDocument = $oDocumentModel->getDocument($document_srl);
237
		if(!$oDocument->isExists() || abs($oDocument->get('member_srl'))==abs($member_srl)) return new Object();
238
		// Get the point module information
239
		$oModuleModel = getModel('module');
240
		$config = $oModuleModel->getModuleConfig('point');
241
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
242
		// Get the points of the member
243
		$oPointModel = getModel('point');
244
		$cur_point = $oPointModel->getPoint($member_srl, true);
245
246
		$point = $module_config['insert_comment'];
247
		if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment;
248
		// Increase the point
249
		$cur_point += $point;
250
		$this->setPoint($member_srl,$cur_point);
251
252
		return new Object();
253
	}
254
255
	/**
256
	 * @brief A trigger which gives points for deleting a comment
257
	 */
258
	function triggerDeleteComment(&$obj)
259
	{
260
		$oModuleModel = getModel('module');
261
		$oPointModel = getModel('point');
262
		$oDocumentModel = getModel('document');
263
264
		$module_srl = $obj->module_srl;
265
		$member_srl = abs($obj->member_srl);
266
		$document_srl = $obj->document_srl;
267
		if(!$module_srl || !$member_srl) return new Object();
268
		// Get the original article (if the original article is missing or if the member is its author, do not apply the points)
269
		$oDocument = $oDocumentModel->getDocument($document_srl);
270
		if(!$oDocument->isExists()) return new Object();
271
		if($oDocument->get('member_srl')==$member_srl) return new Object();
272
		// Get the point module information
273
		$config = $oModuleModel->getModuleConfig('point');
274
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
275
		// Get the points of the member
276
		$cur_point = $oPointModel->getPoint($member_srl, true);
277
278
		$point = $module_config['insert_comment'];
279
		if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment;
280
		// if the point is set to decrease when writing a comment, make sure it does not increase the points when deleting a comment
281
		if($point < 0) return new Object();
282
		// Increase the point
283
		$cur_point -= $point;
284
		$this->setPoint($member_srl,$cur_point);
285
286
		return new Object();
287
	}
288
289
	/**
290
	 * @brief Add the file registration trigger
291
	 * To prevent taking points for invalid file registration this method wlil return a null object
292
	 */
293
	function triggerInsertFile(&$obj)
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
294
	{
295
		return new Object();
296
	}
297
298
	/**
299
	 * @brief A trigger to give points for deleting a file
300
	 * Remove points only in case an invalid file is being deleted
301
	 */
302
	function triggerDeleteFile(&$obj)
303
	{
304
		if($obj->isvalid != 'Y') return new Object();
305
306
		$module_srl = $obj->module_srl;
307
		$member_srl = $obj->member_srl;
308
		if(!$module_srl || !$member_srl) return new Object();
309
		// Get the point module information
310
		$oModuleModel = getModel('module');
311
		$config = $oModuleModel->getModuleConfig('point');
312
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
313
		// Get the points of the member
314
		$oPointModel = getModel('point');
315
		$cur_point = $oPointModel->getPoint($member_srl, true);
316
317
		$point = $module_config['upload_file'];
318
		if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
319
		// Increase the point
320
		$cur_point -= $point;
321
		$this->setPoint($member_srl,$cur_point);
322
323
		return new Object();
324
	}
325
326
	/**
327
	 * @brief The trigger called before a file is downloaded
328
	 */
329
	function triggerBeforeDownloadFile(&$obj)
330
	{
331
		$logged_info = Context::get('logged_info');
332
		$member_srl = $logged_info->member_srl;
333
		$module_srl = $obj->module_srl;
334
		if(!$module_srl) return new Object();
335
		// Pass if it is your file
336
		if(abs($obj->member_srl) == abs($member_srl)) return new Object();
337
338
		$oModuleModel = getModel('module');
339
		$config = $oModuleModel->getModuleConfig('point');
340
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
341
		// If it is set not to allow downloading for non-logged in users, do not permit
342
		if(!Context::get('is_logged'))
343
		{
344
			if($config->disable_download == 'Y' && strlen($module_config['download_file']) == 0 && !is_int($module_config['download_file'])) return new Object(-1,'msg_not_permitted_download');
345
			else return new Object();
346
		}
347
		// Get the points of the member
348
		$oPointModel = getModel('point');
349
		$cur_point = $oPointModel->getPoint($member_srl, true);
350
		// Get the points
351
		$point = $module_config['download_file'];
352
		if(strlen($point) == 0 && !is_int($point)) $point = $config->download_file;
353
		// If points are less than 0, and if downloading a file is not allowed in this case, give an errors
354
		if($cur_point + $point < 0 && $config->disable_download == 'Y') return new Object(-1,'msg_cannot_download');
355
356
		return new Object();
357
	}
358
359
	/**
360
	 * @brief The trigger to give points for downloading the file
361
	 */
362
	function triggerDownloadFile(&$obj)
363
	{
364
		// Run only when logged in
365
		$logged_info = Context::get('logged_info');
366
		if(!$logged_info->member_srl) return new Object();
367
		$module_srl = $obj->module_srl;
368
		$member_srl = $logged_info->member_srl;
369
		if(!$module_srl) return new Object();
370
		// Pass if it is your file
371
		if(abs($obj->member_srl) == abs($member_srl)) return new Object();
372
		// Get the point module information
373
		$oModuleModel = getModel('module');
374
		$config = $oModuleModel->getModuleConfig('point');
375
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
376
		// Get the points of the member
377
		$oPointModel = getModel('point');
378
		$cur_point = $oPointModel->getPoint($member_srl, true);
379
		// Get the points
380
		$point = $module_config['download_file'];
381
		if(strlen($point) == 0 && !is_int($point)) $point = $config->download_file;
382
		// Increase the point
383
		$cur_point += $point;
384
		$this->setPoint($member_srl,$cur_point);
385
386
		return new Object();
387
	}
388
389
	/**
390
	 * @brief Give points for hits increase
391
	 * Run it even if there are no points
392
	 */
393
	function triggerUpdateReadedCount(&$obj)
394
	{
395
		$oModuleModel = getModel('module');
396
		$oPointModel = getModel('point');
397
		// Get visitor information
398
		$logged_info = Context::get('logged_info');
399
		$member_srl = $logged_info->member_srl;
400
		// Get the original author number
401
		$target_member_srl = abs($obj->get('member_srl'));
402
		// Pass without increasing the hits if the viewer is the same as the author
403
		if($target_member_srl == $member_srl) return new Object();
404
		// Get the point information for each module
405
		$config = $oModuleModel->getModuleConfig('point');
406
		$module_config = $oModuleModel->getModulePartConfig('point', $obj->get('module_srl'));
407
		// Get hits points
408
		$point = $module_config['read_document'];
409
		if(strlen($point) == 0 && !is_int($point)) $point = $config->read_document;
410
		// Pass if there are no requested points
411
		if(!$point) return new Object();
412
		// In case of a registered member, if it is read but cannot just pass, then get the current points
413
		if($member_srl)
414
		{
415
			$args->member_srl = $member_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...
416
			$args->document_srl = $obj->document_srl;
417
			$output = executeQuery('document.getDocumentReadedLogInfo', $args);
418
			if($output->data->count) return new Object();
419
			$cur_point = $oPointModel->getPoint($member_srl, true);
420
		}
421
		else
422
		{
423
			$cur_point = 0;
424
		}
425
		// Get the defaul configurations of the Point Module
426
		$config = $oModuleModel->getModuleConfig('point');
427
		// When the requested points are negative, compared it with the current point
428
		$_SESSION['banned_document'][$obj->document_srl] = false;
429
		if($config->disable_read_document == 'Y' && $point < 0 && abs($point)>$cur_point)
430
		{
431
			$message = sprintf(Context::getLang('msg_disallow_by_point'), abs($point), $cur_point);
432
			$obj->add('content', $message);
433
			$_SESSION['banned_document'][$obj->document_srl] = true;
434
			return new Object(-1, $message);
435
		}
436
		// If not logged in, pass
437
		if(!$logged_info->member_srl) return new Object();
438
		// Pass, if there are no requested points
439
		if(!$point) return new Object();
440
		// If the read record is missing, leave it
441
		$output = executeQuery('document.insertDocumentReadedLog', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
442
		// Increase the point
443
		$cur_point += $point;
444
		$this->setPoint($member_srl,$cur_point);
445
446
		return new Object();
447
	}
448
449
	/**
450
	 * @brief Points for voting up or down
451
	 */
452
	function triggerUpdateVotedCount(&$obj)
453
	{
454
		$module_srl = $obj->module_srl;
455
		$member_srl = $obj->member_srl;
456
		if(!$module_srl || !$member_srl) return new Object();
457
458
		$oModuleModel = getModel('module');
459
		$config = $oModuleModel->getModuleConfig('point');
460
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
461
462
		$oPointModel = getModel('point');
463
		$cur_point = $oPointModel->getPoint($member_srl, true);
464
465
		if( $obj->point > 0 )
466
		{
467
			$point = $module_config['voted'];
468
			if(strlen($point) == 0 && !is_int($point)) $point = $config->voted;
469
		}
470
		else
471
		{
472
			$point = $module_config['blamed'];
473
			if(strlen($point) == 0 && !is_int($point)) $point = $config->blamed;
474
		}
475
476
		if(!$point) return new Object();
477
		// Increase the point
478
		$cur_point += $point;
479
		$this->setPoint($member_srl,$cur_point);
480
481
		return new Object();
482
	}
483
484
	/**
485
	 * @brief Set points
486
	 */
487
	function setPoint($member_srl, $point, $mode = null)
488
	{
489
		$member_srl = abs($member_srl);
490
		$mode_arr = array('add', 'minus', 'update', 'signup');
491
		if(!$mode || !in_array($mode,$mode_arr)) $mode = 'update';
492
493
		// Get configuration information
494
		$oMemberModel = getModel('member');
495
		$oModuleModel = getModel('module');
496
		$oPointModel = getModel('point');
497
		$config = $oModuleModel->getModuleConfig('point');
498
499
		// Get the default configuration information
500
		$current_point = $oPointModel->getPoint($member_srl, true);
501
		$current_level = $oPointModel->getLevel($current_point, $config->level_step);
502
503
		// Change points
504
		$args = new stdClass();
505
		$args->member_srl = $member_srl;
506
		$args->point = $current_point;
507
508
		switch($mode)
509
		{
510
			case 'add' :
511
				$args->point += $point;
512
				break;
513
			case 'minus' :
514
				$args->point -= $point;
515
				break;
516
			case 'update' :
517
			case 'signup' :
518
				$args->point = $point;
519
				break;
520
		}
521
		if($args->point < 0) $args->point = 0;
522
		$point = $args->point;
523
524
		// Call a trigger (before)
525
		$trigger_obj = new stdClass();
526
		$trigger_obj->member_srl = $args->member_srl;
527
		$trigger_obj->mode = $mode;
528
		$trigger_obj->current_point = $current_point;
529
		$trigger_obj->current_level = $current_level;
530
		$trigger_obj->set_point = $point;
531
		$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'before', $trigger_obj);
532
		if(!$trigger_output->toBool())
533
		{
534
			return $trigger_output;
535
		}
536
537
		// begin transaction
538
		$oDB = &DB::getInstance();
539
		$oDB->begin();
540
541
		// If there are points, update, if no, insert
542
		$oPointModel = getModel('point');
543
		if($oPointModel->isExistsPoint($member_srl)) executeQuery("point.updatePoint", $args);
544
		else executeQuery("point.insertPoint", $args);
545
546
		// Get a new level
547
		$level = $oPointModel->getLevel($point, $config->level_step);
548
549
		// If existing level and a new one are different attempt to set a point group
550
		if($level != $current_level)
551
		{
552
			// Check if the level, for which the current points are prepared, is calculate and set the correct group
553
			$point_group = $config->point_group;
554
			// If the point group exists
555
			if($point_group && is_array($point_group) && count($point_group) )
556
			{
557
				// Get the default group
558
				$default_group = $oMemberModel->getDefaultGroup();
559
				// Get the removed group and the newly granted group
560
				$del_group_list = array();
561
				$new_group_list = array();
562
563
				asort($point_group);
564
				// Reset group after initialization
565
				if($config->group_reset != 'N')
566
				{
567
					// If the new level is in the right group
568
					if(in_array($level, $point_group))
569
					{
570
						// Delete all groups except the one which the current level belongs to
571 View Code Duplication
						foreach($point_group as $group_srl => $target_level)
572
						{
573
							$del_group_list[] = $group_srl;
574
							if($target_level == $level) $new_group_list[] = $group_srl;
575
						}
576
					}
577
					// Otherwise, in case the level is reduced, add the recent group
578
					else
579
					{
580
						$i = $level;
581
						while($i > 0)
582
						{
583
							if(in_array($i, $point_group))
584
							{
585
								foreach($point_group as $group_srl => $target_level)
586
								{
587
									if($target_level == $i)
588
									{
589
										$new_group_list[] = $group_srl;
590
									}
591
								}
592
								$i = 0;
593
							}
594
							$i--;
595
						}
596
					}
597
					// Delete the group of a level which is higher than the current level
598
					foreach($point_group as $group_srl => $target_level)
599
					{
600
						if($target_level > $level) $del_group_list[] = $group_srl;
601
					}
602
					$del_group_list[] = $default_group->group_srl;
603
				}
604
				// Grant a new group
605
				else
606
				{
607
					// Check until the current level by rotating setting the configurations of the point groups
608 View Code Duplication
					foreach($point_group as $group_srl => $target_level)
609
					{
610
						$del_group_list[] = $group_srl;
611
						if($target_level <= $level) $new_group_list[] = $group_srl;
612
					}
613
				}
614
				// If there is no a new group, granted the default group
615
				if(!$new_group_list[0]) $new_group_list[0] = $default_group->group_srl;
616
				// Remove linkage group
617
				if($del_group_list && count($del_group_list))
0 ignored issues
show
Bug Best Practice introduced by
The expression $del_group_list 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...
618
				{
619
					$del_group_args = new stdClass;
620
					$del_group_args->member_srl = $member_srl;
621
					$del_group_args->group_srl = implode(',', $del_group_list);
622
					$del_group_output = executeQuery('point.deleteMemberGroup', $del_group_args);
0 ignored issues
show
Unused Code introduced by
$del_group_output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
623
				}
624
				// Grant a new group
625
				foreach($new_group_list as $group_srl)
626
				{
627
					$new_group_args = new stdClass;
628
					$new_group_args->member_srl = $member_srl;
629
					$new_group_args->group_srl = $group_srl;
630
					executeQuery('member.addMemberToGroup', $new_group_args);
631
				}
632
			}
633
		}
634
635
		// Call a trigger (after)
636
		$trigger_obj->new_group_list = $new_group_list;
0 ignored issues
show
Bug introduced by
The variable $new_group_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...
637
		$trigger_obj->del_group_list = $del_group_list;
0 ignored issues
show
Bug introduced by
The variable $del_group_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...
638
		$trigger_obj->new_level = $level;
639
		$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'after', $trigger_obj);
640
		if(!$trigger_output->toBool())
641
		{
642
			$oDB->rollback();
643
			return $trigger_output;
644
		}
645
646
		$oDB->commit();
647
648
		// Cache Settings
649
		$cache_path = sprintf('./files/member_extra_info/point/%s/', getNumberingPath($member_srl));
650
		FileHandler::makedir($cache_path);
651
652
		$cache_filename = sprintf('%s%d.cache.txt', $cache_path, $member_srl);
653
		FileHandler::writeFile($cache_filename, $point);
654
655
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
656 View Code Duplication
		if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
0 ignored issues
show
Bug Best Practice introduced by
The expression $new_group_list 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...
Bug Best Practice introduced by
The expression $del_group_list 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...
657
		{
658
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
659
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
660
			$oCacheHandler->delete($cache_key);
661
		}
662
663
		$oCacheHandler = CacheHandler::getInstance('object');
664 View Code Duplication
		if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
0 ignored issues
show
Bug Best Practice introduced by
The expression $new_group_list 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...
Bug Best Practice introduced by
The expression $del_group_list 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...
665
		{
666
			$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
667
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
668
			$oCacheHandler->delete($cache_key);
669
		}
670
671
		return $output;
0 ignored issues
show
Bug introduced by
The variable $output does not exist. Did you mean $trigger_output?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
672
	}
673
674 View Code Duplication
	function triggerCopyModule(&$obj)
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...
675
	{
676
		$oModuleModel = getModel('module');
677
		$pointConfig = $oModuleModel->getModulePartConfig('point', $obj->originModuleSrl);
678
679
		$oModuleController = getController('module');
680
		if(is_array($obj->moduleSrlList))
681
		{
682
			foreach($obj->moduleSrlList AS $key=>$moduleSrl)
683
			{
684
				$oModuleController->insertModulePartConfig('point', $moduleSrl, $pointConfig);
685
			}
686
		}
687
	}
688
}
689
/* End of file point.controller.php */
690
/* Location: ./modules/point/point.controller.php */
691