woocommerce/woocommerce

View on GitHub

Showing 4,341 of 4,341 total issues

Function get_filtered_price has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_filtered_price() {
        global $wpdb;

        $args       = WC()->query->get_main_query()->query_vars;
        $tax_query  = isset( $args['tax_query'] ) ? $args['tax_query'] : array();
Severity: Minor
Found in includes/widgets/class-wc-widget-price-filter.php - About 25 mins to fix

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 set_taxes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function set_taxes( $raw_tax_data ) {
        $raw_tax_data = maybe_unserialize( $raw_tax_data );
        $tax_data     = array(
            'total'    => array(),
            'subtotal' => array(),
Severity: Minor
Found in includes/class-wc-order-item-product.php - About 25 mins to fix

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 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function update_attributes( &$product, $force = false ) {
        $changes = $product->get_changes();

        if ( $force || array_key_exists( 'attributes', $changes ) ) {
            global $wpdb;
Severity: Minor
Found in includes/data-stores/class-wc-product-variation-data-store-cpt.php - About 25 mins to fix

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 offsetGet has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function offsetGet( $offset ) {
        if ( 'line_subtotal' === $offset ) {
            $offset = 'subtotal';
        } elseif ( 'line_subtotal_tax' === $offset ) {
            $offset = 'subtotal_tax';
Severity: Minor
Found in includes/class-wc-order-item-product.php - About 25 mins to fix

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_product_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_product_id( $posted, $action = 'create' ) {
        if ( ! empty( $posted['sku'] ) ) {
            $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
        } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
            $product_id = (int) $posted['product_id'];

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 prepare_item_for_database has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function prepare_item_for_database( $request ) {
        $data = new stdClass;

        // Post ID.
        if ( isset( $request['id'] ) ) {

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_order has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function create_order( $request ) {
        try {
            // Make sure customer exists.
            if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] && false === get_user_by( 'id', $request['customer_id'] ) ) {
                throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id',__( 'Customer ID is invalid.', 'woocommerce' ), 400 );

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 batch_items has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function batch_items( $request ) {
        $items       = array_filter( $request->get_params() );
        $params      = $request->get_url_params();
        $query       = $request->get_query_params();
        $product_id  = $params['product_id'];

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 batch_items has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function batch_items( $request ) {
        $items       = array_filter( $request->get_params() );
        $params      = $request->get_url_params();
        $product_id  = $params['product_id'];
        $body_params = array();

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_order has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function update_order( $request ) {
        try {
            $order = $this->prepare_item_for_database( $request );
            $order->save();

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_inactive_plugins has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_inactive_plugins() {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        if ( ! function_exists( 'get_plugins' ) ) {
            return array();

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_customer_meta_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function update_customer_meta_fields( $customer, $request ) {
        parent::update_customer_meta_fields( $customer, $request );

        // Meta data.
        if ( isset( $request['meta_data'] ) ) {

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_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function update_item( $request ) {
        $setting = $this->get_setting( $request['group_id'], $request['id'] );

        if ( is_wp_error( $setting ) ) {
            return $setting;

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_product_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_product_id( $posted, $action = 'create' ) {
        if ( ! empty( $posted['sku'] ) ) {
            $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
        } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
            $product_id = (int) $posted['product_id'];

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 check_if_field_item_exists has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private function check_if_field_item_exists( $section, $items, $fields ) {
        if ( ! in_array( $section, $fields, true ) ) {
            return false;
        }

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_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_item( $request ) {
        $zone = $this->get_zone( $request['zone_id'] );

        if ( is_wp_error( $zone ) ) {
            return $zone;

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 prepare_items_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function prepare_items_query( $prepared_args = array(), $request = null ) {

        $valid_vars = array_flip( $this->get_allowed_query_vars() );
        $query_args = array();
        foreach ( $valid_vars as $var => $index ) {

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 check_permissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function check_permissions( $request, $context = 'read' ) {
        // Get taxonomy.
        $taxonomy = $this->get_taxonomy( $request );
        if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
            return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) );

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 prepare_objects_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function prepare_objects_query( $request ) {
        // This is needed to get around an array to string notice in WC_REST_Orders_V2_Controller::prepare_objects_query.
        $statuses = $request['status'];
        unset( $request['status'] );
        $args = parent::prepare_objects_query( $request );

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_terms_for_product has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_terms_for_product( $prepared_args, $request ) {
        $taxonomy = $this->get_taxonomy( $request );

        $query_result = get_the_terms( $prepared_args['product'], $taxonomy );
        if ( empty( $query_result ) ) {

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

Severity
Category
Status
Source
Language