felixarntz/wpdlib

View on GitHub
inc/WPDLib/Util/Util.php

Summary

Maintainability
C
1 day
Test Coverage

Function object_array_merge_split has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

        private static function object_array_merge_split( $arrs, $sort_by ) {
            $sortables = array();
            $nulls = array();

            foreach ( $arrs as $arr ) {
Severity: Minor
Found in inc/WPDLib/Util/Util.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_users_options has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        public static function get_users_options( $role = 'any' ) {
            if ( is_array( $role ) ) {
                if ( count( $role ) > 0 ) {
                    $role = $role[0];
                }
Severity: Minor
Found in inc/WPDLib/Util/Util.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 format_unit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        public static function format_unit( $value, $units, $base, $base_unit = '', $decimals = 2 ) {
            $value = floatval( $value );

            if ( empty( $base_unit ) ) {
                $base_unit = $units[0];
Severity: Minor
Found in inc/WPDLib/Util/Util.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 object_array_merge_items has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        private static function object_array_merge_items( $items, $result, &$instance_counts, $key = 'slug' ) {
            foreach ( $items as $item ) {
                if ( ! isset( $result[ $item->$key ] ) ) {
                    $result[ $item->$key ] = $item;
                } else {
Severity: Minor
Found in inc/WPDLib/Util/Util.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 object_array_insert_sorted has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        private static function object_array_insert_sorted( $arr, $item, $sort_by, $key = 'slug' ) {
            $new_arr = array();
            $new_arr[ $item->$key ] = $item;

            $split_key = 0;
Severity: Minor
Found in inc/WPDLib/Util/Util.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 sort_objects_callback has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

        private static function sort_objects_callback( $a, $b ) {
            $sort_by = self::$sort_by;

            if ( ( ! isset( $a->$sort_by ) || null === $a->$sort_by ) && ( ! isset( $b->$sort_by ) || null === $b->$sort_by ) ) {
                return 0;
Severity: Minor
Found in inc/WPDLib/Util/Util.php - About 55 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 mod has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        public static function mod( $divident, $divisor ) {
            if ( is_int( $divident ) && is_int( $divisor ) ) {
                // prevent division by zero
                if ( 0 === $divisor ) {
                    return 0;
Severity: Minor
Found in inc/WPDLib/Util/Util.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 is_rest_zero has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        public static function is_rest_zero( $divident, $divisor ) {
            $divident = abs( $divident );
            $divisor = abs( $divisor );

            if ( is_int( $divident ) && is_int( $divisor ) ) {
Severity: Minor
Found in inc/WPDLib/Util/Util.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

Consider simplifying this complex logical expression.
Open

            if ( ( ! isset( $a->$sort_by ) || null === $a->$sort_by ) && ( ! isset( $b->$sort_by ) || null === $b->$sort_by ) ) {
                return 0;
            } elseif ( ! isset( $a->$sort_by ) || null === $a->$sort_by ) {
                return 1;
            } elseif ( ! isset( $b->$sort_by ) || null === $b->$sort_by ) {
Severity: Major
Found in inc/WPDLib/Util/Util.php - About 40 mins to fix

    Method format_unit has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            public static function format_unit( $value, $units, $base, $base_unit = '', $decimals = 2 ) {
    Severity: Minor
    Found in inc/WPDLib/Util/Util.php - About 35 mins to fix

      Avoid too many return statements within this method.
      Open

                  return ( $a->$sort_by < $b->$sort_by ? -1 : 1 );
      Severity: Major
      Found in inc/WPDLib/Util/Util.php - About 30 mins to fix

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

                public static function get_posts_options( $post_type = 'any' ) {
                    if ( ! is_string( $post_type ) && ! is_array( $post_type ) || empty( $post_type ) ) {
                        $post_type = 'any';
                    }
        
        
        Severity: Minor
        Found in inc/WPDLib/Util/Util.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 object_array_sort has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                public static function object_array_sort( $arr, $sort_by, $associative = false ) {
                    if ( ! empty( $sort_by ) ) {
                        self::$sort_by = $sort_by;
        
                        if ( $associative ) {
        Severity: Minor
        Found in inc/WPDLib/Util/Util.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

        There are no issues that match your filters.

        Category
        Status