mheinzerling/php-databaseutils

View on GitHub

Showing 115 of 115 total issues

Function toBuilderCode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function toBuilderCode(): string
    {
        $result = "\n    ->table(\"" . $this->name . "\")";
        foreach ($this->indexes as $index) {
            $result .= $index->toBuilderCode();
Severity: Minor
Found in src/structure/Table.php - About 45 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

Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct(array $fields = null, string $name = null, Table &$referenceTable = null, array $referenceFields, ReferenceOption $onUpdate, ReferenceOption $onDelete)
Severity: Minor
Found in src/structure/index/ForeignKey.php - About 45 mins to fix

    The class Table has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
    Open

    class Table
    {
        /**
         * @var Database
         */
    Severity: Minor
    Found in src/structure/Table.php by phpmd

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

    The class TableBuilder has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13.
    Open

    class TableBuilder
    {
        /**
         * @var Table
         */

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

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

        public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null)
    Severity: Minor
    Found in src/logging/LoggingPDOStatement.php - About 35 mins to fix

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

          public function bindParam($parameter, &$variable, $data_type = \PDO::PARAM_STR, $length = null, $driver_options = null)
      Severity: Minor
      Found in src/logging/LoggingPDOStatement.php - About 35 mins to fix

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

            private static function onDuplicateAndExec(\PDO $pdo, int $onDuplicate, array $keys, string $sql, array $params): int
        Severity: Minor
        Found in src/DatabaseUtils.php - About 35 mins to fix

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

              public function foreign(string $name = null, string $table, string $reference, ReferenceOption $onUpdate, ReferenceOption $onDelete): FieldBuilder
          Severity: Minor
          Found in src/structure/builder/FieldBuilder.php - About 35 mins to fix

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

                public static function insertMultiple(\PDO $pdo, string $table, array $keys, array $datas, int $onDuplicate = self::DUPLICATE_FAIL): int
            Severity: Minor
            Found in src/DatabaseUtils.php - About 35 mins to fix

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

                  public function hasForeignKeysOnlyOn(array $tables): bool
                  {
                      if (empty($this->indexes)) return true;
                      $names = array_keys($tables);
                      foreach ($this->indexes as $index) {
              Severity: Minor
              Found in src/structure/Table.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 fromSql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function fromSql(string $type, string $collation = null, bool $isBoolean = false): Type
                  {
                      //TODO register parser
                      $result = BoolType::parseBool($type);
                      if ($result != null) return $result;
              Severity: Minor
              Found in src/structure/type/Type.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 toSql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function toSql(SqlSetting $setting): string
                  {
                      $sql = '`' . $this->name . '` ';
                      $sql .= $this->type->toSql() . ' ';
                      if (!$this->null) $sql .= "NOT NULL ";
              Severity: Minor
              Found in src/structure/Field.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 fromSqlCreate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function fromSqlCreate(DatabaseBuilder $db, string $sql): void
                  {
                      list($tableName, $remaining) = explode('(', $sql, 2);
                      $tableName = trim(str_replace(["CREATE TABLE", "IF NOT EXISTS", "`"], "", $tableName));
                      $tb = $db->table($tableName);
              Severity: Minor
              Found in src/structure/builder/TableBuilder.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

              Avoid too many return statements within this method.
              Open

                      if ($result != null) return $result;
              Severity: Major
              Found in src/structure/type/Type.php - About 30 mins to fix

                Missing class import via use statement (line '262', column '43').
                Open

                        if (!empty($remaining)) throw new \Exception("TODO: unhandled SQL CREATE TABLE statement configuration parts >" . $remaining . "<");

                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 '158', column '51').
                Open

                        else if (count($primaries) > 1) throw new \Exception("Unsupported");
                Severity: Minor
                Found in src/structure/Table.php by phpmd

                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 '177', column '60').
                Open

                            if ($primary instanceof LazyPrimary) throw new \Exception("Unsupported");

                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 '66', column '67').
                Open

                            if ($added === false && count($tables) > 0) throw new \Exception("Not supported cyclic dependency in " . implode(", ", array_keys($tables)));
                Severity: Minor
                Found in src/structure/Database.php by phpmd

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

                    public function unique(bool $unique = true): FieldBuilder

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

                    public function index(bool $index = true): FieldBuilder

                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

                Severity
                Category
                Status
                Source
                Language