GemsTracker/gemstracker-library

View on GitHub
classes/Gems/Model/JoinModel.php

Summary

Maintainability
B
6 hrs
Test Coverage
D
62%

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

class Gems_Model_JoinModel extends \MUtil_Model_JoinModel
{
    use TranslateableTrait;

    /**
Severity: Minor
Found in classes/Gems/Model/JoinModel.php by phpmd

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

    protected function _findFilterTables(array &$tables, array $filter)
    {
        foreach ($filter as $key => $value) {
            foreach ($filter as $name => $value) {
                if (is_int($name)) {
Severity: Minor
Found in classes/Gems/Model/JoinModel.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 _findFieldTable has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _findFieldTable(array &$tables, $field)
    {
        // Check for tablename.fieldname, unless the field name is an aliased table
        if ((! $this->has($field)) && \MUtil_String::contains($field, '.')) {
            list($table, $newField) = explode('.', $field, 2);
Severity: Minor
Found in classes/Gems/Model/JoinModel.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 getFilteredSelect has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getFilteredSelect(array $filter, array $cols = [])
    {
        if (! $cols) {
            $cols = $this->getKeys();
        }
Severity: Minor
Found in classes/Gems/Model/JoinModel.php - About 1 hr to fix

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

        public function getFilteredSelect(array $filter, array $cols = [])
        {
            if (! $cols) {
                $cols = $this->getKeys();
            }
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.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

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

        protected function _findExpressionTables(array &$tables, $expression)
        {
            $matches = [];
            preg_match_all('/([a-z]\w+\.[a-z][1-2a-z]+_\w+|[a-z][1-2a-z]+_\w+)/i', $expression, $matches);
            // \MUtil_Echo::track($expression, array_unique($matches[0]));
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    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 ($filter as $key => $value) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    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 '$alias'.
    Open

            foreach ($cols as $alias => $field) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    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 '$to'.
    Open

                    foreach ($this->_joinTables[$table] as $from => $to) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    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 '$expression'.
    Open

                        if ($expression = $this->get($name, 'column_expression')) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    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

    The parameter $table_name is not named in camelCase.
    Open

        public function setTableSaveable($table_name, $fieldPrefix = null, $saveable = null)
        {
            parent::setTableSaveable($table_name, $this->_checkSaveable($saveable, $fieldPrefix));
    
            if ($fieldPrefix) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    CamelCaseParameterName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name parameters.

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

    The variable $table_name is not named in camelCase.
    Open

        public function setTableSaveable($table_name, $fieldPrefix = null, $saveable = null)
        {
            parent::setTableSaveable($table_name, $this->_checkSaveable($saveable, $fieldPrefix));
    
            if ($fieldPrefix) {
    Severity: Minor
    Found in classes/Gems/Model/JoinModel.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status