| Conditions | 1 |
| Paths | 1 |
| Total Lines | 196 |
| Code Lines | 155 |
| 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 |
||
| 201 | public function get_item_schema() { |
||
| 202 | $schema = array( |
||
| 203 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
||
| 204 | 'title' => $this->post_type, |
||
| 205 | 'type' => 'object', |
||
| 206 | 'properties' => array( |
||
| 207 | 'id' => array( |
||
| 208 | 'description' => __( 'Unique identifier for the object.', 'woocommerce-rest-api' ), |
||
| 209 | 'type' => 'integer', |
||
| 210 | 'context' => array( 'view', 'edit' ), |
||
| 211 | 'readonly' => true, |
||
| 212 | ), |
||
| 213 | 'code' => array( |
||
| 214 | 'description' => __( 'Coupon code.', 'woocommerce-rest-api' ), |
||
| 215 | 'type' => 'string', |
||
| 216 | 'context' => array( 'view', 'edit' ), |
||
| 217 | 'required' => true, |
||
| 218 | ), |
||
| 219 | 'amount' => array( |
||
| 220 | 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce-rest-api' ), |
||
| 221 | 'type' => 'string', |
||
| 222 | 'context' => array( 'view', 'edit' ), |
||
| 223 | ), |
||
| 224 | 'date_created' => array( |
||
| 225 | 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce-rest-api' ), |
||
| 226 | 'type' => 'date-time', |
||
| 227 | 'context' => array( 'view', 'edit' ), |
||
| 228 | 'readonly' => true, |
||
| 229 | ), |
||
| 230 | 'date_created_gmt' => array( |
||
| 231 | 'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce-rest-api' ), |
||
| 232 | 'type' => 'date-time', |
||
| 233 | 'context' => array( 'view', 'edit' ), |
||
| 234 | 'readonly' => true, |
||
| 235 | ), |
||
| 236 | 'date_modified' => array( |
||
| 237 | 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce-rest-api' ), |
||
| 238 | 'type' => 'date-time', |
||
| 239 | 'context' => array( 'view', 'edit' ), |
||
| 240 | 'readonly' => true, |
||
| 241 | ), |
||
| 242 | 'date_modified_gmt' => array( |
||
| 243 | 'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce-rest-api' ), |
||
| 244 | 'type' => 'date-time', |
||
| 245 | 'context' => array( 'view', 'edit' ), |
||
| 246 | 'readonly' => true, |
||
| 247 | ), |
||
| 248 | 'discount_type' => array( |
||
| 249 | 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce-rest-api' ), |
||
| 250 | 'type' => 'string', |
||
| 251 | 'default' => 'fixed_cart', |
||
| 252 | 'enum' => array_keys( wc_get_coupon_types() ), |
||
| 253 | 'context' => array( 'view', 'edit' ), |
||
| 254 | ), |
||
| 255 | 'description' => array( |
||
| 256 | 'description' => __( 'Coupon description.', 'woocommerce-rest-api' ), |
||
| 257 | 'type' => 'string', |
||
| 258 | 'context' => array( 'view', 'edit' ), |
||
| 259 | ), |
||
| 260 | 'date_expires' => array( |
||
| 261 | 'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce-rest-api' ), |
||
| 262 | 'type' => 'string', |
||
| 263 | 'context' => array( 'view', 'edit' ), |
||
| 264 | ), |
||
| 265 | 'date_expires_gmt' => array( |
||
| 266 | 'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce-rest-api' ), |
||
| 267 | 'type' => 'string', |
||
| 268 | 'context' => array( 'view', 'edit' ), |
||
| 269 | ), |
||
| 270 | 'usage_count' => array( |
||
| 271 | 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce-rest-api' ), |
||
| 272 | 'type' => 'integer', |
||
| 273 | 'context' => array( 'view', 'edit' ), |
||
| 274 | 'readonly' => true, |
||
| 275 | ), |
||
| 276 | 'individual_use' => array( |
||
| 277 | 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce-rest-api' ), |
||
| 278 | 'type' => 'boolean', |
||
| 279 | 'default' => false, |
||
| 280 | 'context' => array( 'view', 'edit' ), |
||
| 281 | ), |
||
| 282 | 'product_ids' => array( |
||
| 283 | 'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce-rest-api' ), |
||
| 284 | 'type' => 'array', |
||
| 285 | 'items' => array( |
||
| 286 | 'type' => 'integer', |
||
| 287 | ), |
||
| 288 | 'context' => array( 'view', 'edit' ), |
||
| 289 | ), |
||
| 290 | 'excluded_product_ids' => array( |
||
| 291 | 'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce-rest-api' ), |
||
| 292 | 'type' => 'array', |
||
| 293 | 'items' => array( |
||
| 294 | 'type' => 'integer', |
||
| 295 | ), |
||
| 296 | 'context' => array( 'view', 'edit' ), |
||
| 297 | ), |
||
| 298 | 'usage_limit' => array( |
||
| 299 | 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce-rest-api' ), |
||
| 300 | 'type' => 'integer', |
||
| 301 | 'context' => array( 'view', 'edit' ), |
||
| 302 | ), |
||
| 303 | 'usage_limit_per_user' => array( |
||
| 304 | 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce-rest-api' ), |
||
| 305 | 'type' => 'integer', |
||
| 306 | 'context' => array( 'view', 'edit' ), |
||
| 307 | ), |
||
| 308 | 'limit_usage_to_x_items' => array( |
||
| 309 | 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce-rest-api' ), |
||
| 310 | 'type' => 'integer', |
||
| 311 | 'context' => array( 'view', 'edit' ), |
||
| 312 | ), |
||
| 313 | 'free_shipping' => array( |
||
| 314 | 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce-rest-api' ), |
||
| 315 | 'type' => 'boolean', |
||
| 316 | 'default' => false, |
||
| 317 | 'context' => array( 'view', 'edit' ), |
||
| 318 | ), |
||
| 319 | 'product_categories' => array( |
||
| 320 | 'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce-rest-api' ), |
||
| 321 | 'type' => 'array', |
||
| 322 | 'items' => array( |
||
| 323 | 'type' => 'integer', |
||
| 324 | ), |
||
| 325 | 'context' => array( 'view', 'edit' ), |
||
| 326 | ), |
||
| 327 | 'excluded_product_categories' => array( |
||
| 328 | 'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce-rest-api' ), |
||
| 329 | 'type' => 'array', |
||
| 330 | 'items' => array( |
||
| 331 | 'type' => 'integer', |
||
| 332 | ), |
||
| 333 | 'context' => array( 'view', 'edit' ), |
||
| 334 | ), |
||
| 335 | 'exclude_sale_items' => array( |
||
| 336 | 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce-rest-api' ), |
||
| 337 | 'type' => 'boolean', |
||
| 338 | 'default' => false, |
||
| 339 | 'context' => array( 'view', 'edit' ), |
||
| 340 | ), |
||
| 341 | 'minimum_amount' => array( |
||
| 342 | 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce-rest-api' ), |
||
| 343 | 'type' => 'string', |
||
| 344 | 'context' => array( 'view', 'edit' ), |
||
| 345 | ), |
||
| 346 | 'maximum_amount' => array( |
||
| 347 | 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce-rest-api' ), |
||
| 348 | 'type' => 'string', |
||
| 349 | 'context' => array( 'view', 'edit' ), |
||
| 350 | ), |
||
| 351 | 'email_restrictions' => array( |
||
| 352 | 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce-rest-api' ), |
||
| 353 | 'type' => 'array', |
||
| 354 | 'items' => array( |
||
| 355 | 'type' => 'string', |
||
| 356 | ), |
||
| 357 | 'context' => array( 'view', 'edit' ), |
||
| 358 | ), |
||
| 359 | 'used_by' => array( |
||
| 360 | 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce-rest-api' ), |
||
| 361 | 'type' => 'array', |
||
| 362 | 'items' => array( |
||
| 363 | 'type' => 'integer', |
||
| 364 | ), |
||
| 365 | 'context' => array( 'view', 'edit' ), |
||
| 366 | 'readonly' => true, |
||
| 367 | ), |
||
| 368 | 'meta_data' => array( |
||
| 369 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||
| 370 | 'type' => 'array', |
||
| 371 | 'context' => array( 'view', 'edit' ), |
||
| 372 | 'items' => array( |
||
| 373 | 'type' => 'object', |
||
| 374 | 'properties' => array( |
||
| 375 | 'id' => array( |
||
| 376 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||
| 377 | 'type' => 'integer', |
||
| 378 | 'context' => array( 'view', 'edit' ), |
||
| 379 | 'readonly' => true, |
||
| 380 | ), |
||
| 381 | 'key' => array( |
||
| 382 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||
| 383 | 'type' => 'string', |
||
| 384 | 'context' => array( 'view', 'edit' ), |
||
| 385 | ), |
||
| 386 | 'value' => array( |
||
| 387 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||
| 388 | 'type' => 'mixed', |
||
| 389 | 'context' => array( 'view', 'edit' ), |
||
| 390 | ), |
||
| 391 | ), |
||
| 392 | ), |
||
| 393 | ), |
||
| 394 | ), |
||
| 395 | ); |
||
| 396 | return $this->add_additional_fields_schema( $schema ); |
||
| 397 | } |
||
| 466 |