Conditions | 38 |
Paths | > 20000 |
Total Lines | 172 |
Code Lines | 87 |
Lines | 22 |
Ratio | 12.79 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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) |
||
|
|||
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++) |
|
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 | |||
532 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: