| 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 |
||
| 12 | public static function register() |
||
| 13 | { |
||
| 14 | Blade::directive('paystack', function () { |
||
| 15 | |||
| 16 | $fallback_email = "\'" . Config::get('paystack-lite.customer_fallback_email') . "\'"; |
||
| 17 | $public_key = "\'" . Config::get('paystack-lite.public_key') . "\'"; |
||
| 18 | $paystack_js = '<script src="' . Config::get('paystack-lite.paystack_inline_js') . '"></script>'; |
||
| 19 | $script_open = "<script>"; |
||
| 20 | $script_closed = "</script>"; |
||
| 21 | |||
| 22 | return "<?php |
||
| 23 | echo ' |
||
| 24 | $paystack_js |
||
| 25 | |||
| 26 | $script_open |
||
| 27 | function payWithPaystack(amount, email, meta, callback, onclose) { |
||
| 28 | var meta_data = meta ? meta : {}; |
||
| 29 | var options = { |
||
| 30 | key: $public_key, |
||
| 31 | email: email, |
||
| 32 | amount: amount+\'00\', |
||
| 33 | metadata: meta, |
||
| 34 | callback: function(response){ |
||
| 35 | callback(response); |
||
| 36 | }, |
||
| 37 | onClose:function(){ |
||
| 38 | if(onclose){ |
||
| 39 | onclose(); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | }; |
||
| 43 | |||
| 44 | //check if email is valide else fallback |
||
| 45 | if(!Boolean(options.email)){ |
||
| 46 | options.email = $fallback_email; |
||
| 47 | }else{ |
||
| 48 | if(!validateEmail(email)){ |
||
| 49 | options.email = $fallback_email; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | var handler = PaystackPop.setup(options); |
||
| 54 | handler.openIframe(); |
||
| 55 | } |
||
| 56 | |||
| 57 | function validateEmail(email) { |
||
| 58 | 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,}))$/; |
||
| 59 | return re.test(email); |
||
| 60 | } |
||
| 61 | |||
| 62 | $script_closed |
||
| 63 | '; |
||
| 64 | ?>"; |
||
| 65 | }); |
||
| 66 | } |
||
| 67 | } |
||
| 68 |