| Conditions | 26 |
| Paths | 26 |
| Total Lines | 77 |
| Code Lines | 70 |
| 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 |
||
| 43 | public function __get( $key ) { |
||
| 44 | _doing_it_wrong( $key, 'Coupon properties should not be accessed directly.', '2.7' ); |
||
| 45 | |||
| 46 | switch( $key ) { |
||
| 47 | case 'id' : |
||
| 48 | $value = $this->get_id(); |
||
| 49 | break; |
||
| 50 | case 'exists' : |
||
| 51 | $value = ( $this->get_id() > 0 ) ? true : false; |
||
| 52 | break; |
||
| 53 | case 'coupon_custom_fields' : |
||
| 54 | $legacy_custom_fields = array(); |
||
| 55 | $custom_fields = $this->get_id() ? $this->get_meta_data() : array(); |
||
| 56 | if ( ! empty( $custom_fields ) ) { |
||
| 57 | foreach ( $custom_fields as $cf_value ) { |
||
| 58 | // legacy only supports 1 key |
||
| 59 | $legacy_custom_fields[ $cf_value->key ][0] = $cf_value->value; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | $value = $legacy_custom_fields; |
||
| 63 | break; |
||
| 64 | case 'type' : |
||
| 65 | case 'discount_type' : |
||
| 66 | $value = $this->get_discount_type(); |
||
| 67 | break; |
||
| 68 | case 'amount' : |
||
| 69 | $value = $this->get_amount(); |
||
| 70 | break; |
||
| 71 | case 'code' : |
||
| 72 | $value = $this->get_code(); |
||
| 73 | break; |
||
| 74 | case 'individual_use' : |
||
| 75 | $value = ( true === $this->get_individual_use() ) ? 'yes' : 'no'; |
||
| 76 | break; |
||
| 77 | case 'product_ids' : |
||
| 78 | $value = $this->get_product_ids(); |
||
| 79 | break; |
||
| 80 | case 'exclude_product_ids' : |
||
| 81 | $value = $this->get_excluded_product_ids(); |
||
| 82 | break; |
||
| 83 | case 'usage_limit' : |
||
| 84 | $value = $this->get_usage_limit(); |
||
| 85 | break; |
||
| 86 | case 'usage_limit_per_user' : |
||
| 87 | $value = $this->get_usage_limit_per_user(); |
||
| 88 | break; |
||
| 89 | case 'limit_usage_to_x_items' : |
||
| 90 | $value = $this->get_limit_usage_to_x_items(); |
||
| 91 | break; |
||
| 92 | case 'usage_count' : |
||
| 93 | $value = $this->get_usage_count(); |
||
| 94 | break; |
||
| 95 | case 'expiry_date' : |
||
| 96 | $value = $this->get_expiry_date(); |
||
| 97 | break; |
||
| 98 | case 'product_categories' : |
||
| 99 | $value = $this->get_product_categories(); |
||
| 100 | break; |
||
| 101 | case 'exclude_product_categories' : |
||
| 102 | $value = $this->get_excluded_product_categories(); |
||
| 103 | break; |
||
| 104 | case 'minimum_amount' : |
||
| 105 | $value = $this->get_minimum_amount(); |
||
| 106 | break; |
||
| 107 | case 'maximum_amount' : |
||
| 108 | $value = $this->get_maximum_amount(); |
||
| 109 | break; |
||
| 110 | case 'customer_email' : |
||
| 111 | $value = $this->get_email_restrictions(); |
||
| 112 | break; |
||
| 113 | default : |
||
| 114 | $value = ''; |
||
| 115 | break; |
||
| 116 | } |
||
| 117 | |||
| 118 | return $value; |
||
| 119 | } |
||
| 120 | |||
| 170 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.