Conditions | 10 |
Paths | 108 |
Total Lines | 80 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
114 | public function ipn() |
||
115 | { |
||
116 | $raw_post_data = file_get_contents('php://input'); |
||
117 | $raw_post_array = explode('&', $raw_post_data); |
||
118 | $myPost = array(); |
||
119 | foreach ($raw_post_array as $keyval) |
||
120 | { |
||
121 | $keyval = explode ('=', $keyval); |
||
122 | if (count($keyval) == 2) |
||
123 | { |
||
124 | $myPost[$keyval[0]] = urldecode($keyval[1]); |
||
125 | } |
||
126 | } |
||
127 | // read the post from PayPal system and add 'cmd' |
||
128 | $req = 'cmd=_notify-validate'; |
||
129 | if (function_exists('get_magic_quotes_gpc')) |
||
130 | { |
||
131 | $get_magic_quotes_exists = true; |
||
132 | } |
||
133 | foreach ($myPost as $key => $value) |
||
134 | { |
||
135 | if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) |
||
136 | { |
||
137 | $value = urlencode(stripslashes($value)); |
||
138 | } |
||
139 | else |
||
140 | { |
||
141 | $value = urlencode($value); |
||
142 | } |
||
143 | $req .= "&$key=$value"; |
||
144 | } |
||
145 | |||
146 | $sql = 'SELECT paypal_sandbox |
||
147 | FROM ' . $this->table_config; |
||
148 | $result = $this->db->sql_query($sql); |
||
149 | $row = $this->db->sql_fetchrow($result); |
||
150 | |||
151 | $paypal_url = ($row['paypal_sandbox'] == 1) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; |
||
152 | |||
153 | $ch = curl_init($paypal_url); |
||
154 | if ($ch == false) |
||
155 | { |
||
156 | return false; |
||
157 | } |
||
158 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
||
159 | curl_setopt($ch, CURLOPT_POST, 1); |
||
160 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); |
||
161 | curl_setopt($ch, CURLOPT_POSTFIELDS, $req); |
||
162 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
||
163 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
||
164 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); |
||
165 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
||
166 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); |
||
167 | $res = curl_exec($ch); |
||
168 | curl_close($ch); |
||
169 | |||
170 | // Inspect IPN validation result and act accordingly |
||
171 | // Split response headers and payload, a better way for strcmp |
||
172 | $tokens = explode("\r\n\r\n", trim($res)); |
||
173 | $res = trim(end($tokens)); |
||
174 | if (strcmp($res, 'VERIFIED') == 0) |
||
175 | { |
||
176 | $sql_data = array( |
||
177 | 'user_id' => (int) $this->request->variable('custom', '0'), |
||
178 | 'item_id' => (int) $this->request->variable('item_number', '0'), |
||
179 | 'item_name' => $this->request->variable('item_number', '', true), |
||
180 | 'donation_time' => time(), |
||
181 | 'donation_amount' => $this->request->variable('mc_gross', '0'), |
||
182 | ); |
||
183 | |||
184 | $sql = 'INSERT INTO ' . $this->table_donations . ' |
||
185 | ' . $this->db->sql_build_array('INSERT', $sql_data); |
||
186 | $this->db->sql_query($sql); |
||
187 | } |
||
188 | |||
189 | $headers = array( |
||
190 | 'Content-Type' => 'application/xml; charset=UTF-8', |
||
191 | ); |
||
192 | return new Response('', '200', $headers); |
||
193 | } |
||
194 | |||
227 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..