Conditions | 4 |
Paths | 3 |
Total Lines | 55 |
Code Lines | 40 |
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 |
||
195 | public static function makeDonationForm($about) |
||
196 | { |
||
197 | $donationform = [ |
||
198 | 0 => '<form name="donation" id="donation" action="https://xoops.org/modules/xdonations/" method="post" onsubmit="return xoopsFormValidate_donation();">', |
||
199 | 1 => '<table class="outer" cellspacing="1" width="100%"><tbody><tr><th colspan="2">' |
||
200 | . \_AM_MODULEBUILDER_ABOUT_MAKE_DONATION |
||
201 | . '</th></tr><tr align="left" valign="top"><td class="head"><div class="xoops-form-element-caption-required"><span class="caption-text">' |
||
202 | . \_AM_MODULEBUILDER_DONATION_AMOUNT |
||
203 | . '</span><span class="caption-marker">*</span></div></td><td class="even"><select size="1" name="item[A][amount]" id="item[A][amount]" title="Donation Amount"><option value="5">5.00 EUR</option><option value="10">10.00 EUR</option><option value="20">20.00 EUR</option><option value="40">40.00 EUR</option><option value="60">60.00 EUR</option><option value="80">80.00 EUR</option><option value="90">90.00 EUR</option><option value="100">100.00 EUR</option><option value="200">200.00 EUR</option></select></td></tr><tr align="left" valign="top"><td class="head"></td><td class="even"><input class="formButton" name="submit" id="submit" value="' |
||
204 | . \_SUBMIT |
||
205 | . '" title="' |
||
206 | . \_SUBMIT |
||
207 | . '" type="submit"></td></tr></tbody></table>', |
||
208 | 2 => '<input name="op" id="op" value="createinvoice" type="hidden"><input name="plugin" id="plugin" value="donations" type="hidden"><input name="donation" id="donation" value="1" type="hidden"><input name="drawfor" id="drawfor" value="Chronolabs Co-Operative" type="hidden"><input name="drawto" id="drawto" value="%s" type="hidden"><input name="drawto_email" id="drawto_email" value="%s" type="hidden"><input name="key" id="key" value="%s" type="hidden"><input name="currency" id="currency" value="EUR" type="hidden"><input name="weight_unit" id="weight_unit" value="kgs" type="hidden"><input name="item[A][cat]" id="item[A][cat]" value="XDN%s" type="hidden"><input name="item[A][name]" id="item[A][name]" value="Donation for %s" type="hidden"><input name="item[A][quantity]" id="item[A][quantity]" value="1" type="hidden"><input name="item[A][shipping]" id="item[A][shipping]" value="0" type="hidden"><input name="item[A][handling]" id="item[A][handling]" value="0" type="hidden"><input name="item[A][weight]" id="item[A][weight]" value="0" type="hidden"><input name="item[A][tax]" id="item[A][tax]" value="0" type="hidden"><input name="return" id="return" value="https://xoops.org/modules/xdonations/success.php" type="hidden"><input name="cancel" id="cancel" value="https://xoops.org/modules/xdonations/success.php" type="hidden"></form>', |
||
209 | 'D' => '', |
||
210 | 3 => '', |
||
211 | 4 => '<!-- Start Form Validation JavaScript //--> |
||
212 | <script type="text/javascript"> |
||
213 | <!--// |
||
214 | function xoopsFormValidate_donation() { var myform = window.document.donation; |
||
215 | var hasSelected = false; var selectBox = myform.item[A][amount];for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true && selectBox.options[i].value != \'\') { hasSelected = true; break; } }if (!hasSelected) { window.alert("Please enter Donation Amount"); selectBox.focus(); return false; }return true; |
||
216 | } |
||
217 | //--></script> |
||
218 | <!-- End Form Validation JavaScript //-->', |
||
219 | ]; |
||
220 | $paypalform = [ |
||
221 | 0 => '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">', |
||
222 | 1 => '<input name="cmd" value="_s-xclick" type="hidden">', |
||
223 | 2 => '<input name="hosted_button_id" value="%s" type="hidden">', |
||
224 | 3 => '<img alt="" src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" height="1" border="0" width="1">', |
||
225 | 4 => '<input src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" border="0" type="image">', |
||
226 | 5 => '</form>', |
||
227 | ]; |
||
228 | for ($key = 0; $key <= 4; ++$key) { |
||
229 | switch ($key) { |
||
230 | case 2: |
||
231 | $donationform[$key] = \sprintf( |
||
232 | $donationform[$key], |
||
233 | $GLOBALS['xoopsConfig']['sitename'] . ' - ' . ('' != $GLOBALS['xoopsUser']->getVar('name') ? $GLOBALS['xoopsUser']->getVar('name') . ' [' . $GLOBALS['xoopsUser']->getVar('uname') . ']' : $GLOBALS['xoopsUser']->getVar('uname')), |
||
234 | $GLOBALS['xoopsUser']->getVar('email'), |
||
235 | \XOOPS_LICENSE_KEY, |
||
236 | \mb_strtoupper($GLOBALS['xoopsModule']->getVar('dirname')), |
||
237 | \mb_strtoupper($GLOBALS['xoopsModule']->getVar('dirname')) . ' ' . $GLOBALS['xoopsModule']->getVar('name') |
||
238 | ); |
||
239 | break; |
||
240 | } |
||
241 | } |
||
242 | $aboutRes = ''; |
||
243 | $istart = \mb_strpos($about, $paypalform[0], 1); |
||
244 | $iend = \mb_strpos($about, $paypalform[5], $istart + 1) + mb_strlen($paypalform[5]) - 1; |
||
245 | $aboutRes .= \mb_substr($about, 0, $istart - 1); |
||
246 | $aboutRes .= \implode("\n", $donationform); |
||
247 | $aboutRes .= \mb_substr($about, $iend + 1, mb_strlen($about) - $iend - 1); |
||
248 | |||
249 | return $aboutRes; |
||
250 | } |
||
262 |