GemsTracker/gemstracker-library

View on GitHub
classes/Gems/Tracker/Engine/FieldsDefinition.php

Summary

Maintainability
F
4 days
Test Coverage
B
89%

File FieldsDefinition.php has 411 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 *
 * @package    Gems
Severity: Minor
Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 5 hrs to fix

    Function processBeforeSave has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public function processBeforeSave(array $fieldData, array $trackData)
        {
            $this->changed = false;
    
            if (! $this->exists) {
    Severity: Minor
    Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 4 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 saveFields has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public function saveFields($respTrackId, array $fieldData)
        {
            $saves  = [];
            $logs   = [];
            
    Severity: Minor
    Found in classes/Gems/Tracker/Engine/FieldsDefinition.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

    The class FieldsDefinition has an overall complexity of 118 which is very high. The configured complexity threshold is 50.
    Open

    class FieldsDefinition extends \MUtil_Translate_TranslateableAbstract
    {
        /**
         * Field key separator
         */

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

        public function calculateFieldsInfo(array $data)
        {
            if (! $this->exists) {
                return null;
            }
    Severity: Minor
    Found in classes/Gems/Tracker/Engine/FieldsDefinition.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

    FieldsDefinition has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FieldsDefinition extends \MUtil_Translate_TranslateableAbstract
    {
        /**
         * Field key separator
         */
    Severity: Minor
    Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 3 hrs to fix

      Function getMaintenanceModel has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getMaintenanceModel($detailed = false, $action = 'index')
          {
              if (isset($this->_maintenanceModels[$action])) {
                  return $this->_maintenanceModels[$action];
              }
      Severity: Minor
      Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 saveFields has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function saveFields($respTrackId, array $fieldData)
          {
              $saves  = [];
              $logs   = [];
              
      Severity: Minor
      Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 1 hr to fix

        Function getFieldsDataFor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getFieldsDataFor($respTrackId)
            {
                if (! $this->_fields) {
                    return array();
                }
        Severity: Minor
        Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 processBeforeSave has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function processBeforeSave(array $fieldData, array $trackData)
            {
                $this->changed = false;
        
                if (! $this->exists) {
        Severity: Minor
        Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 1 hr to fix

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

              public function getDataModelDependencies(\MUtil_Model_ModelAbstract $model)
              {
                  if (! $this->exists) {
                      return null;
                  }
          Severity: Minor
          Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 _ensureTrackFields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function _ensureTrackFields()
              {
                  if (! is_array($this->_fields)) {
                      // Check for cases where the track id is zero, but there is a field for track 0 in the db
                      if ($this->_trackId) {
          Severity: Minor
          Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 getMaintenanceModel has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getMaintenanceModel($detailed = false, $action = 'index')
              {
                  if (isset($this->_maintenanceModels[$action])) {
                      return $this->_maintenanceModels[$action];
                  }
          Severity: Minor
          Found in classes/Gems/Tracker/Engine/FieldsDefinition.php - About 1 hr to fix

            Function hasAppointmentFields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function hasAppointmentFields()
                {
                    if (null === $this->_hasAppointmentFields) {
                        $this->_hasAppointmentFields = false;
            
            
            Severity: Minor
            Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 getDataModelSettings has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getDataModelSettings()
                {
                    if (! $this->exists) {
                        return array();
                    }
            Severity: Minor
            Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 getFieldByOrder has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getFieldByOrder($order)
                {
                    foreach ($this->_fields as $field) {
                        if ($field instanceof FieldInterface) {
                            if ($field->getOrder() == $order) {
            Severity: Minor
            Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 getManualFields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getManualFields()
                {
                    $output = [];
                    foreach ($this->_fields as $key => $field) {
                        if ($field instanceof FieldInterface) {
            Severity: Minor
            Found in classes/Gems/Tracker/Engine/FieldsDefinition.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 getFieldByCode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getFieldByCode($code)
                {
                    foreach ($this->_fields as $field) {
                        if ($field instanceof FieldInterface) {
                            if ($field->getCode() == $code) {
            Severity: Minor
            Found in classes/Gems/Tracker/Engine/FieldsDefinition.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

            The method processBeforeSave() has an NPath complexity of 372. The configured NPath complexity threshold is 200.
            Open

                public function processBeforeSave(array $fieldData, array $trackData)
                {
                    $this->changed = false;
            
                    if (! $this->exists) {

            NPathComplexity

            Since: 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example

            class Foo {
                function bar() {
                    // lots of complicated code
                }
            }

            Source https://phpmd.org/rules/codesize.html#npathcomplexity

            The method saveFields() has an NPath complexity of 444. The configured NPath complexity threshold is 200.
            Open

                public function saveFields($respTrackId, array $fieldData)
                {
                    $saves  = [];
                    $logs   = [];
                    

            NPathComplexity

            Since: 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example

            class Foo {
                function bar() {
                    // lots of complicated code
                }
            }

            Source https://phpmd.org/rules/codesize.html#npathcomplexity

            The method saveFields() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
            Open

                public function saveFields($respTrackId, array $fieldData)
                {
                    $saves  = [];
                    $logs   = [];
                    

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The method calculateFieldsInfo() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
            Open

                public function calculateFieldsInfo(array $data)
                {
                    if (! $this->exists) {
                        return null;
                    }

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The method processBeforeSave() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
            Open

                public function processBeforeSave(array $fieldData, array $trackData)
                {
                    $this->changed = false;
            
                    if (! $this->exists) {

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            Avoid unused local variables such as '$key'.
            Open

                    foreach ($this->_fields as $key => $field) {

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            Avoid unused local variables such as '$dependsOn'.
            Open

                            $dependsOn = $field->getDataModelDependsOn();

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            Avoid excessively long variable names like $_hasAppointmentFields. Keep variable name length under 20.
            Open

                private $_hasAppointmentFields = null;

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#longvariable

            Avoid variables with short names like $db. Configured minimum length is 3.
            Open

                protected $db;

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            There are no issues that match your filters.

            Category
            Status