vakata/phptree

View on GitHub

Showing 12 of 12 total issues

Function toDatabase has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    public function toDatabase(DBInterface $db, $tb, array $fields = [], bool $transaction = true): array
    {
        $cur = [];
        $new = [];
        $mod = [];
Severity: Minor
Found in src/Tree.php - About 6 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

Method toDatabase has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function toDatabase(DBInterface $db, $tb, array $fields = [], bool $transaction = true): array
    {
        $cur = [];
        $new = [];
        $mod = [];
Severity: Major
Found in src/Tree.php - About 3 hrs to fix

    Node has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Node
    {
        public static function copy(Node $original): Node
        {
            $node = clone $original;
    Severity: Minor
    Found in src/Node.php - About 3 hrs to fix

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

          public static function fromDatabase(DBInterface $db, $tb, array $fields = [], int $root = null): self
          {
              $lft = null;
              $rgt = null;
              $lvl = null;
      Severity: Minor
      Found in src/Tree.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

      File Tree.php has 290 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace vakata\phptree;
      
      use vakata\database\DBInterface;
      Severity: Minor
      Found in src/Tree.php - About 2 hrs to fix

        Method fromDatabase has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function fromDatabase(DBInterface $db, $tb, array $fields = [], int $root = null): self
            {
                $lft = null;
                $rgt = null;
                $lvl = null;
        Severity: Major
        Found in src/Tree.php - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                          if ($kk == 'parent' && $v[$vv] == null) {
                              $v[$vv] = null;
                          } elseif ($kk == 'parent' && isset($root) && (int)$v[$fields['id']] === $root) {
                              $v[$vv] = null;
                          } elseif ($kk == 'position' && isset($root) && (int)$v[$fields['id']] === $root) {
          Severity: Critical
          Found in src/Tree.php - About 1 hr to fix

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

                public static function fromAdjacencyArray(
                    array $nodes = [],
                    string $id = 'id',
                    string $parent = 'parent',
                    string $position = null,
            Severity: Minor
            Found in src/Tree.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 fromAdjacencyArray has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function fromAdjacencyArray(
                    array $nodes = [],
                    string $id = 'id',
                    string $parent = 'parent',
                    string $position = null,
            Severity: Minor
            Found in src/Tree.php - About 1 hr to fix

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

                  public static function fromNestedSetArray(
                      array $nodes = [],
                      string $id = 'id',
                      string $left = 'left',
                      string $right = 'right'
              Severity: Minor
              Found in src/Tree.php - About 1 hr to fix

                Method fromAdjacencyArray has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        array $nodes = [],
                        string $id = 'id',
                        string $parent = 'parent',
                        string $position = null,
                        int $rootID = null
                Severity: Minor
                Found in src/Tree.php - About 35 mins to fix

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

                      public static function fromNestedSetArray(
                          array $nodes = [],
                          string $id = 'id',
                          string $left = 'left',
                          string $right = 'right'
                  Severity: Minor
                  Found in src/Tree.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

                  Severity
                  Category
                  Status
                  Source
                  Language