Conditions | 23 |
Paths | 4680 |
Total Lines | 146 |
Code Lines | 85 |
Lines | 0 |
Ratio | 0 % |
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 |
||
20 | function procPollInsert() |
||
21 | { |
||
22 | $stop_date = Context::get('stop_date'); |
||
23 | if($stop_date < date('Ymd')) |
||
24 | { |
||
25 | $stop_date = date('YmdHis', $_SERVER['REQUEST_TIME']+60*60*24*365); |
||
26 | } |
||
27 | |||
28 | $logged_info = Context::get('logged_info'); |
||
29 | $vars = Context::getRequestVars(); |
||
30 | $args = new stdClass; |
||
31 | $tmp_args = array(); |
||
32 | |||
33 | unset($vars->_filter); |
||
34 | unset($vars->error_return_url); |
||
35 | unset($vars->stop_date); |
||
36 | |||
37 | foreach($vars as $key => $val) |
||
38 | { |
||
39 | if(stripos($key, 'tidx')) |
||
40 | { |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | $tmp_arr = explode('_', $key); |
||
45 | |||
46 | $poll_index = $tmp_arr[1]; |
||
47 | if(!$poll_index) |
||
48 | { |
||
49 | continue; |
||
50 | } |
||
51 | |||
52 | if(!trim($val)) |
||
53 | { |
||
54 | continue; |
||
55 | } |
||
56 | |||
57 | if($tmp_args[$poll_index] == NULL) |
||
58 | { |
||
59 | $tmp_args[$poll_index] = new stdClass; |
||
60 | } |
||
61 | |||
62 | if(!is_array($tmp_args[$poll_index]->item)) |
||
63 | { |
||
64 | $tmp_args[$poll_index]->item = array(); |
||
65 | } |
||
66 | |||
67 | if($logged_info->is_admin != 'Y') |
||
68 | { |
||
69 | $val = htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
||
70 | } |
||
71 | |||
72 | switch($tmp_arr[0]) |
||
73 | { |
||
74 | case 'title': |
||
75 | $tmp_args[$poll_index]->title = $val; |
||
76 | break; |
||
77 | case 'checkcount': |
||
78 | $tmp_args[$poll_index]->checkcount = $val; |
||
79 | break; |
||
80 | case 'item': |
||
81 | $tmp_args[$poll_index]->item[] = $val; |
||
82 | break; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | foreach($tmp_args as $key => $val) |
||
87 | { |
||
88 | if(!$val->checkcount) |
||
89 | { |
||
90 | $val->checkcount = 1; |
||
91 | } |
||
92 | |||
93 | if($val->title && count($val->item)) |
||
94 | { |
||
95 | $args->poll[] = $val; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if(!count($args->poll)) return new Object(-1, 'cmd_null_item'); |
||
100 | |||
101 | $args->stop_date = $stop_date; |
||
102 | |||
103 | // Configure the variables |
||
104 | $poll_srl = getNextSequence(); |
||
105 | $member_srl = $logged_info->member_srl?$logged_info->member_srl:0; |
||
106 | |||
107 | $oDB = &DB::getInstance(); |
||
108 | $oDB->begin(); |
||
109 | |||
110 | // Register the poll |
||
111 | $poll_args = new stdClass; |
||
112 | $poll_args->poll_srl = $poll_srl; |
||
113 | $poll_args->member_srl = $member_srl; |
||
114 | $poll_args->list_order = $poll_srl*-1; |
||
115 | $poll_args->stop_date = $args->stop_date; |
||
116 | $poll_args->poll_count = 0; |
||
117 | $output = executeQuery('poll.insertPoll', $poll_args); |
||
118 | if(!$output->toBool()) |
||
119 | { |
||
120 | $oDB->rollback(); |
||
121 | return $output; |
||
122 | } |
||
123 | |||
124 | // Individual poll registration |
||
125 | foreach($args->poll as $key => $val) |
||
126 | { |
||
127 | $title_args = new stdClass; |
||
128 | $title_args->poll_srl = $poll_srl; |
||
129 | $title_args->poll_index_srl = getNextSequence(); |
||
130 | $title_args->title = $val->title; |
||
131 | $title_args->checkcount = $val->checkcount; |
||
132 | $title_args->poll_count = 0; |
||
133 | $title_args->list_order = $title_args->poll_index_srl * -1; |
||
134 | $title_args->member_srl = $member_srl; |
||
135 | $title_args->upload_target_srl = $upload_target_srl; |
||
|
|||
136 | $output = executeQuery('poll.insertPollTitle', $title_args); |
||
137 | if(!$output->toBool()) |
||
138 | { |
||
139 | $oDB->rollback(); |
||
140 | return $output; |
||
141 | } |
||
142 | |||
143 | // Add the individual survey items |
||
144 | foreach($val->item as $k => $v) |
||
145 | { |
||
146 | $item_args = new stdClass; |
||
147 | $item_args->poll_srl = $poll_srl; |
||
148 | $item_args->poll_index_srl = $title_args->poll_index_srl; |
||
149 | $item_args->title = $v; |
||
150 | $item_args->poll_count = 0; |
||
151 | $item_args->upload_target_srl = $upload_target_srl; |
||
152 | $output = executeQuery('poll.insertPollItem', $item_args); |
||
153 | if(!$output->toBool()) |
||
154 | { |
||
155 | $oDB->rollback(); |
||
156 | return $output; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | $oDB->commit(); |
||
162 | |||
163 | $this->add('poll_srl', $poll_srl); |
||
164 | $this->setMessage('success_registed'); |
||
165 | } |
||
166 | |||
421 |
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.