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 ( 6e0140...4c5f43 )
by gyeong-won
14:03
created

boardController   D

Complexity

Total Complexity 86

Size/Duplication

Total Lines 522
Duplicated Lines 16.28 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 85
loc 522
rs 4.8717
c 0
b 0
f 0
wmc 86
lcom 1
cbo 4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
F procBoardInsertDocument() 22 172 38
C procBoardDeleteDocument() 4 38 7
A procBoardVoteDocument() 0 8 1
F procBoardInsertComment() 10 125 19
B procBoardDeleteComment() 26 26 4
B procBoardDeleteTrackback() 23 23 4
B procBoardVerificationPassword() 0 45 6
B triggerMemberMenu() 0 43 6

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

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @class  boardController
6
 * @author NAVER ([email protected])
7
 * @brief  board module Controller class
8
 **/
9
10
class boardController extends board
11
{
12
13
	/**
14
	 * @brief initialization
15
	 **/
16
	function init()
17
	{
18
	}
19
20
	/**
21
	 * @brief insert document
22
	 **/
23
	function procBoardInsertDocument()
24
	{
25
		// check grant
26
		if($this->module_info->module != "board")
27
		{
28
			return new Object(-1, "msg_invalid_request");
29
		}
30
		if(!$this->grant->write_document)
0 ignored issues
show
Bug introduced by
The property grant 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...
31
		{
32
			return new Object(-1, 'msg_not_permitted');
33
		}
34
		$logged_info = Context::get('logged_info');
35
36
		// setup variables
37
		$obj = Context::getRequestVars();
38
		$obj->module_srl = $this->module_srl;
39
		if($obj->is_notice!='Y'||!$this->grant->manager) $obj->is_notice = 'N';
40
		$obj->commentStatus = $obj->comment_status;
41
42
		$oModuleModel = getModel('module');
43
		$module_config = $oModuleModel->getModuleInfoByModuleSrl($obj->module_srl);
44 View Code Duplication
		if($module_config->mobile_use_editor === 'Y')
45
		{
46
			if(!isset($obj->use_editor)) $obj->use_editor = 'Y';
47
			if(!isset($obj->use_html)) $obj->use_html = 'Y';
48
		}
49
		else
50
		{
51
			if(!isset($obj->use_editor)) $obj->use_editor = 'N';
52
			if(!isset($obj->use_html)) $obj->use_html = 'N';
53
		}
54
55
		settype($obj->title, "string");
56 View Code Duplication
		if($obj->title == '') $obj->title = cut_str(trim(strip_tags(nl2br($obj->content))),20,'...');
57
		//setup dpcument title tp 'Untitled'
58
		if($obj->title == '') $obj->title = 'Untitled';
59
60
		// unset document style if the user is not the document manager
61
		if(!$this->grant->manager)
62
		{
63
			unset($obj->title_color);
64
			unset($obj->title_bold);
65
		}
66
67
		// generate document module model object
68
		$oDocumentModel = getModel('document');
69
70
		// generate document module의 controller object
71
		$oDocumentController = getController('document');
72
73
		// check if the document is existed
74
		$oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager);
75
76
		// update the document if it is existed
77
		$is_update = false;
78
		if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
79
		{
80
			$is_update = true;
81
		}
82
83
		// if use anonymous is true
84
		if($this->module_info->use_anonymous == 'Y')
85
		{
86
			$this->module_info->admin_mail = '';
87
			$obj->notify_message = 'N';
88
			if($is_update===false)
89
			{
90
				$obj->member_srl = -1*$logged_info->member_srl;
91
			}
92
			$obj->email_address = $obj->homepage = $obj->user_id = '';
93
			$obj->user_name = $obj->nick_name = 'anonymous';
94
			$bAnonymous = true;
95
			if($is_update===false)
96
			{
97
				$oDocument->add('member_srl', $obj->member_srl);
98
			}
99
		}
100
		else
101
		{
102
			$bAnonymous = false;
103
		}
104
105
		if($obj->is_secret == 'Y' || strtoupper($obj->status == 'SECRET'))
106
		{
107
			$use_status = explode('|@|', $this->module_info->use_status);
108
			if(!is_array($use_status) || !in_array('SECRET', $use_status))
109
			{
110
				unset($obj->is_secret);
111
				$obj->status = 'PUBLIC';
112
			}
113
		}
114
115
		// update the document if it is existed
116
		if($is_update)
117
		{
118
			if(!$oDocument->isGranted())
119
			{
120
				return new Object(-1,'msg_not_permitted');
121
			}
122
123
			if($this->module_info->use_anonymous == 'Y') {
124
				$obj->member_srl = abs($oDocument->get('member_srl')) * -1;
125
				$oDocument->add('member_srl', $obj->member_srl);
126
			}
127
128 View Code Duplication
			if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
129
			{
130
				return new Object(-1,'msg_protect_content');
131
			}
132
133
			if(!$this->grant->manager)
134
			{
135
				// notice & document style same as before if not manager
136
				$obj->is_notice = $oDocument->get('is_notice');
137
				$obj->title_color = $oDocument->get('title_color');
138
				$obj->title_bold = $oDocument->get('title_bold');
139
			}
140
			
141
			// modify list_order if document status is temp
142
			if($oDocument->get('status') == 'TEMP')
143
			{
144
				$obj->last_update = $obj->regdate = date('YmdHis');
145
				$obj->update_order = $obj->list_order = (getNextSequence() * -1);
146
			}
147
148
			$output = $oDocumentController->updateDocument($oDocument, $obj, true);
149
			$msg_code = 'success_updated';
150
151
		// insert a new document otherwise
152
		} else {
153
			$output = $oDocumentController->insertDocument($obj, $bAnonymous);
154
			$msg_code = 'success_registed';
155
			$obj->document_srl = $output->get('document_srl');
156
157
			// send an email to admin user
158
			if($output->toBool() && $this->module_info->admin_mail)
159
			{
160
				$oModuleModel = getModel('module');
161
				$member_config = $oModuleModel->getModuleConfig('member');
162
				
163
				$oMail = new Mail();
164
				$oMail->setTitle($obj->title);
165
				$oMail->setContent( sprintf("From : <a href=\"%s\">%s</a><br/>\r\n%s", getFullUrl('','document_srl',$obj->document_srl), getFullUrl('','document_srl',$obj->document_srl), $obj->content));
166
				$oMail->setSender($obj->user_name ? $obj->user_name : 'anonymous', $obj->email_address ? $obj->email_address : $member_config->webmaster_email);
167
168
				$target_mail = explode(',',$this->module_info->admin_mail);
169 View Code Duplication
				for($i=0;$i<count($target_mail);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
170
				{
171
					$email_address = trim($target_mail[$i]);
172
					if(!$email_address) continue;
173
					$oMail->setReceiptor($email_address, $email_address);
174
					$oMail->send();
175
				}
176
			}
177
		}
178
179
		// if there is an error
180
		if(!$output->toBool())
181
		{
182
			return $output;
183
		}
184
185
		// return the results
186
		$this->add('mid', Context::get('mid'));
187
		$this->add('document_srl', $output->get('document_srl'));
188
189
		// alert a message
190
		if(Context::get('xeVirtualRequestMethod') !== 'xml')
191
		{
192
			$this->setMessage($msg_code);
193
		}
194
	}
195
196
	/**
197
	 * @brief delete the document
198
	 **/
199
	function procBoardDeleteDocument()
200
	{
201
		// get the document_srl
202
		$document_srl = Context::get('document_srl');
203
204
		// if the document is not existed
205
		if(!$document_srl)
206
		{
207
			return $this->doError('msg_invalid_document');
0 ignored issues
show
Bug introduced by
The method doError() does not seem to exist on object<boardController>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
208
		}
209
210
		$oDocumentModel = &getModel('document');
211
		$oDocument = $oDocumentModel->getDocument($document_srl);
212
		// check protect content
213 View Code Duplication
		if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
214
		{
215
			return new Object(-1, 'msg_protect_content');
216
		}
217
218
		// generate document module controller object
219
		$oDocumentController = getController('document');
220
221
		// delete the document
222
		$output = $oDocumentController->deleteDocument($document_srl, $this->grant->manager);
223
		if(!$output->toBool())
224
		{
225
			return $output;
226
		}
227
228
		// alert an message
229
		$this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'page', Context::get('page'), 'document_srl', ''));
230
		$this->add('mid', Context::get('mid'));
231
		$this->add('page', Context::get('page'));
232
		if(Context::get('xeVirtualRequestMethod') !== 'xml')
233
		{
234
			$this->setMessage('success_deleted');
235
		}
236
	}
237
238
	/**
239
	 * @brief vote
240
	 **/
241
	function procBoardVoteDocument()
242
	{
243
		// generate document module controller object
244
		$oDocumentController = getController('document');
245
246
		$document_srl = Context::get('document_srl');
247
		return $oDocumentController->updateVotedCount($document_srl);
248
	}
249
250
	/**
251
	 * @brief insert comments
252
	 **/
253
	function procBoardInsertComment()
254
	{
255
		// check grant
256
		if(!$this->grant->write_comment)
257
		{
258
			return new Object(-1, 'msg_not_permitted');
259
		}
260
		$logged_info = Context::get('logged_info');
261
262
		// get the relevant data for inserting comment
263
		$obj = Context::getRequestVars();
264
		$obj->module_srl = $this->module_srl;
265
266
		if(!$this->module_info->use_status) $this->module_info->use_status = 'PUBLIC';
267
		if(!is_array($this->module_info->use_status))
268
		{
269
			$this->module_info->use_status = explode('|@|', $this->module_info->use_status);
270
		}
271
272
		if(in_array('SECRET', $this->module_info->use_status))
273
		{
274
			$this->module_info->secret = 'Y';
275
		}
276
		else
277
		{
278
			unset($obj->is_secret);
279
			$this->module_info->secret = 'N';
280
		}
281
282
		$oModuleModel = getModel('module');
283
		$module_config = $oModuleModel->getModuleInfoByModuleSrl($obj->module_srl);
284 View Code Duplication
		if($module_config->mobile_use_editor === 'Y')
285
		{
286
			if(!isset($obj->use_editor)) $obj->use_editor = 'Y';
287
			if(!isset($obj->use_html)) $obj->use_html = 'Y';
288
		}
289
		else
290
		{
291
			if(!isset($obj->use_editor)) $obj->use_editor = 'N';
292
			if(!isset($obj->use_html)) $obj->use_html = 'N';
293
		}
294
295
		// check if the doument is existed
296
		$oDocumentModel = getModel('document');
297
		$oDocument = $oDocumentModel->getDocument($obj->document_srl);
298
		if(!$oDocument->isExists())
299
		{
300
			return new Object(-1,'msg_not_founded');
301
		}
302
303
		// For anonymous use, remove writer's information and notifying information
304
		if($this->module_info->use_anonymous == 'Y')
305
		{
306
			$this->module_info->admin_mail = '';
307
			$obj->notify_message = 'N';
308
			$obj->member_srl = -1*$logged_info->member_srl;
309
			$obj->email_address = $obj->homepage = $obj->user_id = '';
310
			$obj->user_name = $obj->nick_name = 'anonymous';
311
			$bAnonymous = true;
312
		}
313
		else
314
		{
315
			$bAnonymous = false;
316
		}
317
318
		// generate comment  module model object
319
		$oCommentModel = getModel('comment');
320
321
		// generate comment module controller object
322
		$oCommentController = getController('comment');
323
324
		// check the comment is existed
325
		// if the comment is not existed, then generate a new sequence
326
		if(!$obj->comment_srl)
327
		{
328
			$obj->comment_srl = getNextSequence();
329
		} else {
330
			$comment = $oCommentModel->getComment($obj->comment_srl, $this->grant->manager);
331
		}
332
333
		// if comment_srl is not existed, then insert the comment
334
		if($comment->comment_srl != $obj->comment_srl)
335
		{
336
337
			// parent_srl is existed
338
			if($obj->parent_srl)
339
			{
340
				$parent_comment = $oCommentModel->getComment($obj->parent_srl);
341
				if(!$parent_comment->comment_srl)
342
				{
343
					return new Object(-1, 'msg_invalid_request');
344
				}
345
346
				$output = $oCommentController->insertComment($obj, $bAnonymous);
347
348
			// parent_srl is not existed
349
			} else {
350
				$output = $oCommentController->insertComment($obj, $bAnonymous);
351
			}
352
		// update the comment if it is not existed
353
		} else {
354
			// check the grant
355
			if(!$comment->isGranted())
0 ignored issues
show
Bug introduced by
The variable $comment 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...
356
			{
357
				return new Object(-1,'msg_not_permitted');
358
			}
359
360
			$obj->parent_srl = $comment->parent_srl;
361
			$output = $oCommentController->updateComment($obj, $this->grant->manager);
362
			$comment_srl = $obj->comment_srl;
0 ignored issues
show
Unused Code introduced by
$comment_srl 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...
363
		}
364
365
		if(!$output->toBool())
366
		{
367
			return $output;
368
		}
369
370
		if(Context::get('xeVirtualRequestMethod') !== 'xml')
371
		{
372
			$this->setMessage('success_registed');
373
		}
374
		$this->add('mid', Context::get('mid'));
375
		$this->add('document_srl', $obj->document_srl);
376
		$this->add('comment_srl', $obj->comment_srl);
377
	}
378
379
	/**
380
	 * @brief delete the comment
381
	 **/
382 View Code Duplication
	function procBoardDeleteComment()
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...
383
	{
384
		// get the comment_srl
385
		$comment_srl = Context::get('comment_srl');
386
		if(!$comment_srl)
387
		{
388
			return $this->doError('msg_invalid_request');
0 ignored issues
show
Bug introduced by
The method doError() does not seem to exist on object<boardController>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
389
		}
390
391
		// generate comment  controller object
392
		$oCommentController = getController('comment');
393
394
		$output = $oCommentController->deleteComment($comment_srl, $this->grant->manager);
395
		if(!$output->toBool())
396
		{
397
			return $output;
398
		}
399
400
		$this->add('mid', Context::get('mid'));
401
		$this->add('page', Context::get('page'));
402
		$this->add('document_srl', $output->get('document_srl'));
403
		if(Context::get('xeVirtualRequestMethod') !== 'xml')
404
		{
405
			$this->setMessage('success_deleted');
406
		}
407
	}
408
409
	/**
410
	 * @brief delete the tracjback
411
	 **/
412 View Code Duplication
	function procBoardDeleteTrackback()
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...
413
	{
414
		$trackback_srl = Context::get('trackback_srl');
415
416
		// generate trackback module controller object
417
		$oTrackbackController = getController('trackback');
418
419
		if(!$oTrackbackController) return;
420
421
		$output = $oTrackbackController->deleteTrackback($trackback_srl, $this->grant->manager);
0 ignored issues
show
Bug introduced by
The method deleteTrackback() does not seem to exist on object<ModuleObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
422
		if(!$output->toBool())
423
		{
424
			return $output;
425
		}
426
427
		$this->add('mid', Context::get('mid'));
428
		$this->add('page', Context::get('page'));
429
		$this->add('document_srl', $output->get('document_srl'));
430
		if(Context::get('xeVirtualRequestMethod') !== 'xml')
431
		{
432
			$this->setMessage('success_deleted');
433
		}
434
	}
435
436
	/**
437
	 * @brief check the password for document and comment
438
	 **/
439
	function procBoardVerificationPassword()
440
	{
441
		// get the id number of the document and the comment
442
		$password = Context::get('password');
443
		$document_srl = Context::get('document_srl');
444
		$comment_srl = Context::get('comment_srl');
445
446
		$oMemberModel = getModel('member');
447
448
		// if the comment exists
449
		if($comment_srl)
450
		{
451
			// get the comment information
452
			$oCommentModel = getModel('comment');
453
			$oComment = $oCommentModel->getComment($comment_srl);
454
			if(!$oComment->isExists())
455
			{
456
				return new Object(-1, 'msg_invalid_request');
457
			}
458
459
			// compare the comment password and the user input password
460
			if(!$oMemberModel->isValidPassword($oComment->get('password'),$password))
461
			{
462
				return new Object(-1, 'msg_invalid_password');
463
			}
464
465
			$oComment->setGrant();
466
		} else {
467
			 // get the document information
468
			$oDocumentModel = getModel('document');
469
			$oDocument = $oDocumentModel->getDocument($document_srl);
470
			if(!$oDocument->isExists())
471
			{
472
				return new Object(-1, 'msg_invalid_request');
473
			}
474
475
			// compare the document password and the user input password
476
			if(!$oMemberModel->isValidPassword($oDocument->get('password'),$password))
477
			{
478
				return new Object(-1, 'msg_invalid_password');
479
			}
480
481
			$oDocument->setGrant();
482
		}
483
	}
484
485
	/**
486
	 * @brief the trigger for displaying 'view document' link when click the user ID
487
	 **/
488
	function triggerMemberMenu(&$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...
489
	{
490
		$member_srl = Context::get('target_srl');
491
		$mid = Context::get('cur_mid');
492
493
		if(!$member_srl || !$mid)
494
		{
495
			return new Object();
496
		}
497
498
		$logged_info = Context::get('logged_info');
499
500
		// get the module information
501
		$oModuleModel = getModel('module');
502
		$columnList = array('module');
503
		$cur_module_info = $oModuleModel->getModuleInfoByMid($mid, 0, $columnList);
504
505
		if($cur_module_info->module != 'board')
506
		{
507
			return new Object();
508
		}
509
510
		// get the member information
511
		if($member_srl == $logged_info->member_srl)
512
		{
513
			$member_info = $logged_info;
514
		} else {
515
			$oMemberModel = getModel('member');
516
			$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
517
		}
518
519
		if(!$member_info->user_id)
520
		{
521
			return new Object();
522
		}
523
524
		//search
525
		$url = getUrl('','mid',$mid,'search_target','nick_name','search_keyword',$member_info->nick_name);
526
		$oMemberController = getController('member');
527
		$oMemberController->addMemberPopupMenu($url, 'cmd_view_own_document', '');
528
529
		return new Object();
530
	}
531
}
532