mheinzerling/php-databaseutils

View on GitHub
src/structure/Database.php

Summary

Maintainability
A
2 hrs
Test Coverage

Function migrate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function migrate(Database $before, SqlSetting $setting, array $renames = null /*TODO*/): Migration
    {
        $migration = new Migration();
        if ($this->name != $before->name) $migration->todo("TODO: rename database to >" . $this->name . "< from >" . $before->name . "<");
        $myTables = $this->topoOrder($this->getTables());
Severity: Minor
Found in src/structure/Database.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 topoOrder has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    private function topoOrder(array $tables): array
    {
        $result = [];
        while (count($tables)) {
            $added = false;
Severity: Minor
Found in src/structure/Database.php - About 55 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

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

Avoid unused parameters such as '$renames'.
Open

    public function migrate(Database $before, SqlSetting $setting, array $renames = null /*TODO*/): Migration
Severity: Minor
Found in src/structure/Database.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

Avoid unused parameters such as '$setting'.
Open

    public function toCreateSql(SqlSetting $setting): string
Severity: Minor
Found in src/structure/Database.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

Avoid using mheinzerling\commons\database\structure\count() function in while loops.
Open

        while (count($tables)) {
            $added = false;
            foreach ($tables as $name => $table) {
                if ($table->hasForeignKeysOnlyOn($result)) {
                    $result[$name] = $table;
Severity: Minor
Found in src/structure/Database.php by phpmd

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

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

TODO found
Open

        //TODO create database (if not exists); setting withDatabase
Severity: Minor
Found in src/structure/Database.php by fixme

TODO found
Open

    public function migrate(Database $before, SqlSetting $setting, array $renames = null /*TODO*/): Migration
Severity: Minor
Found in src/structure/Database.php by fixme

TODO found
Open

        if ($this->name != $before->name) $migration->todo("TODO: rename database to >" . $this->name . "< from >" . $before->name . "<");
Severity: Minor
Found in src/structure/Database.php by fixme

There are no issues that match your filters.

Category
Status