| Conditions | 1 |
| Paths | 1 |
| Total Lines | 102 |
| 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 |
||
| 110 | public static function create_variation_product() { |
||
| 111 | $product = new WC_Product_Variable(); |
||
| 112 | $product->set_props( |
||
| 113 | [ |
||
| 114 | 'name' => 'Dummy Variable Product', |
||
| 115 | 'sku' => 'DUMMY VARIABLE SKU', |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | |||
| 119 | $attributes = []; |
||
| 120 | |||
| 121 | $attribute = new WC_Product_Attribute(); |
||
| 122 | $attribute_data = self::create_attribute( 'size', [ 'small', 'large', 'huge' ] ); |
||
| 123 | $attribute->set_id( $attribute_data['attribute_id'] ); |
||
| 124 | $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
||
| 125 | $attribute->set_options( $attribute_data['term_ids'] ); |
||
| 126 | $attribute->set_position( 1 ); |
||
| 127 | $attribute->set_visible( true ); |
||
| 128 | $attribute->set_variation( true ); |
||
| 129 | $attributes[] = $attribute; |
||
| 130 | |||
| 131 | $attribute = new WC_Product_Attribute(); |
||
| 132 | $attribute_data = self::create_attribute( 'colour', [ 'red', 'blue' ] ); |
||
| 133 | $attribute->set_id( $attribute_data['attribute_id'] ); |
||
| 134 | $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
||
| 135 | $attribute->set_options( $attribute_data['term_ids'] ); |
||
| 136 | $attribute->set_position( 1 ); |
||
| 137 | $attribute->set_visible( true ); |
||
| 138 | $attribute->set_variation( true ); |
||
| 139 | $attributes[] = $attribute; |
||
| 140 | |||
| 141 | $attribute = new WC_Product_Attribute(); |
||
| 142 | $attribute_data = self::create_attribute( 'number', [ '0', '1', '2' ] ); |
||
| 143 | $attribute->set_id( $attribute_data['attribute_id'] ); |
||
| 144 | $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
||
| 145 | $attribute->set_options( $attribute_data['term_ids'] ); |
||
| 146 | $attribute->set_position( 1 ); |
||
| 147 | $attribute->set_visible( true ); |
||
| 148 | $attribute->set_variation( true ); |
||
| 149 | $attributes[] = $attribute; |
||
| 150 | |||
| 151 | $product->set_attributes( $attributes ); |
||
| 152 | $product->save(); |
||
| 153 | |||
| 154 | $variation_1 = new WC_Product_Variation(); |
||
| 155 | $variation_1->set_props( |
||
| 156 | [ |
||
| 157 | 'parent_id' => $product->get_id(), |
||
| 158 | 'sku' => 'DUMMY SKU VARIABLE SMALL', |
||
| 159 | 'regular_price' => 10, |
||
| 160 | ] |
||
| 161 | ); |
||
| 162 | $variation_1->set_attributes( [ 'pa_size' => 'small' ] ); |
||
| 163 | $variation_1->save(); |
||
| 164 | |||
| 165 | $variation_2 = new WC_Product_Variation(); |
||
| 166 | $variation_2->set_props( |
||
| 167 | [ |
||
| 168 | 'parent_id' => $product->get_id(), |
||
| 169 | 'sku' => 'DUMMY SKU VARIABLE LARGE', |
||
| 170 | 'regular_price' => 15, |
||
| 171 | ] |
||
| 172 | ); |
||
| 173 | $variation_2->set_attributes( [ 'pa_size' => 'large' ] ); |
||
| 174 | $variation_2->save(); |
||
| 175 | |||
| 176 | $variation_3 = new WC_Product_Variation(); |
||
| 177 | $variation_3->set_props( |
||
| 178 | [ |
||
| 179 | 'parent_id' => $product->get_id(), |
||
| 180 | 'sku' => 'DUMMY SKU VARIABLE HUGE RED 0', |
||
| 181 | 'regular_price' => 16, |
||
| 182 | ] |
||
| 183 | ); |
||
| 184 | $variation_3->set_attributes( |
||
| 185 | [ |
||
| 186 | 'pa_size' => 'huge', |
||
| 187 | 'pa_colour' => 'red', |
||
| 188 | 'pa_number' => '0', |
||
| 189 | ] |
||
| 190 | ); |
||
| 191 | $variation_3->save(); |
||
| 192 | |||
| 193 | $variation_4 = new WC_Product_Variation(); |
||
| 194 | $variation_4->set_props( |
||
| 195 | [ |
||
| 196 | 'parent_id' => $product->get_id(), |
||
| 197 | 'sku' => 'DUMMY SKU VARIABLE HUGE RED 2', |
||
| 198 | 'regular_price' => 17, |
||
| 199 | ] |
||
| 200 | ); |
||
| 201 | $variation_4->set_attributes( |
||
| 202 | [ |
||
| 203 | 'pa_size' => 'huge', |
||
| 204 | 'pa_colour' => 'red', |
||
| 205 | 'pa_number' => '2', |
||
| 206 | ] |
||
| 207 | ); |
||
| 208 | $variation_4->save(); |
||
| 209 | |||
| 210 | return wc_get_product( $product->get_id() ); |
||
| 211 | } |
||
| 212 | |||
| 354 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.