woothemes/woocommerce

View on GitHub
includes/abstracts/abstract-wc-data.php

Summary

Maintainability
F
3 days
Test Coverage

File abstract-wc-data.php has 390 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Abstract Data.
 *
 * Handles generic data interaction which is implemented by
Severity: Minor
Found in includes/abstracts/abstract-wc-data.php - About 5 hrs to fix

    WC_Data has 40 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class WC_Data {
    
        /**
         * ID for this object.
         *
    Severity: Minor
    Found in includes/abstracts/abstract-wc-data.php - About 5 hrs to fix

      Function update_meta_data has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public function update_meta_data( $key, $value, $meta_id = 0 ) {
              if ( $this->is_internal_meta_key( $key ) ) {
                  $function = 'set_' . $key;
      
                  if ( is_callable( array( $this, $function ) ) ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-data.php - About 2 hrs 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 save_meta_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          public function save_meta_data() {
              if ( ! $this->data_store || is_null( $this->meta_data ) ) {
                  return;
              }
              foreach ( $this->meta_data as $array_key => $meta ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-data.php - About 1 hr 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_props has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function set_props( $props, $context = 'set' ) {
              $errors = false;
      
              foreach ( $props as $prop => $value ) {
                  try {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-data.php - About 1 hr 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 read_meta_data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          public function read_meta_data( $force_read = false ) {
              $this->meta_data = array();
              $cache_loaded    = false;
      
              if ( ! $this->get_id() ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-data.php - About 1 hr 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

      Method update_meta_data has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function update_meta_data( $key, $value, $meta_id = 0 ) {
              if ( $this->is_internal_meta_key( $key ) ) {
                  $function = 'set_' . $key;
      
                  if ( is_callable( array( $this, $function ) ) ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-data.php - About 1 hr to fix

        Method read_meta_data has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function read_meta_data( $force_read = false ) {
                $this->meta_data = array();
                $cache_loaded    = false;
        
                if ( ! $this->get_id() ) {
        Severity: Minor
        Found in includes/abstracts/abstract-wc-data.php - About 1 hr to fix

          Function set_date_prop has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function set_date_prop( $prop, $value ) {
                  try {
                      if ( empty( $value ) ) {
                          $this->set_prop( $prop, null );
                          return;
          Severity: Minor
          Found in includes/abstracts/abstract-wc-data.php - About 1 hr 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_meta has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function get_meta( $key = '', $single = true, $context = 'view' ) {
                  if ( $this->is_internal_meta_key( $key ) ) {
                      $function = 'get_' . $key;
          
                      if ( is_callable( array( $this, $function ) ) ) {
          Severity: Minor
          Found in includes/abstracts/abstract-wc-data.php - About 45 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_prop has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function set_prop( $prop, $value ) {
                  if ( array_key_exists( $prop, $this->data ) ) {
                      if ( true === $this->object_read ) {
                          if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
                              $this->changes[ $prop ] = $value;
          Severity: Minor
          Found in includes/abstracts/abstract-wc-data.php - About 45 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_meta_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function set_meta_data( $data ) {
                  if ( ! empty( $data ) && is_array( $data ) ) {
                      $this->maybe_read_meta_data();
                      foreach ( $data as $meta ) {
                          $meta = (array) $meta;
          Severity: Minor
          Found in includes/abstracts/abstract-wc-data.php - About 35 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 __clone has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function __clone() {
                  $this->maybe_read_meta_data();
                  if ( ! empty( $this->meta_data ) ) {
                      foreach ( $this->meta_data as $array_key => $meta ) {
                          $this->meta_data[ $array_key ] = clone $meta;
          Severity: Minor
          Found in includes/abstracts/abstract-wc-data.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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                          if ( 1 === preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|((-|\+)\d{2}:\d{2}))$/', $value, $date_bits ) ) {
                              $offset    = ! empty( $date_bits[7] ) ? iso8601_timezone_to_offset( $date_bits[7] ) : wc_timezone_offset();
                              $timestamp = gmmktime( $date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1] ) - $offset;
                          } else {
                              $timestamp = wc_string_to_timestamp( get_gmt_from_date( gmdate( 'Y-m-d H:i:s', wc_string_to_timestamp( $value ) ) ) );
          Severity: Major
          Found in includes/abstracts/abstract-wc-data.php and 1 other location - About 3 hrs to fix
          includes/wc-formatting-functions.php on lines 724..729

          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 156.

          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

          Further Reading

          There are no issues that match your filters.

          Category
          Status