File class-wc-product-data-store-cpt.php
has 1385 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WC_Product_Data_Store_CPT class file.
*
* @package WooCommerce\Classes
Method get_wp_query_args
has 202 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_wp_query_args( $query_vars ) {
// Map query vars to ones that get_wp_query_args or WP_Query recognize.
$key_mapping = array(
'status' => 'post_status',
Function get_wp_query_args
has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring. Open
protected function get_wp_query_args( $query_vars ) {
// Map query vars to ones that get_wp_query_args or WP_Query recognize.
$key_mapping = array(
'status' => 'post_status',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
WC_Product_Data_Store_CPT
has 45 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface, WC_Product_Data_Store_Interface {
/**
* Data stored in meta keys, but not considered "meta".
*
Function search_products
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
global $wpdb;
$custom_results = apply_filters( 'woocommerce_product_pre_search_products', false, $term, $type, $include_variations, $all_statuses, $limit );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function update_post_meta
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
protected function update_post_meta( &$product, $force = false ) {
$meta_key_to_props = array(
'_sku' => 'sku',
'_regular_price' => 'regular_price',
'_sale_price' => 'sale_price',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method search_products
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
global $wpdb;
$custom_results = apply_filters( 'woocommerce_product_pre_search_products', false, $term, $type, $include_variations, $all_statuses, $limit );
Method update_post_meta
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function update_post_meta( &$product, $force = false ) {
$meta_key_to_props = array(
'_sku' => 'sku',
'_regular_price' => 'regular_price',
'_sale_price' => 'sale_price',
Function find_matching_product_variation
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function find_matching_product_variation( $product, $match_attributes = array() ) {
global $wpdb;
$meta_attribute_names = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function handle_updated_props
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_updated_props( &$product ) {
$price_is_synced = $product->is_type( array( 'variable', 'grouped' ) );
if ( ! $price_is_synced ) {
if ( in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function update_attributes
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
protected function update_attributes( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'attributes', $changes ) ) {
$attributes = $product->get_attributes();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update( &$product ) {
$product->save_meta_data();
$changes = $product->get_changes();
// Only update the post when the post data changes.
Method find_matching_product_variation
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function find_matching_product_variation( $product, $match_attributes = array() ) {
global $wpdb;
$meta_attribute_names = array();
Method read_product_data
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function read_product_data( &$product ) {
$id = $product->get_id();
$post_meta_values = get_post_meta( $id );
$meta_key_to_props = array(
'_sku' => 'sku',
Function update_visibility
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
protected function update_visibility( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_intersect( array( 'featured', 'stock_status', 'average_rating', 'catalog_visibility' ), array_keys( $changes ) ) ) {
$terms = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update_product_stock
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' ) {
global $wpdb;
// Ensures a row exists to update.
add_post_meta( $product_id_with_stock, '_stock', 0, true );
Function read_attributes
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function read_attributes( &$product ) {
$meta_attributes = get_post_meta( $product->get_id(), '_product_attributes', true );
if ( ! empty( $meta_attributes ) && is_array( $meta_attributes ) ) {
$attributes = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function create( &$product ) {
if ( ! $product->get_date_created( 'edit' ) ) {
$product->set_date_created( time() );
}
Method handle_updated_props
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_updated_props( &$product ) {
$price_is_synced = $product->is_type( array( 'variable', 'grouped' ) );
if ( ! $price_is_synced ) {
if ( in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) ) {
Method read_attributes
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function read_attributes( &$product ) {
$meta_attributes = get_post_meta( $product->get_id(), '_product_attributes', true );
if ( ! empty( $meta_attributes ) && is_array( $meta_attributes ) ) {
$attributes = array();
Method get_related_products_query
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
global $wpdb;
$include_term_ids = array_merge( $cats_array, $tags_array );
$exclude_term_ids = array();
Method update_product_sales
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update_product_sales( $product_id, $quantity = null, $operation = 'set' ) {
global $wpdb;
add_post_meta( $product_id, 'total_sales', 0, true );
// Update stock in DB directly.
Method get_on_sale_products
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_on_sale_products() {
global $wpdb;
$exclude_term_ids = array();
$outofstock_join = '';
Function update
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function update( &$product ) {
$product->save_meta_data();
$changes = $product->get_changes();
// Only update the post when the post data changes.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function create_all_product_variations
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function create_all_product_variations( $product, $limit = -1 ) {
$count = 0;
if ( ! $product ) {
return $count;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update_attributes
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function update_attributes( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'attributes', $changes ) ) {
$attributes = $product->get_attributes();
Method create_all_product_variations
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function create_all_product_variations( $product, $limit = -1 ) {
$count = 0;
if ( ! $product ) {
return $count;
Method update_visibility
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function update_visibility( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_intersect( array( 'featured', 'stock_status', 'average_rating', 'catalog_visibility' ), array_keys( $changes ) ) ) {
$terms = array();
Function update_downloads
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function update_downloads( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'downloads', $changes ) ) {
$downloads = $product->get_downloads();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method read
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function read( &$product ) {
$product->set_defaults();
$post_object = get_post( $product->get_id() );
if ( ! $product->get_id() || ! $post_object || 'product' !== $post_object->post_type ) {
Method search_products
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
Function update_terms
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function update_terms( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'category_ids', $changes ) ) {
$categories = $product->get_category_ids( 'edit' );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_related_products
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) {
Function read_downloads
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function read_downloads( &$product ) {
$meta_values = array_filter( (array) get_post_meta( $product->get_id(), '_downloadable_files', true ) );
if ( $meta_values ) {
$downloads = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_related_products_query
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
global $wpdb;
$include_term_ids = array_merge( $cats_array, $tags_array );
$exclude_term_ids = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
$meta_key_to_props = array(
'_sku' => 'sku',
'_regular_price' => 'regular_price',
'_sale_price' => 'sale_price',
'_price' => 'price',
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 168.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
$meta_key_to_props = array(
'_sku' => 'sku',
'_regular_price' => 'regular_price',
'_sale_price' => 'sale_price',
'_sale_price_dates_from' => 'date_on_sale_from',
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 158.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ( ! empty( $meta_value['is_taxonomy'] ) ) {
if ( ! taxonomy_exists( $meta_value['name'] ) ) {
continue;
}
$id = wc_attribute_taxonomy_id_by_name( $meta_value['name'] );
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 105.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 4 locations. Consider refactoring. Open
if ( doing_action( 'save_post' ) ) {
$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $product->get_id() ) );
clean_post_cache( $product->get_id() );
} else {
wp_update_post( array_merge( array( 'ID' => $product->get_id() ), $post_data ) );
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 91.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76