mdmsoft/yii2-admin

View on GitHub
components/Helper.php

Summary

Maintainability
C
1 day
Test Coverage

Function checkRoute has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public static function checkRoute($route, $params = [], $user = null)
    {
        $config = Configs::instance();
        $r = static::normalizeRoute($route, $config->advanced);
        if ($config->onlyRegisteredRoute && !isset(static::getRegisteredRoutes()[$r])) {
Severity: Minor
Found in components/Helper.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 getDefaultRoutes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    protected static function getDefaultRoutes()
    {
        if (self::$_defaultRoutes === null) {
            $manager = Configs::authManager();
            $roles = $manager->defaultRoles;
Severity: Minor
Found in components/Helper.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 getRoutesByUser has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getRoutesByUser($userId)
    {
        if (!isset(self::$_userRoutes[$userId])) {
            $cache = Configs::cache();
            if ($cache && ($routes = $cache->get([__METHOD__, $userId])) !== false) {
Severity: Minor
Found in components/Helper.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 checkRoute has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function checkRoute($route, $params = [], $user = null)
    {
        $config = Configs::instance();
        $r = static::normalizeRoute($route, $config->advanced);
        if ($config->onlyRegisteredRoute && !isset(static::getRegisteredRoutes()[$r])) {
Severity: Minor
Found in components/Helper.php - About 1 hr to fix

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

        protected static function filterRecursive($items, $user)
        {
            $result = [];
            foreach ($items as $i => $item) {
                $url = ArrayHelper::getValue($item, 'url', '#');
    Severity: Minor
    Found in components/Helper.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 true;
    Severity: Major
    Found in components/Helper.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                  return isset($routes['/*']);
      Severity: Major
      Found in components/Helper.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                            return true;
        Severity: Major
        Found in components/Helper.php - About 30 mins to fix

          Function getRegisteredRoutes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function getRegisteredRoutes()
              {
                  if (self::$_routes === null) {
                      self::$_routes = [];
                      $manager = Configs::authManager();
          Severity: Minor
          Found in components/Helper.php - About 25 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 filterActionColumn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function filterActionColumn($buttons = [], $user = null)
              {
                  if (is_array($buttons)) {
                      $result = [];
                      foreach ($buttons as $button) {
          Severity: Minor
          Found in components/Helper.php - About 25 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 normalizeRoute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected static function normalizeRoute($route, $advanced = false)
              {
                  if ($route === '') {
                      $normalized = '/' . Yii::$app->controller->getRoute();
                  } elseif (strncmp($route, '/', 1) === 0) {
          Severity: Minor
          Found in components/Helper.php - About 25 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

          There are no issues that match your filters.

          Category
          Status