| Conditions | 11 |
| Paths | 256 |
| Total Lines | 138 |
| Code Lines | 66 |
| 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 |
||
| 59 | function give_run_install() { |
||
| 60 | |||
| 61 | $give_options = give_get_settings(); |
||
| 62 | |||
| 63 | // Setup the Give Custom Post Types. |
||
| 64 | give_setup_post_types(); |
||
| 65 | |||
| 66 | // Clear the permalinks. |
||
| 67 | flush_rewrite_rules( false ); |
||
| 68 | |||
| 69 | // Add Upgraded From Option. |
||
| 70 | $current_version = get_option( 'give_version' ); |
||
| 71 | if ( $current_version ) { |
||
| 72 | update_option( 'give_version_upgraded_from', $current_version ); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Setup some default options. |
||
| 76 | $options = array(); |
||
| 77 | |||
| 78 | // Checks if the Success Page option exists AND that the page exists. |
||
| 79 | if ( ! get_post( give_get_option( 'success_page' ) ) ) { |
||
| 80 | |||
| 81 | // Donation Confirmation (Success) Page |
||
| 82 | $success = wp_insert_post( |
||
| 83 | array( |
||
| 84 | 'post_title' => esc_html__( 'Donation Confirmation', 'give' ), |
||
| 85 | 'post_content' => '[give_receipt]', |
||
| 86 | 'post_status' => 'publish', |
||
| 87 | 'post_author' => 1, |
||
| 88 | 'post_type' => 'page', |
||
| 89 | 'comment_status' => 'closed' |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | |||
| 93 | // Store our page IDs |
||
| 94 | $options['success_page'] = $success; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Checks if the Failure Page option exists AND that the page exists. |
||
| 98 | if ( ! get_post( give_get_option( 'failure_page' ) ) ) { |
||
| 99 | |||
| 100 | // Failed Donation Page |
||
| 101 | $failed = wp_insert_post( |
||
| 102 | array( |
||
| 103 | 'post_title' => esc_html__( 'Donation Failed', 'give' ), |
||
| 104 | 'post_content' => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ), |
||
| 105 | 'post_status' => 'publish', |
||
| 106 | 'post_author' => 1, |
||
| 107 | 'post_type' => 'page', |
||
| 108 | 'comment_status' => 'closed' |
||
| 109 | ) |
||
| 110 | ); |
||
| 111 | |||
| 112 | $options['failure_page'] = $failed; |
||
| 113 | } |
||
| 114 | |||
| 115 | // Checks if the History Page option exists AND that the page exists. |
||
| 116 | if ( ! get_post( give_get_option( 'history_page' ) ) ) { |
||
| 117 | // Donation History Page |
||
| 118 | $history = wp_insert_post( |
||
| 119 | array( |
||
| 120 | 'post_title' => esc_html__( 'Donation History', 'give' ), |
||
| 121 | 'post_content' => '[donation_history]', |
||
| 122 | 'post_status' => 'publish', |
||
| 123 | 'post_author' => 1, |
||
| 124 | 'post_type' => 'page', |
||
| 125 | 'comment_status' => 'closed' |
||
| 126 | ) |
||
| 127 | ); |
||
| 128 | |||
| 129 | $options['history_page'] = $history; |
||
| 130 | } |
||
| 131 | |||
| 132 | //Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency. |
||
| 133 | if ( empty( $current_version ) ) { |
||
| 134 | $options = array_merge( $options, give_get_default_settings() ); |
||
| 135 | } |
||
| 136 | |||
| 137 | // Populate the default values. |
||
| 138 | update_option( 'give_settings', array_merge( $give_options, $options ) ); |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Run plugin upgrades. |
||
| 142 | * |
||
| 143 | * @since 1.8 |
||
| 144 | */ |
||
| 145 | do_action( 'give_upgrades' ); |
||
| 146 | |||
| 147 | |||
| 148 | if( GIVE_VERSION !== get_option( 'give_version' ) ) { |
||
| 149 | update_option( 'give_version', GIVE_VERSION ); |
||
| 150 | } |
||
| 151 | |||
| 152 | // Create Give roles. |
||
| 153 | $roles = new Give_Roles(); |
||
| 154 | $roles->add_roles(); |
||
| 155 | $roles->add_caps(); |
||
| 156 | |||
| 157 | $api = new Give_API(); |
||
| 158 | update_option( 'give_default_api_version', 'v' . $api->get_version() ); |
||
| 159 | |||
| 160 | // Create the customers databases. |
||
| 161 | @Give()->customers->create_table(); |
||
| 162 | @Give()->customer_meta->create_table(); |
||
| 163 | |||
| 164 | // Check for PHP Session support, and enable if available. |
||
| 165 | Give()->session->use_php_sessions(); |
||
| 166 | |||
| 167 | // Add a temporary option to note that Give pages have been created. |
||
| 168 | set_transient( '_give_installed', $options, 30 ); |
||
| 169 | |||
| 170 | if ( ! $current_version ) { |
||
| 171 | |||
| 172 | require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
||
| 173 | |||
| 174 | // When new upgrade routines are added, mark them as complete on fresh install. |
||
| 175 | $upgrade_routines = array( |
||
| 176 | 'upgrade_give_user_caps_cleanup', |
||
| 177 | 'upgrade_give_payment_customer_id', |
||
| 178 | 'upgrade_give_offline_status', |
||
| 179 | 'v18_upgrades_core_setting', |
||
| 180 | 'v18_upgrades_form_metadata' |
||
| 181 | ); |
||
| 182 | |||
| 183 | foreach ( $upgrade_routines as $upgrade ) { |
||
| 184 | give_set_upgrade_complete( $upgrade ); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | // Bail if activating from network, or bulk. |
||
| 189 | if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
||
| 190 | return; |
||
| 191 | } |
||
| 192 | |||
| 193 | // Add the transient to redirect. |
||
| 194 | set_transient( '_give_activation_redirect', true, 30 ); |
||
| 195 | |||
| 196 | } |
||
| 197 | |||
| 400 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.