robotomize/fujes

View on GitHub
src/robotomize/Fujes/SearchLevenshteinCompare.php

Summary

Maintainability
D
2 days
Test Coverage

SearchLevenshteinCompare has 33 functions (exceeds 20 allowed). Consider refactoring.
Open

class SearchLevenshteinCompare implements ISearch
{
    /**
     * @var array
     */
Severity: Minor
Found in src/robotomize/Fujes/SearchLevenshteinCompare.php - About 4 hrs to fix

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

    class SearchLevenshteinCompare implements ISearch
    {
        /**
         * @var array
         */

    File SearchLevenshteinCompare.php has 271 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
        /**
         * This file is part of the Fujes package.
         * @link    https://github.com/robotomize/fujes
         * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
    Severity: Minor
    Found in src/robotomize/Fujes/SearchLevenshteinCompare.php - About 2 hrs to fix

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

          public function search($inputArray = [], $key = '', $level = 0)
          {
              if (0 === count($inputArray)) {
                  $inputArray = $this->inputArray;
              }
      Severity: Minor
      Found in src/robotomize/Fujes/SearchLevenshteinCompare.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 preSearch has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function preSearch($inputArray = [], $key = '', $level = 0)
          {
              if (0 === count($inputArray)) {
                  $inputArray = $this->inputArray;
              }
      Severity: Minor
      Found in src/robotomize/Fujes/SearchLevenshteinCompare.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 __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              $inputArray,
              $matchString,
              $multipleResult = false,
              $quality = 1,
              $versionType = 'master'
      Severity: Minor
      Found in src/robotomize/Fujes/SearchLevenshteinCompare.php - About 35 mins to fix

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

            public function countDepth($inputArray = [])
            {
                if (0 === count($inputArray)) {
                    $inputArray = $this->inputArray;
                }
        Severity: Minor
        Found in src/robotomize/Fujes/SearchLevenshteinCompare.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 __construct has a boolean flag argument $multipleResult, which is a certain sign of a Single Responsibility Principle violation.
        Open

                $multipleResult = 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 '59', column '23').
        Open

                    throw new \InvalidArgumentException;

        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 __invoke uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return $this;
                }

        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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->inputArray = $inputArray;
                    $this->matchString = mb_strtolower($matchString);
                    $this->multipleResult = $multipleResult;
                    $this->quality = $quality;

        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 preSearch uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        if ($this->splitDirectMatchSheetJsonTree($vv, $keys)) {
                            break;
                        } else {
                            continue;

        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 __toString uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return serialize($this);
                }

        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 search uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        $currentCompareArray = $this->splitSheetJsonTree($vv, $keys);
                        if (0 !== count($currentCompareArray)) {
                            $this->scoreMatrix[] = $currentCompareArray;
                        }

        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 directCompareTwoString uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return false;
                }

        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 relevantCalc uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        return [];
                    }

        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 countDepth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        continue;
                    }

        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 compareStart uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return $compare;
                }

        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 preSearch uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                        } else {
                            continue;
                        }

        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 preSearch uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return false;
                }

        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 sortingScoreMatrix uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return false;
                }

        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 search uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return false;
                }

        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 private fields such as '$searchIteration'.
        Open

            private $searchIteration = 0;

        UnusedPrivateField

        Since: 0.2

        Detects when a private field is declared and/or assigned a value, but not used.

        Example

        class Something
        {
            private static $FOO = 2; // Unused
            private $i = 5; // Unused
            private $j = 6;
            public function addOne()
            {
                return $this->j++;
            }
        }

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

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

                foreach ($inputArray as $kk => $vv) {

        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

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

            public function preSearch($inputArray = [], $key = '', $level = 0)
            {
                if (0 === count($inputArray)) {
                    $inputArray = $this->inputArray;
                }
        Severity: Major
        Found in src/robotomize/Fujes/SearchLevenshteinCompare.php and 1 other location - About 4 hrs to fix
        src/robotomize/Fujes/SearchSubstringCompare.php on lines 112..140

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 168.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

            public function compareStart($current, $key)
            {
                $compare = levenshtein(strtolower(trim($current)), $this->matchString);
                if (strtolower($current) === $this->matchString || $compare <= $this->precision) {
                    $this->directMatch[] = [$key, $current, $compare];
        Severity: Major
        Found in src/robotomize/Fujes/SearchLevenshteinCompare.php and 1 other location - About 1 hr to fix
        src/robotomize/Fujes/SearchSubstringCompare.php on lines 153..162

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 103.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

            private static $directMatchCoefficient = 0;

        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 excessively long variable names like $directMatchCoefficient. Keep variable name length under 20.
        Open

            public static function setDirectMatchCoefficient($directMatchCoefficient)

        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

        The 'getMultipleResult()' method which returns a boolean should be named 'is...()' or 'has...()'
        Open

            public function getMultipleResult()
            {
                return $this->multipleResult;
            }

        BooleanGetMethodName

        Since: 0.2

        Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

        Example

        class Foo {
            /**
             * @return boolean
             */
            public function getFoo() {} // bad
            /**
             * @return bool
             */
            public function isFoo(); // ok
            /**
             * @return boolean
             */
            public function getFoo($bar); // ok, unless checkParameterizedMethods=true
        }

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

        There are no issues that match your filters.

        Category
        Status