yiisoft/yii2

View on GitHub
framework/console/controllers/MigrateController.php

Summary

Maintainability
C
7 hrs
Test Coverage

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

class MigrateController extends BaseMigrateController
{
    /**
     * Maximum length of a migration name.
     * @since 2.0.13

Since: PHPMD 0.2.5

The Weighted Method Count (WMC) of a class is a good indicator of how much time and effort is required to modify and maintain this class. The WMC metric is defined as the sum of complexities of all methods declared in a class. A large number of methods also means that this class has a greater potential impact on derived classes.

Example:

class Foo {
      public function bar() {
          if ($a == $b)  {
              if ($a1 == $b1) {
                  fiddle();
              } elseif ($a2 == $b2) {
                  fiddle();
              } else {
              }
          }
      }
      public function baz() {
          if ($a == $b) {
              if ($a1 == $b1) {
                  fiddle();
              } elseif ($a2 == $b2) {
                  fiddle();
              } else {
              }
          }
      }
      // Several other complex methods
  }

Source: http://phpmd.org/rules/codesize.txt

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

    protected function generateMigrationSourceCode($params)
    {
        $parsedFields = $this->parseFields();
        $fields = $parsedFields['fields'];
        $foreignKeys = $parsedFields['foreignKeys'];
Severity: Minor
Found in framework/console/controllers/MigrateController.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 truncateDatabase has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    protected function truncateDatabase()
    {
        $db = $this->db;
        $schemas = $db->schema->getTableSchemas();

Severity: Minor
Found in framework/console/controllers/MigrateController.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 parseFields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    protected function parseFields()
    {
        $fields = [];
        $foreignKeys = [];

Severity: Minor
Found in framework/console/controllers/MigrateController.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 getMigrationHistory has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getMigrationHistory($limit)
    {
        if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) {
            $this->createMigrationHistoryTable();
        }
Severity: Minor
Found in framework/console/controllers/MigrateController.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

Avoid too many return statements within this method.
Open

        return $history;
Severity: Major
Found in framework/console/controllers/MigrateController.php - About 30 mins to fix

    The method generateMigrationSourceCode() has 104 lines of code. Current threshold is set to 100. Avoid really long methods.
    Open

        protected function generateMigrationSourceCode($params)
        {
            $parsedFields = $this->parseFields();
            $fields = $parsedFields['fields'];
            $foreignKeys = $parsedFields['foreignKeys'];

    The method generateMigrationSourceCode() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
    Open

        protected function generateMigrationSourceCode($params)
        {
            $parsedFields = $this->parseFields();
            $fields = $parsedFields['fields'];
            $foreignKeys = $parsedFields['foreignKeys'];

    Since: PHPMD 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: http://phpmd.org/rules/codesize.txt

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

            foreach ($this->fields as $index => $field) {

    Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

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

            foreach ($rows as $key => $row) {

    Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

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

                    foreach ($schema->foreignKeys as $name => $foreignKey) {

    Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

    There are no issues that match your filters.

    Category
    Status