yiisoft/yii2

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

Summary

Maintainability
F
4 days
Test Coverage

Function extractMessagesFromTokens has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
Open

    protected function extractMessagesFromTokens(array $tokens, array $translatorTokens, array $ignoreCategories)
    {
        $messages = [];
        $translatorTokensCount = count($translatorTokens);
        $matchedTokensCount = 0;
Severity: Minor
Found in framework/console/controllers/MessageController.php - About 1 day 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 saveMessagesToPO has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    protected function saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)
    {
        $file = str_replace('\\', '/', "$dirName/$catalog.po");
        FileHelper::createDirectory(dirname($file));
        $this->stdout("Saving messages to $file...\n");
Severity: Minor
Found in framework/console/controllers/MessageController.php - About 7 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 saveMessagesToDb has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
    {
        $currentMessages = [];
        $rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
        foreach ($rows as $row) {
Severity: Minor
Found in framework/console/controllers/MessageController.php - About 5 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 saveMessagesCategoryToPHP has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    protected function saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $removeUnused, $sort, $category, $markUnused)
    {
        if (is_file($fileName)) {
            $rawExistingMessages = require $fileName;
            $existingMessages = $rawExistingMessages;
Severity: Minor
Found in framework/console/controllers/MessageController.php - About 5 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

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

class MessageController extends \yii\console\Controller
{
    /**
     * @var string controller default action ID.
     */

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 initConfig has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    protected function initConfig($configFile)
    {
        $configFileContent = [];
        if ($configFile !== null) {
            $configFile = Yii::getAlias($configFile);
Severity: Minor
Found in framework/console/controllers/MessageController.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 actionExtract has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function actionExtract($configFile = null)
    {
        $this->initConfig($configFile);

        $files = FileHelper::findFiles(realpath($this->config['sourcePath']), $this->config);
Severity: Minor
Found in framework/console/controllers/MessageController.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

The class MessageController has 20 fields. Consider redesigning MessageController to keep the number of fields under 15.
Open

class MessageController extends \yii\console\Controller
{
    /**
     * @var string controller default action ID.
     */

Since: PHPMD 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example:

class Person {
     protected $one;
     private $two;
     private $three;
     [... many more fields ...]
  }

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

Function isCategoryIgnored has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    protected function isCategoryIgnored($category, array $ignoreCategories)
    {
        if (!empty($ignoreCategories)) {
            if (in_array($category, $ignoreCategories, true)) {
                return true;
Severity: Minor
Found in framework/console/controllers/MessageController.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

Method saveMessagesCategoryToPHP has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected function saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $removeUnused, $sort, $category, $markUnused)
Severity: Major
Found in framework/console/controllers/MessageController.php - About 50 mins to fix

    Method saveMessagesToDb has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
    Severity: Major
    Found in framework/console/controllers/MessageController.php - About 50 mins to fix

      Method saveMessagesToPO has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          protected function saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)
      Severity: Major
      Found in framework/console/controllers/MessageController.php - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                    if (in_array($previousToken, [T_OBJECT_OPERATOR, T_PAAMAYIM_NEKUDOTAYIM], true)) {
                                        $matchedTokensCount = 0;
                                        continue;
                                    }
        Severity: Major
        Found in framework/console/controllers/MessageController.php - About 45 mins to fix

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

              protected function saveMessagesToPHP($messages, $dirName, $overwrite, $removeUnused, $sort, $markUnused)
          Severity: Minor
          Found in framework/console/controllers/MessageController.php - About 45 mins to fix

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

                protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
                {
                    $currentMessages = [];
                    $rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
                    foreach ($rows as $row) {

            The method saveMessagesCategoryToPHP() has an NPath complexity of 2308. The configured NPath complexity threshold is 200.
            Open

                protected function saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $removeUnused, $sort, $category, $markUnused)
                {
                    if (is_file($fileName)) {
                        $rawExistingMessages = require $fileName;
                        $existingMessages = $rawExistingMessages;

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

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

            The method saveMessagesToPO() has an NPath complexity of 1734. The configured NPath complexity threshold is 200.
            Open

                protected function saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)
                {
                    $file = str_replace('\\', '/', "$dirName/$catalog.po");
                    FileHelper::createDirectory(dirname($file));
                    $this->stdout("Saving messages to $file...\n");

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

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

            The method initConfig() has an NPath complexity of 1080. The configured NPath complexity threshold is 200.
            Open

                protected function initConfig($configFile)
                {
                    $configFileContent = [];
                    if ($configFile !== null) {
                        $configFile = Yii::getAlias($configFile);

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

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

            The method saveMessagesToDb() has an NPath complexity of 276480. The configured NPath complexity threshold is 200.
            Open

                protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
                {
                    $currentMessages = [];
                    $rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
                    foreach ($rows as $row) {

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

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

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

                protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
                {
                    $currentMessages = [];
                    $rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
                    foreach ($rows as $row) {

            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

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

                protected function saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $removeUnused, $sort, $category, $markUnused)
                {
                    if (is_file($fileName)) {
                        $rawExistingMessages = require $fileName;
                        $existingMessages = $rawExistingMessages;

            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

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

                protected function saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)
                {
                    $file = str_replace('\\', '/', "$dirName/$catalog.po");
                    FileHelper::createDirectory(dirname($file));
                    $this->stdout("Saving messages to $file...\n");

            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

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

                public function actionExtract($configFile = null)
                {
                    $this->initConfig($configFile);
            
                    $files = FileHelper::findFiles(realpath($this->config['sourcePath']), $this->config);

            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

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

                protected function extractMessagesFromTokens(array $tokens, array $translatorTokens, array $ignoreCategories)
                {
                    $messages = [];
                    $translatorTokensCount = count($translatorTokens);
                    $matchedTokensCount = 0;

            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

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

                protected function initConfig($configFile)
                {
                    $configFileContent = [];
                    if ($configFile !== null) {
                        $configFile = Yii::getAlias($configFile);

            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

            There are no issues that match your filters.

            Category
            Status