| Conditions | 1 |
| Paths | 1 |
| Total Lines | 372 |
| Code Lines | 295 |
| 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 |
||
| 22 | public static function get_schema() { |
||
| 23 | $weight_unit = get_option( 'woocommerce_weight_unit' ); |
||
| 24 | $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
||
| 25 | $schema = array( |
||
| 26 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
||
| 27 | 'title' => 'product_variation', |
||
| 28 | 'type' => 'object', |
||
| 29 | 'properties' => array( |
||
| 30 | 'id' => array( |
||
| 31 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
||
| 32 | 'type' => 'integer', |
||
| 33 | 'context' => array( 'view', 'edit' ), |
||
| 34 | 'readonly' => true, |
||
| 35 | ), |
||
| 36 | 'name' => array( |
||
| 37 | 'description' => __( 'Product parent name.', 'woocommerce' ), |
||
| 38 | 'type' => 'string', |
||
| 39 | 'context' => array( 'view', 'edit' ), |
||
| 40 | ), |
||
| 41 | 'type' => array( |
||
| 42 | 'description' => __( 'Product type.', 'woocommerce' ), |
||
| 43 | 'type' => 'string', |
||
| 44 | 'default' => 'variation', |
||
| 45 | 'enum' => array( 'variation' ), |
||
| 46 | 'context' => array( 'view', 'edit' ), |
||
| 47 | ), |
||
| 48 | 'parent_id' => array( |
||
| 49 | 'description' => __( 'Product parent ID.', 'woocommerce' ), |
||
| 50 | 'type' => 'integer', |
||
| 51 | 'context' => array( 'view', 'edit' ), |
||
| 52 | ), |
||
| 53 | 'date_created' => array( |
||
| 54 | 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
||
| 55 | 'type' => 'date-time', |
||
| 56 | 'context' => array( 'view', 'edit' ), |
||
| 57 | 'readonly' => true, |
||
| 58 | ), |
||
| 59 | 'date_modified' => array( |
||
| 60 | 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
||
| 61 | 'type' => 'date-time', |
||
| 62 | 'context' => array( 'view', 'edit' ), |
||
| 63 | 'readonly' => true, |
||
| 64 | ), |
||
| 65 | 'description' => array( |
||
| 66 | 'description' => __( 'Variation description.', 'woocommerce' ), |
||
| 67 | 'type' => 'string', |
||
| 68 | 'context' => array( 'view', 'edit' ), |
||
| 69 | 'arg_options' => array( |
||
| 70 | 'sanitize_callback' => 'wp_filter_post_kses', |
||
| 71 | ), |
||
| 72 | ), |
||
| 73 | 'permalink' => array( |
||
| 74 | 'description' => __( 'Variation URL.', 'woocommerce' ), |
||
| 75 | 'type' => 'string', |
||
| 76 | 'format' => 'uri', |
||
| 77 | 'context' => array( 'view', 'edit' ), |
||
| 78 | 'readonly' => true, |
||
| 79 | ), |
||
| 80 | 'sku' => array( |
||
| 81 | 'description' => __( 'Unique identifier.', 'woocommerce' ), |
||
| 82 | 'type' => 'string', |
||
| 83 | 'context' => array( 'view', 'edit' ), |
||
| 84 | 'arg_options' => array( |
||
| 85 | 'sanitize_callback' => 'wc_clean', |
||
| 86 | ), |
||
| 87 | ), |
||
| 88 | 'price' => array( |
||
| 89 | 'description' => __( 'Current variation price.', 'woocommerce' ), |
||
| 90 | 'type' => 'string', |
||
| 91 | 'context' => array( 'view', 'edit' ), |
||
| 92 | 'readonly' => true, |
||
| 93 | ), |
||
| 94 | 'regular_price' => array( |
||
| 95 | 'description' => __( 'Variation regular price.', 'woocommerce' ), |
||
| 96 | 'type' => 'string', |
||
| 97 | 'context' => array( 'view', 'edit' ), |
||
| 98 | ), |
||
| 99 | 'sale_price' => array( |
||
| 100 | 'description' => __( 'Variation sale price.', 'woocommerce' ), |
||
| 101 | 'type' => 'string', |
||
| 102 | 'context' => array( 'view', 'edit' ), |
||
| 103 | ), |
||
| 104 | 'date_on_sale_from' => array( |
||
| 105 | 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 106 | 'type' => 'date-time', |
||
| 107 | 'context' => array( 'view', 'edit' ), |
||
| 108 | ), |
||
| 109 | 'date_on_sale_from_gmt' => array( |
||
| 110 | 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
||
| 111 | 'type' => 'date-time', |
||
| 112 | 'context' => array( 'view', 'edit' ), |
||
| 113 | ), |
||
| 114 | 'date_on_sale_to' => array( |
||
| 115 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 116 | 'type' => 'date-time', |
||
| 117 | 'context' => array( 'view', 'edit' ), |
||
| 118 | ), |
||
| 119 | 'date_on_sale_to_gmt' => array( |
||
| 120 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 121 | 'type' => 'date-time', |
||
| 122 | 'context' => array( 'view', 'edit' ), |
||
| 123 | ), |
||
| 124 | 'on_sale' => array( |
||
| 125 | 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
||
| 126 | 'type' => 'boolean', |
||
| 127 | 'context' => array( 'view', 'edit' ), |
||
| 128 | 'readonly' => true, |
||
| 129 | ), |
||
| 130 | 'status' => array( |
||
| 131 | 'description' => __( 'Variation status.', 'woocommerce' ), |
||
| 132 | 'type' => 'string', |
||
| 133 | 'default' => 'publish', |
||
| 134 | 'enum' => array_keys( get_post_statuses() ), |
||
| 135 | 'context' => array( 'view', 'edit' ), |
||
| 136 | ), |
||
| 137 | 'purchasable' => array( |
||
| 138 | 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
||
| 139 | 'type' => 'boolean', |
||
| 140 | 'context' => array( 'view', 'edit' ), |
||
| 141 | 'readonly' => true, |
||
| 142 | ), |
||
| 143 | 'virtual' => array( |
||
| 144 | 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
||
| 145 | 'type' => 'boolean', |
||
| 146 | 'default' => false, |
||
| 147 | 'context' => array( 'view', 'edit' ), |
||
| 148 | ), |
||
| 149 | 'downloadable' => array( |
||
| 150 | 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
||
| 151 | 'type' => 'boolean', |
||
| 152 | 'default' => false, |
||
| 153 | 'context' => array( 'view', 'edit' ), |
||
| 154 | ), |
||
| 155 | 'downloads' => array( |
||
| 156 | 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
||
| 157 | 'type' => 'array', |
||
| 158 | 'context' => array( 'view', 'edit' ), |
||
| 159 | 'items' => array( |
||
| 160 | 'type' => 'object', |
||
| 161 | 'properties' => array( |
||
| 162 | 'id' => array( |
||
| 163 | 'description' => __( 'File ID.', 'woocommerce' ), |
||
| 164 | 'type' => 'string', |
||
| 165 | 'context' => array( 'view', 'edit' ), |
||
| 166 | ), |
||
| 167 | 'name' => array( |
||
| 168 | 'description' => __( 'File name.', 'woocommerce' ), |
||
| 169 | 'type' => 'string', |
||
| 170 | 'context' => array( 'view', 'edit' ), |
||
| 171 | ), |
||
| 172 | 'file' => array( |
||
| 173 | 'description' => __( 'File URL.', 'woocommerce' ), |
||
| 174 | 'type' => 'string', |
||
| 175 | 'context' => array( 'view', 'edit' ), |
||
| 176 | ), |
||
| 177 | ), |
||
| 178 | ), |
||
| 179 | ), |
||
| 180 | 'download_limit' => array( |
||
| 181 | 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
||
| 182 | 'type' => 'integer', |
||
| 183 | 'default' => -1, |
||
| 184 | 'context' => array( 'view', 'edit' ), |
||
| 185 | ), |
||
| 186 | 'download_expiry' => array( |
||
| 187 | 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
||
| 188 | 'type' => 'integer', |
||
| 189 | 'default' => -1, |
||
| 190 | 'context' => array( 'view', 'edit' ), |
||
| 191 | ), |
||
| 192 | 'tax_status' => array( |
||
| 193 | 'description' => __( 'Tax status.', 'woocommerce' ), |
||
| 194 | 'type' => 'string', |
||
| 195 | 'default' => 'taxable', |
||
| 196 | 'enum' => array( 'taxable', 'shipping', 'none' ), |
||
| 197 | 'context' => array( 'view', 'edit' ), |
||
| 198 | ), |
||
| 199 | 'tax_class' => array( |
||
| 200 | 'description' => __( 'Tax class.', 'woocommerce' ), |
||
| 201 | 'type' => 'string', |
||
| 202 | 'context' => array( 'view', 'edit' ), |
||
| 203 | ), |
||
| 204 | 'manage_stock' => array( |
||
| 205 | 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
||
| 206 | 'type' => 'boolean', |
||
| 207 | 'default' => false, |
||
| 208 | 'context' => array( 'view', 'edit' ), |
||
| 209 | ), |
||
| 210 | 'stock_quantity' => array( |
||
| 211 | 'description' => __( 'Stock quantity.', 'woocommerce' ), |
||
| 212 | 'type' => 'integer', |
||
| 213 | 'context' => array( 'view', 'edit' ), |
||
| 214 | ), |
||
| 215 | 'stock_status' => array( |
||
| 216 | 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
||
| 217 | 'type' => 'string', |
||
| 218 | 'default' => 'instock', |
||
| 219 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
||
| 220 | 'context' => array( 'view', 'edit' ), |
||
| 221 | ), |
||
| 222 | 'backorders' => array( |
||
| 223 | 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
||
| 224 | 'type' => 'string', |
||
| 225 | 'default' => 'no', |
||
| 226 | 'enum' => array( 'no', 'notify', 'yes' ), |
||
| 227 | 'context' => array( 'view', 'edit' ), |
||
| 228 | ), |
||
| 229 | 'backorders_allowed' => array( |
||
| 230 | 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
||
| 231 | 'type' => 'boolean', |
||
| 232 | 'context' => array( 'view', 'edit' ), |
||
| 233 | 'readonly' => true, |
||
| 234 | ), |
||
| 235 | 'backordered' => array( |
||
| 236 | 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
||
| 237 | 'type' => 'boolean', |
||
| 238 | 'context' => array( 'view', 'edit' ), |
||
| 239 | 'readonly' => true, |
||
| 240 | ), |
||
| 241 | 'weight' => array( |
||
| 242 | /* translators: %s: weight unit */ |
||
| 243 | 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
||
|
|
|||
| 244 | 'type' => 'string', |
||
| 245 | 'context' => array( 'view', 'edit' ), |
||
| 246 | ), |
||
| 247 | 'dimensions' => array( |
||
| 248 | 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
||
| 249 | 'type' => 'object', |
||
| 250 | 'context' => array( 'view', 'edit' ), |
||
| 251 | 'properties' => array( |
||
| 252 | 'length' => array( |
||
| 253 | /* translators: %s: dimension unit */ |
||
| 254 | 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 255 | 'type' => 'string', |
||
| 256 | 'context' => array( 'view', 'edit' ), |
||
| 257 | ), |
||
| 258 | 'width' => array( |
||
| 259 | /* translators: %s: dimension unit */ |
||
| 260 | 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 261 | 'type' => 'string', |
||
| 262 | 'context' => array( 'view', 'edit' ), |
||
| 263 | ), |
||
| 264 | 'height' => array( |
||
| 265 | /* translators: %s: dimension unit */ |
||
| 266 | 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 267 | 'type' => 'string', |
||
| 268 | 'context' => array( 'view', 'edit' ), |
||
| 269 | ), |
||
| 270 | ), |
||
| 271 | ), |
||
| 272 | 'shipping_class' => array( |
||
| 273 | 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
||
| 274 | 'type' => 'string', |
||
| 275 | 'context' => array( 'view', 'edit' ), |
||
| 276 | ), |
||
| 277 | 'shipping_class_id' => array( |
||
| 278 | 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
||
| 279 | 'type' => 'string', |
||
| 280 | 'context' => array( 'view', 'edit' ), |
||
| 281 | 'readonly' => true, |
||
| 282 | ), |
||
| 283 | 'image' => array( |
||
| 284 | 'description' => __( 'Variation image data.', 'woocommerce' ), |
||
| 285 | 'type' => 'object', |
||
| 286 | 'context' => array( 'view', 'edit' ), |
||
| 287 | 'properties' => array( |
||
| 288 | 'id' => array( |
||
| 289 | 'description' => __( 'Image ID.', 'woocommerce' ), |
||
| 290 | 'type' => 'integer', |
||
| 291 | 'context' => array( 'view', 'edit' ), |
||
| 292 | ), |
||
| 293 | 'date_created' => array( |
||
| 294 | 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
||
| 295 | 'type' => 'date-time', |
||
| 296 | 'context' => array( 'view', 'edit' ), |
||
| 297 | 'readonly' => true, |
||
| 298 | ), |
||
| 299 | 'date_created_gmt' => array( |
||
| 300 | 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
||
| 301 | 'type' => 'date-time', |
||
| 302 | 'context' => array( 'view', 'edit' ), |
||
| 303 | 'readonly' => true, |
||
| 304 | ), |
||
| 305 | 'date_modified' => array( |
||
| 306 | 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
||
| 307 | 'type' => 'date-time', |
||
| 308 | 'context' => array( 'view', 'edit' ), |
||
| 309 | 'readonly' => true, |
||
| 310 | ), |
||
| 311 | 'date_modified_gmt' => array( |
||
| 312 | 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
||
| 313 | 'type' => 'date-time', |
||
| 314 | 'context' => array( 'view', 'edit' ), |
||
| 315 | 'readonly' => true, |
||
| 316 | ), |
||
| 317 | 'src' => array( |
||
| 318 | 'description' => __( 'Image URL.', 'woocommerce' ), |
||
| 319 | 'type' => 'string', |
||
| 320 | 'format' => 'uri', |
||
| 321 | 'context' => array( 'view', 'edit' ), |
||
| 322 | ), |
||
| 323 | 'name' => array( |
||
| 324 | 'description' => __( 'Image name.', 'woocommerce' ), |
||
| 325 | 'type' => 'string', |
||
| 326 | 'context' => array( 'view', 'edit' ), |
||
| 327 | ), |
||
| 328 | 'alt' => array( |
||
| 329 | 'description' => __( 'Image alternative text.', 'woocommerce' ), |
||
| 330 | 'type' => 'string', |
||
| 331 | 'context' => array( 'view', 'edit' ), |
||
| 332 | ), |
||
| 333 | ), |
||
| 334 | ), |
||
| 335 | 'attributes' => array( |
||
| 336 | 'description' => __( 'List of attributes.', 'woocommerce' ), |
||
| 337 | 'type' => 'array', |
||
| 338 | 'context' => array( 'view', 'edit' ), |
||
| 339 | 'items' => array( |
||
| 340 | 'type' => 'object', |
||
| 341 | 'properties' => array( |
||
| 342 | 'id' => array( |
||
| 343 | 'description' => __( 'Attribute ID.', 'woocommerce' ), |
||
| 344 | 'type' => 'integer', |
||
| 345 | 'context' => array( 'view', 'edit' ), |
||
| 346 | ), |
||
| 347 | 'name' => array( |
||
| 348 | 'description' => __( 'Attribute name.', 'woocommerce' ), |
||
| 349 | 'type' => 'string', |
||
| 350 | 'context' => array( 'view', 'edit' ), |
||
| 351 | ), |
||
| 352 | 'option' => array( |
||
| 353 | 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
||
| 354 | 'type' => 'string', |
||
| 355 | 'context' => array( 'view', 'edit' ), |
||
| 356 | ), |
||
| 357 | ), |
||
| 358 | ), |
||
| 359 | ), |
||
| 360 | 'menu_order' => array( |
||
| 361 | 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
||
| 362 | 'type' => 'integer', |
||
| 363 | 'context' => array( 'view', 'edit' ), |
||
| 364 | ), |
||
| 365 | 'meta_data' => array( |
||
| 366 | 'description' => __( 'Meta data.', 'woocommerce' ), |
||
| 367 | 'type' => 'array', |
||
| 368 | 'context' => array( 'view', 'edit' ), |
||
| 369 | 'items' => array( |
||
| 370 | 'type' => 'object', |
||
| 371 | 'properties' => array( |
||
| 372 | 'id' => array( |
||
| 373 | 'description' => __( 'Meta ID.', 'woocommerce' ), |
||
| 374 | 'type' => 'integer', |
||
| 375 | 'context' => array( 'view', 'edit' ), |
||
| 376 | 'readonly' => true, |
||
| 377 | ), |
||
| 378 | 'key' => array( |
||
| 379 | 'description' => __( 'Meta key.', 'woocommerce' ), |
||
| 380 | 'type' => 'string', |
||
| 381 | 'context' => array( 'view', 'edit' ), |
||
| 382 | ), |
||
| 383 | 'value' => array( |
||
| 384 | 'description' => __( 'Meta value.', 'woocommerce' ), |
||
| 385 | 'type' => 'mixed', |
||
| 386 | 'context' => array( 'view', 'edit' ), |
||
| 387 | ), |
||
| 388 | ), |
||
| 389 | ), |
||
| 390 | ), |
||
| 391 | ), |
||
| 392 | ); |
||
| 393 | return $schema; |
||
| 394 | } |
||
| 681 |