| Conditions | 17 |
| Paths | 1025 |
| Total Lines | 86 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 53 | public function check_plugin_settings() |
||
| 54 | { |
||
| 55 | if (!pg_wc_is_screen_correct()) { |
||
| 56 | return; |
||
| 57 | } |
||
| 58 | if ($this->settings['enabled'] !== 'yes') { |
||
| 59 | WC_Admin_Notices::add_custom_notice( |
||
| 60 | PAGANTIS_PLUGIN_ID, |
||
| 61 | sprintf( |
||
| 62 | // translators: 1: URL to WP plugin page. |
||
| 63 | __('Activate Pagantis to start offering comfortable payments in installments to your clients. <a class="button button-primary" href="%1$s">Activate Pagantis now!</a>', 'pagantis'), |
||
| 64 | pg_wc_get_pagantis_admin_url() |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($this->settings['pagantis_public_key'] === '' xor $this->settings['pagantis_private_key'] === '' |
||
| 70 | || $this->settings['enabled'] === 'yes' |
||
| 71 | ) { |
||
| 72 | WC_Admin_Notices::add_custom_notice( |
||
| 73 | PAGANTIS_PLUGIN_ID.'keys_setup', |
||
| 74 | sprintf( |
||
| 75 | // translators: 1: URL to WP plugin page. |
||
| 76 | __('Set your Pagantis merchant keys to start offering comfortable payments in installments <a class="button button-primary" href="%1$s">Go to keys setup</a></p>', 'pagantis'), |
||
| 77 | pg_wc_get_pagantis_admin_url() |
||
| 78 | ) |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | if ($this->settings['pagantis_public_key'] === '' xor $this->settings['pagantis_private_key'] === '') { |
||
| 84 | WC_Admin_Notices::add_custom_notice( |
||
| 85 | PAGANTIS_PLUGIN_ID, |
||
| 86 | sprintf( |
||
| 87 | // translators: 1: URL to WP plugin page. |
||
| 88 | __('Check your Pagantis merchant keys to start offering Pagantis as a payment method . <a class="button button-primary" href="%1$s">Go to keys setup</a>', 'pagantis'), |
||
| 89 | pg_wc_get_pagantis_admin_url() |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($this->settings['pagantis_public_key'] === '' || $this->settings['pagantis_private_key'] === '') { |
||
| 95 | WC_Admin_Notices::add_custom_notice( |
||
| 96 | PAGANTIS_PLUGIN_ID.'keys_error', |
||
| 97 | sprintf( |
||
| 98 | // translators: 1: URL to WP plugin page. |
||
| 99 | __('Set your Pagantis merchant Api keys to start offering comfortable payments in installments. <a class="button button-primary" href="%1$s">Go to keys setup.</a>', 'pagantis'), |
||
| 100 | pg_wc_get_pagantis_admin_url() |
||
| 101 | ) |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($this->settings['pagantis_public_key'] !== '' xor $this->settings['pagantis_private_key'] !== '') { |
||
| 106 | WC_Admin_Notices::remove_notice(PAGANTIS_PLUGIN_ID.'keys_setup'); |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($this->settings['pagantis_public_key'] !== '' || $this->settings['pagantis_private_key'] !== '') { |
||
| 110 | WC_Admin_Notices::remove_notice(PAGANTIS_PLUGIN_ID.'keys_error'); |
||
| 111 | } |
||
| 112 | |||
| 113 | if (! in_array(get_woocommerce_currency(), $this->allowed_currencies, true)) { |
||
| 114 | WC_Admin_Settings::add_error(__('Error: Pagantis only can be used in Euros.', 'pagantis')); |
||
| 115 | $this->settings['enabled'] = 'no'; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] < '2' |
||
| 119 | || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] > '12' |
||
| 120 | ) { |
||
| 121 | $this->settings['enabled'] = 'no'; |
||
| 122 | |||
| 123 | WC_Admin_Settings::add_error(__( |
||
| 124 | 'Error: Pagantis can be used up to 12 installments please contact your account manager', |
||
| 125 | 'pagantis' |
||
| 126 | )); |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] < '2' |
||
| 130 | || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] > '12' |
||
| 131 | ) { |
||
| 132 | WC_Admin_Settings::add_error(__( |
||
| 133 | 'Error: Pagantis can be used from 2 installments please contact your account manager', |
||
| 134 | 'pagantis' |
||
| 135 | )); |
||
| 136 | } |
||
| 137 | if ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] < 0) { |
||
| 138 | WC_Admin_Settings::add_error(__('Error: Pagantis can not be used for free products', 'pagantis')); |
||
| 139 | } |
||
| 142 |