| Conditions | 10 |
| Paths | 9 |
| Total Lines | 43 |
| Code Lines | 30 |
| 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 namespace EmailLog\License; |
||
| 85 | public function activate() { |
||
| 86 | $response = $this->edd_api->activate_license( $this->get_license_key(), $this->get_addon_name() ); |
||
| 87 | |||
| 88 | if ( $response->success && 'valid' === $response->license ) { |
||
| 89 | return $response; |
||
| 90 | } |
||
| 91 | |||
| 92 | switch ( $response->error ) { |
||
| 93 | case 'expired': |
||
| 94 | $message = sprintf( |
||
| 95 | __( 'Your license key expired on %s.' ), |
||
| 96 | date_i18n( get_option( 'date_format' ), strtotime( $response->expires, current_time( 'timestamp' ) ) ) |
||
| 97 | ); |
||
| 98 | break; |
||
| 99 | |||
| 100 | case 'revoked': |
||
| 101 | $message = __( 'Your license key has been disabled.' ); |
||
| 102 | break; |
||
| 103 | |||
| 104 | case 'missing': |
||
| 105 | $message = __( 'Your license key is invalid.' ); |
||
| 106 | break; |
||
| 107 | |||
| 108 | case 'invalid': |
||
| 109 | case 'site_inactive': |
||
| 110 | $message = __( 'Your license is not active for this URL.' ); |
||
| 111 | break; |
||
| 112 | |||
| 113 | case 'item_name_mismatch': |
||
| 114 | $message = sprintf( __( 'Your license key is not valid for %s.' ), $this->get_addon_name() ); |
||
| 115 | break; |
||
| 116 | |||
| 117 | case 'no_activations_left': |
||
| 118 | $message = __( 'Your license key has reached its activation limit.' ); |
||
| 119 | break; |
||
| 120 | |||
| 121 | default: |
||
| 122 | $message = __( 'An error occurred, please try again.' ); |
||
| 123 | break; |
||
| 124 | } |
||
| 125 | |||
| 126 | throw new \Exception( $message ); |
||
| 127 | } |
||
| 128 | |||
| 168 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.