Conditions | 31 |
Paths | 15842 |
Total Lines | 156 |
Code Lines | 77 |
Lines | 11 |
Ratio | 7.05 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 | settype($obj->title, "string"); |
||
43 | if($obj->title == '') $obj->title = cut_str(trim(strip_tags(nl2br($obj->content))),20,'...'); |
||
44 | //setup dpcument title tp 'Untitled' |
||
45 | if($obj->title == '') $obj->title = 'Untitled'; |
||
46 | |||
47 | // unset document style if the user is not the document manager |
||
48 | if(!$this->grant->manager) |
||
49 | { |
||
50 | unset($obj->title_color); |
||
51 | unset($obj->title_bold); |
||
52 | } |
||
53 | |||
54 | // generate document module model object |
||
55 | $oDocumentModel = getModel('document'); |
||
56 | |||
57 | // generate document module의 controller object |
||
58 | $oDocumentController = getController('document'); |
||
59 | |||
60 | // check if the document is existed |
||
61 | $oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager); |
||
62 | |||
63 | // update the document if it is existed |
||
64 | $is_update = false; |
||
65 | if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl) |
||
66 | { |
||
67 | $is_update = true; |
||
68 | } |
||
69 | |||
70 | // if use anonymous is true |
||
71 | if($this->module_info->use_anonymous == 'Y') |
||
72 | { |
||
73 | $this->module_info->admin_mail = ''; |
||
74 | $obj->notify_message = 'N'; |
||
75 | if($is_update===false) |
||
76 | { |
||
77 | $obj->member_srl = -1*$logged_info->member_srl; |
||
78 | } |
||
79 | $obj->email_address = $obj->homepage = $obj->user_id = ''; |
||
80 | $obj->user_name = $obj->nick_name = 'anonymous'; |
||
81 | $bAnonymous = true; |
||
82 | if($is_update===false) |
||
83 | { |
||
84 | $oDocument->add('member_srl', $obj->member_srl); |
||
85 | } |
||
86 | } |
||
87 | else |
||
88 | { |
||
89 | $bAnonymous = false; |
||
90 | } |
||
91 | |||
92 | if($obj->is_secret == 'Y' || strtoupper($obj->status == 'SECRET')) |
||
93 | { |
||
94 | $use_status = explode('|@|', $this->module_info->use_status); |
||
95 | if(!is_array($use_status) || !in_array('SECRET', $use_status)) |
||
96 | { |
||
97 | unset($obj->is_secret); |
||
98 | $obj->status = 'PUBLIC'; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // update the document if it is existed |
||
103 | if($is_update) |
||
104 | { |
||
105 | if(!$oDocument->isGranted()) |
||
106 | { |
||
107 | return new Object(-1,'msg_not_permitted'); |
||
108 | } |
||
109 | |||
110 | if($this->module_info->use_anonymous == 'Y') { |
||
111 | $obj->member_srl = abs($oDocument->get('member_srl')) * -1; |
||
112 | $oDocument->add('member_srl', $obj->member_srl); |
||
113 | } |
||
114 | |||
115 | View Code Duplication | if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false) |
|
116 | { |
||
117 | return new Object(-1,'msg_protect_content'); |
||
118 | } |
||
119 | |||
120 | if(!$this->grant->manager) |
||
121 | { |
||
122 | // notice & document style same as before if not manager |
||
123 | $obj->is_notice = $oDocument->get('is_notice'); |
||
124 | $obj->title_color = $oDocument->get('title_color'); |
||
125 | $obj->title_bold = $oDocument->get('title_bold'); |
||
126 | } |
||
127 | |||
128 | // modify list_order if document status is temp |
||
129 | if($oDocument->get('status') == 'TEMP') |
||
130 | { |
||
131 | $obj->last_update = $obj->regdate = date('YmdHis'); |
||
132 | $obj->update_order = $obj->list_order = (getNextSequence() * -1); |
||
133 | } |
||
134 | |||
135 | $output = $oDocumentController->updateDocument($oDocument, $obj, true); |
||
136 | $msg_code = 'success_updated'; |
||
137 | |||
138 | // insert a new document otherwise |
||
139 | } else { |
||
140 | $output = $oDocumentController->insertDocument($obj, $bAnonymous); |
||
141 | $msg_code = 'success_registed'; |
||
142 | $obj->document_srl = $output->get('document_srl'); |
||
143 | |||
144 | // send an email to admin user |
||
145 | if($output->toBool() && $this->module_info->admin_mail) |
||
146 | { |
||
147 | $oMail = new Mail(); |
||
148 | $oMail->setTitle($obj->title); |
||
149 | $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)); |
||
150 | $oMail->setSender($obj->user_name, $obj->email_address); |
||
151 | |||
152 | $target_mail = explode(',',$this->module_info->admin_mail); |
||
153 | View Code Duplication | for($i=0;$i<count($target_mail);$i++) |
|
154 | { |
||
155 | $email_address = trim($target_mail[$i]); |
||
156 | if(!$email_address) continue; |
||
157 | $oMail->setReceiptor($email_address, $email_address); |
||
158 | $oMail->send(); |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | |||
163 | // if there is an error |
||
164 | if(!$output->toBool()) |
||
165 | { |
||
166 | return $output; |
||
167 | } |
||
168 | |||
169 | // return the results |
||
170 | $this->add('mid', Context::get('mid')); |
||
171 | $this->add('document_srl', $output->get('document_srl')); |
||
172 | |||
173 | // alert a message |
||
174 | if(Context::get('xeVirtualRequestMethod') !== 'xml') |
||
175 | { |
||
176 | $this->setMessage($msg_code); |
||
177 | } |
||
178 | } |
||
179 | |||
503 |
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.