| 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 |
||
| 59 | public function __get( $key ) { |
||
| 60 | _doing_it_wrong( $key, 'Coupon properties should not be accessed directly.', '2.7' ); |
||
| 61 | |||
| 62 | switch ( $key ) { |
||
| 63 | case 'id' : |
||
| 64 | $value = $this->get_id(); |
||
| 65 | break; |
||
| 66 | case 'exists' : |
||
| 67 | $value = ( $this->get_id() > 0 ) ? true : false; |
||
| 68 | break; |
||
| 69 | case 'coupon_custom_fields' : |
||
| 70 | $legacy_custom_fields = array(); |
||
| 71 | $custom_fields = $this->get_id() ? $this->get_meta_data() : array(); |
||
| 72 | if ( ! empty( $custom_fields ) ) { |
||
| 73 | foreach ( $custom_fields as $cf_value ) { |
||
| 74 | // legacy only supports 1 key |
||
| 75 | $legacy_custom_fields[ $cf_value->key ][0] = $cf_value->value; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | $value = $legacy_custom_fields; |
||
| 79 | break; |
||
| 80 | case 'type' : |
||
| 81 | case 'discount_type' : |
||
| 82 | $value = $this->get_discount_type(); |
||
| 83 | break; |
||
| 84 | case 'amount' : |
||
| 85 | $value = $this->get_amount(); |
||
| 86 | break; |
||
| 87 | case 'code' : |
||
| 88 | $value = $this->get_code(); |
||
| 89 | break; |
||
| 90 | case 'individual_use' : |
||
| 91 | $value = ( true === $this->get_individual_use() ) ? 'yes' : 'no'; |
||
| 92 | break; |
||
| 93 | case 'product_ids' : |
||
| 94 | $value = $this->get_product_ids(); |
||
| 95 | break; |
||
| 96 | case 'exclude_product_ids' : |
||
| 97 | $value = $this->get_excluded_product_ids(); |
||
| 98 | break; |
||
| 99 | case 'usage_limit' : |
||
| 100 | $value = $this->get_usage_limit(); |
||
| 101 | break; |
||
| 102 | case 'usage_limit_per_user' : |
||
| 103 | $value = $this->get_usage_limit_per_user(); |
||
| 104 | break; |
||
| 105 | case 'limit_usage_to_x_items' : |
||
| 106 | $value = $this->get_limit_usage_to_x_items(); |
||
| 107 | break; |
||
| 108 | case 'usage_count' : |
||
| 109 | $value = $this->get_usage_count(); |
||
| 110 | break; |
||
| 111 | case 'expiry_date' : |
||
| 112 | $value = $this->get_expiry_date(); |
||
| 113 | break; |
||
| 114 | case 'product_categories' : |
||
| 115 | $value = $this->get_product_categories(); |
||
| 116 | break; |
||
| 117 | case 'exclude_product_categories' : |
||
| 118 | $value = $this->get_excluded_product_categories(); |
||
| 119 | break; |
||
| 120 | case 'minimum_amount' : |
||
| 121 | $value = $this->get_minimum_amount(); |
||
| 122 | break; |
||
| 123 | case 'maximum_amount' : |
||
| 124 | $value = $this->get_maximum_amount(); |
||
| 125 | break; |
||
| 126 | case 'customer_email' : |
||
| 127 | $value = $this->get_email_restrictions(); |
||
| 128 | break; |
||
| 129 | default : |
||
| 130 | $value = ''; |
||
| 131 | break; |
||
| 132 | } |
||
| 133 | |||
| 134 | return $value; |
||
| 135 | } |
||
| 136 | |||
| 185 |
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.