felixarntz/wpdlib

View on GitHub
inc/WPDLib/FieldTypes/Manager.php

Summary

Maintainability
F
3 days
Test Coverage

File Manager.php has 385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WPDLib\FieldTypes\Manager class
 *
 * @package WPDLib
Severity: Minor
Found in inc/WPDLib/FieldTypes/Manager.php - About 5 hrs to fix

    Function get_dependencies_and_script_vars has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

            public static function get_dependencies_and_script_vars( $fields = array() ) {
                $dependencies = array();
                $script_vars = array();
    
                foreach ( $fields as $field ) {
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Manager.php - About 3 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 make_html_attributes has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

            public static function make_html_attributes( $atts, $html5 = true, $echo = true ) {
                $output = '';
    
                $bool_atts = array_filter( $atts, 'is_bool' );
    
    
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Manager.php - About 3 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

    Manager has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

        final class Manager {
    
            /**
             * Status whether the class has been initialized.
             *
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Manager.php - About 3 hrs to fix

      Function parse_bool has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              private static function parse_bool( $value ) {
                  if ( is_int( $value ) ) {
                      if ( $value > 0 ) {
                          return true;
                      }
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Manager.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_float has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              private static function format_float( $value, $mode = 'input', $args = array() ) {
                  $positive_only = isset( $args['positive_only'] ) ? (bool) $args['positive_only'] : false;
      
                  $formatted = self::parse_float( $value );
                  if ( $positive_only ) {
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Manager.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_default_datetime_format has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              private static function get_default_datetime_format( $type, $mode = 'input' ) {
                  if ( 'output' === $mode ) {
                      if ( $type == 'date' ) {
                          return get_option( 'date_format' );
                      } elseif ( $type == 'time' ) {
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Manager.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_html_data_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

              private static function sort_html_data_attributes( $a, $b, $priorities = array() ) {
                  if ( strpos( $a, 'data-' ) === 0 && strpos( $b, 'data-' ) !== 0 ) {
                      if ( in_array( $b, $priorities ) ) {
                          return 1;
                      }
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Manager.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 format has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public static function format( $value, $type, $mode = 'input', $args = array() ) {
                  $mode = 'output' === $mode ? 'output' : 'input';
      
                  $formatted = $value;
      
      
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Manager.php - About 1 hr to fix

        Method make_html_attributes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public static function make_html_attributes( $atts, $html5 = true, $echo = true ) {
                    $output = '';
        
                    $bool_atts = array_filter( $atts, 'is_bool' );
        
        
        Severity: Minor
        Found in inc/WPDLib/FieldTypes/Manager.php - About 1 hr to fix

          Function sort_html_priority_attributes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  private static function sort_html_priority_attributes( $a, $b, $priorities = array() ) {
                      if ( in_array( $a, $priorities ) && ! in_array( $b, $priorities ) ) {
                          return -1;
                      } elseif ( ! in_array( $a, $priorities ) && in_array( $b, $priorities ) ) {
                          return 1;
          Severity: Minor
          Found in inc/WPDLib/FieldTypes/Manager.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

          Avoid too many return statements within this method.
          Open

                              return self::format_float( $value, $mode, $args );
          Severity: Major
          Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return 'His';
            Severity: Major
            Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                  return self::format_datetime( $value, $mode, $type, $args );
              Severity: Major
              Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return $formatted;
                Severity: Major
                Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return 0;
                  Severity: Major
                  Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return 'YmdHis';
                    Severity: Major
                    Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return self::format_int( $value, $mode, $args );
                      Severity: Major
                      Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return 0;
                        Severity: Major
                        Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                              return self::format_byte( $value, $mode, $args );
                          Severity: Major
                          Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return false;
                            Severity: Major
                            Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return (bool) $value;
                              Severity: Major
                              Found in inc/WPDLib/FieldTypes/Manager.php - About 30 mins to fix

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

                                        private static function format_bool( $value, $mode = 'input' ) {
                                            $formatted = self::parse_bool( $value );
                                
                                            if ( 'output' === $mode ) {
                                                if ( $formatted ) {
                                Severity: Minor
                                Found in inc/WPDLib/FieldTypes/Manager.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_instance has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                        public static function get_instance( $args, $repeatable = false ) {
                                            if ( ! isset( $args['type'] ) ) {
                                                return null;
                                            }
                                
                                
                                Severity: Minor
                                Found in inc/WPDLib/FieldTypes/Manager.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