| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| 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 | private static function paystackPopupCheckout() |
||
| 21 | { |
||
| 22 | Blade::directive('paystack', function () { |
||
| 23 | |||
| 24 | $fallback_email = "\'" . Config::get('paystack-lite.customer_fallback_email') . "\'"; |
||
| 25 | $public_key = "\'" . Config::get('paystack-lite.public_key') . "\'"; |
||
| 26 | $paystack_js = '<script src="' . Config::get('paystack-lite.paystack_inline_js') . '"></script>'; |
||
| 27 | $script_open = "<script>"; |
||
| 28 | $script_closed = "</script>"; |
||
| 29 | |||
| 30 | return "<?php |
||
| 31 | echo ' |
||
| 32 | $paystack_js |
||
| 33 | |||
| 34 | $script_open |
||
| 35 | function payWithPaystack(amount, email, meta, callback, onclose) { |
||
| 36 | var meta_data = meta ? meta : {}; |
||
| 37 | var options = { |
||
| 38 | key: $public_key, |
||
| 39 | email: email, |
||
| 40 | amount: amount+\'00\', |
||
| 41 | metadata: meta, |
||
| 42 | callback: function(response){ |
||
| 43 | callback(response); |
||
| 44 | }, |
||
| 45 | onClose:function(){ |
||
| 46 | if(onclose){ |
||
| 47 | onclose(); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | }; |
||
| 51 | |||
| 52 | //check if email is valide else fallback |
||
| 53 | if(!Boolean(options.email)){ |
||
| 54 | options.email = $fallback_email; |
||
| 55 | }else{ |
||
| 56 | if(!validateEmail(email)){ |
||
| 57 | options.email = $fallback_email; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | var handler = PaystackPop.setup(options); |
||
| 62 | handler.openIframe(); |
||
| 63 | } |
||
| 64 | |||
| 65 | function validateEmail(email) { |
||
| 66 | var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
||
| 67 | return re.test(email); |
||
| 68 | } |
||
| 69 | |||
| 70 | $script_closed |
||
| 71 | '; |
||
| 72 | ?>"; |
||
| 73 | }); |
||
| 74 | } |
||
| 75 | |||
| 133 |
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.