| Conditions | 11 |
| Paths | 58 |
| Total Lines | 46 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 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 |
||
| 84 | public static function activate() { |
||
| 85 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
||
| 86 | |||
| 87 | if ( ! isset( $_POST['license'] ) || empty( $_POST['license'] ) ) { |
||
| 88 | wp_die( __( 'Oops! You forgot to enter your license number.', 'formidable' ) ); |
||
| 89 | } |
||
| 90 | |||
| 91 | $license = stripslashes( sanitize_text_field( $_POST['license'] ) ); |
||
|
1 ignored issue
–
show
|
|||
| 92 | $plugin_slug = sanitize_text_field( $_POST['plugin'] ); |
||
| 93 | $this_plugin = self::get_addon( $plugin_slug ); |
||
| 94 | update_option( $this_plugin->option_name . 'key', $license ); |
||
| 95 | |||
| 96 | $response = array( 'success' => false, 'message' => '' ); |
||
| 97 | try { |
||
| 98 | $license_data = $this_plugin->send_mothership_request( 'activate_license', $license ); |
||
| 99 | |||
| 100 | // $license_data->license will be either "valid" or "invalid" |
||
| 101 | $is_valid = 'invalid'; |
||
| 102 | if ( is_array( $license_data ) ) { |
||
| 103 | if ( $license_data['license'] == 'valid' ) { |
||
|
1 ignored issue
–
show
|
|||
| 104 | $is_valid = $license_data['license']; |
||
| 105 | $response['message'] = __( 'Enjoy!', 'formidable' ); |
||
| 106 | $response['success'] = true; |
||
| 107 | } else if ( $license_data['license'] == 'invalid' ) { |
||
|
1 ignored issue
–
show
|
|||
| 108 | $response['message'] = __( 'That license is invalid', 'formidable' ); |
||
| 109 | } |
||
| 110 | } else if ( $license_data == 'expired' ) { |
||
|
1 ignored issue
–
show
|
|||
| 111 | $response['message'] = __( 'That license is expired', 'formidable' ); |
||
| 112 | } else if ( $license_data == 'no_activations_left' ) { |
||
|
1 ignored issue
–
show
|
|||
| 113 | $response['message'] = __( 'That license has been used too many times', 'formidable' ); |
||
| 114 | } else if ( $license_data == 'invalid_item_id' ) { |
||
|
1 ignored issue
–
show
|
|||
| 115 | $response['message'] = __( 'Opps! That is the wrong license number for this plugin.', 'formidable' ); |
||
| 116 | } else if ( $license_data == 'missing' ) { |
||
|
1 ignored issue
–
show
|
|||
| 117 | $response['message'] = __( 'That license is invalid', 'formidable' ); |
||
| 118 | } else { |
||
| 119 | $response['message'] = FrmAppHelper::kses( $license_data, array('a') ); |
||
| 120 | } |
||
| 121 | |||
| 122 | update_option( $this_plugin->option_name . 'active', $is_valid ); |
||
| 123 | } catch ( Exception $e ) { |
||
| 124 | $response['message'] = $e->getMessage(); |
||
| 125 | } |
||
| 126 | |||
| 127 | echo json_encode( $response ); |
||
| 128 | wp_die(); |
||
| 129 | } |
||
| 130 | |||
| 204 |