rugk/xenforo-threema-gateway

View on GitHub
src/library/ThreemaGateway/Model/Messages.php

Summary

Maintainability
D
1 day
Test Coverage

Method getMessageDataByType has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getMessageDataByType($messageType, $includeMetaData = true)
    {
        /** @var array $output */
        $output = [];

Severity: Major
Found in src/library/ThreemaGateway/Model/Messages.php - About 3 hrs to fix

    File Messages.php has 310 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Model for messages stored in database.
     *
     * @package ThreemaGateway
    Severity: Minor
    Found in src/library/ThreemaGateway/Model/Messages.php - About 3 hrs to fix

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

      class ThreemaGateway_Model_Messages extends XenForo_Model
      {
          /**
           * @var string database table (prefix) for messages
           */

      Function getAllMessageData has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAllMessageData(array $metaData, $groupByMessageType = false)
          {
              // get grouped messages by type
              $messageTypes = $this->groupArray($metaData, 'message_type_code');
              // we always need to do this (regardless of message_type_code) as each
      Severity: Minor
      Found in src/library/ThreemaGateway/Model/Messages.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 getMessageDataByType has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getMessageDataByType($messageType, $includeMetaData = true)
          {
              /** @var array $output */
              $output = [];
      
      
      Severity: Minor
      Found in src/library/ThreemaGateway/Model/Messages.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 getAllMessageData has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getAllMessageData(array $metaData, $groupByMessageType = false)
          {
              // get grouped messages by type
              $messageTypes = $this->groupArray($metaData, 'message_type_code');
              // we always need to do this (regardless of message_type_code) as each
      Severity: Minor
      Found in src/library/ThreemaGateway/Model/Messages.php - About 1 hr to fix

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

            public function getMessageMetaData($groupById = false, $ignoreInvalid = true)
            {
                /** @var array $limitOptions */
                $limitOptions = $this->prepareLimitFetchOptions($this->fetchOptions);
        
        
        Severity: Minor
        Found in src/library/ThreemaGateway/Model/Messages.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 pushArrayKeys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function pushArrayKeys(array &$baseArray, array &$subArray, array $removeKeys)
            {
                foreach ($removeKeys as $key) {
                    // skip invalid keys
                    if (!array_key_exists($key, $subArray[0])) {
        Severity: Minor
        Found in src/library/ThreemaGateway/Model/Messages.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 getMessageDataByType() has 140 lines of code. Current threshold is set to 100. Avoid really long methods.
        Open

            public function getMessageDataByType($messageType, $includeMetaData = true)
            {
                /** @var array $output */
                $output = [];
        
        

        The method getMessageDataByType() has an NPath complexity of 960. The configured NPath complexity threshold is 200.
        Open

            public function getMessageDataByType($messageType, $includeMetaData = true)
            {
                /** @var array $output */
                $output = [];
        
        

        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 getMessageDataByType() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
        Open

            public function getMessageDataByType($messageType, $includeMetaData = true)
            {
                /** @var array $output */
                $output = [];
        
        

        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 groupArray has a boolean flag argument $ignoreIndex, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function groupArray(array $array, $indexKey, $ignoreIndex = false)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method getMessageDataByType has a boolean flag argument $includeMetaData, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getMessageDataByType($messageType, $includeMetaData = true)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        Missing class import via use statement (line '380', column '49').
        Open

                        throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '434', column '45').
        Open

                    throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        The method getAllMessageData has a boolean flag argument $groupByMessageType, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getAllMessageData(array $metaData, $groupByMessageType = false)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method injectFetchOption has a boolean flag argument $append, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function injectFetchOption($option, $value, $append = false)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        Missing class import via use statement (line '406', column '23').
        Open

                    throw new XenForo_Exception(new XenForo_Phrase('threemagw_missing_database_data'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '406', column '45').
        Open

                    throw new XenForo_Exception(new XenForo_Phrase('threemagw_missing_database_data'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        The method getMessageMetaData has a boolean flag argument $groupById, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getMessageMetaData($groupById = false, $ignoreInvalid = true)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method getMessageMetaData has a boolean flag argument $ignoreInvalid, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getMessageMetaData($groupById = false, $ignoreInvalid = true)

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        Missing class import via use statement (line '380', column '27').
        Open

                        throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '434', column '23').
        Open

                    throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        The method groupArray uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        $output[$value[$indexKey]][] = $value;
                    }

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method injectFetchOption uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->fetchOptions[$option] = $value;
                }

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method appendMixedCondition uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->fetchOptions['where'][]  = $attName . ' IN (' . implode(', ', array_fill(0, count($attValue), '?')) . ')';
                    $this->fetchOptions['params'] += $attValue;
                }

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method getAllMessageData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                        } else {
                            $output[$msgId] = $mergedArrays;
                        }

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        The method removeMetaData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->_getDb()->delete(
                        self::DB_TABLE_MESSAGES,
                        array_merge(
                            array_combine($this->fetchOptions['where'], $this->fetchOptions['params']),

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

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

                foreach ($array as $i => $value) {

        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

        There are no issues that match your filters.

        Category
        Status