plugins/categories/classes/yf_cats.class.php

Summary

Maintainability
F
3 days
Test Coverage

Function _get_items_array has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    public function _get_items_array($cat_name = '', $recursive_sort = true, $all = false)
    {
        if (empty($cat_name)) {
            $cat_name = $this->_default_cats_block;
        }
Severity: Minor
Found in plugins/categories/classes/yf_cats.class.php - About 4 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

File yf_cats.class.php has 361 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Category display handler.
 *
Severity: Minor
Found in plugins/categories/classes/yf_cats.class.php - About 4 hrs to fix

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

        public function _recursive_sort_items($items = [], $skip_item_id = 0, $parent_id = 0)
        {
            $children = [];
            $cur_group = MAIN_TYPE_USER ? $_SESSION['user_group'] : $_SESSION['admin_group'];
            foreach ((array) $items as $id => $info) {
    Severity: Minor
    Found in plugins/categories/classes/yf_cats.class.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 _get_nav_by_item_id has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        public function _get_nav_by_item_id($item_id = 0, $cat_items = [], $STPL_NAME = '', $prepare_link_callback = null)
        {
            if (empty($STPL_NAME)) {
                $STPL_NAME = __CLASS__ . '/nav_item';
            }
    Severity: Minor
    Found in plugins/categories/classes/yf_cats.class.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 _prepare_for_box has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public function _prepare_for_box($cat_items = [], $with_all = true, $parent_item_id = 0, $all = false)
        {
            if ( ! empty($cat_items) && is_string($cat_items)) {
                $cat_items = $this->_get_items_array($cat_items);
            }
    Severity: Minor
    Found in plugins/categories/classes/yf_cats.class.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 _get_items_array has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function _get_items_array($cat_name = '', $recursive_sort = true, $all = false)
        {
            if (empty($cat_name)) {
                $cat_name = $this->_default_cats_block;
            }
    Severity: Minor
    Found in plugins/categories/classes/yf_cats.class.php - About 1 hr to fix

      Method _get_nav_by_item_id has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function _get_nav_by_item_id($item_id = 0, $cat_items = [], $STPL_NAME = '', $prepare_link_callback = null)
          {
              if (empty($STPL_NAME)) {
                  $STPL_NAME = __CLASS__ . '/nav_item';
              }
      Severity: Minor
      Found in plugins/categories/classes/yf_cats.class.php - About 1 hr to fix

        Function _recursive_get_parents_ids has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function _recursive_get_parents_ids($cat_id = 0, $cat_items = [])
            {
                $parents_ids = [];
                if (empty($cat_id)) {
                    return $parents_ids;
        Severity: Minor
        Found in plugins/categories/classes/yf_cats.class.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 _recursive_get_children_ids has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function _recursive_get_children_ids($cat_id = 0, $cat_items = [], $get_sub_children = true, $return_array = false)
            {
                $children_ids = [];
                if (empty($cat_id)) {
                    return $children_ids;
        Severity: Minor
        Found in plugins/categories/classes/yf_cats.class.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 _prepare_for_box has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function _prepare_for_box($cat_items = [], $with_all = true, $parent_item_id = 0, $all = false)
            {
                if ( ! empty($cat_items) && is_string($cat_items)) {
                    $cat_items = $this->_get_items_array($cat_items);
                }
        Severity: Minor
        Found in plugins/categories/classes/yf_cats.class.php - About 1 hr to fix

          Method _recursive_get_children_ids has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function _recursive_get_children_ids($cat_id = 0, $cat_items = [], $get_sub_children = true, $return_array = false)
              {
                  $children_ids = [];
                  if (empty($cat_id)) {
                      return $children_ids;
          Severity: Minor
          Found in plugins/categories/classes/yf_cats.class.php - About 1 hr to fix

            Method _recursive_sort_items has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function _recursive_sort_items($items = [], $skip_item_id = 0, $parent_id = 0)
                {
                    $children = [];
                    $cur_group = MAIN_TYPE_USER ? $_SESSION['user_group'] : $_SESSION['admin_group'];
                    foreach ((array) $items as $id => $info) {
            Severity: Minor
            Found in plugins/categories/classes/yf_cats.class.php - About 1 hr to fix

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

                  public function _get_recursive_cat_ids($cat_id = 0, $all_cats = false)
                  {
                      $cat_id = (int) $cat_id;
                      if (empty($all_cats)) {
                          $all_cats = conf('all_cats');
              Severity: Minor
              Found in plugins/categories/classes/yf_cats.class.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

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

                  public function _get_cat_id_by_name($cat_name = '')
                  {
                      if (empty($cat_name)) {
                          $cat_name = $this->_default_cats_block;
                      }
              Severity: Minor
              Found in plugins/categories/classes/yf_cats.class.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 _count_levels has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function _count_levels($start_id = 0, &$children, $level = 0)
                  {
                      $ids = [];
                      foreach ((array) $children[$start_id] as $id => $_tmp) {
                          $ids[$id] = $level;
              Severity: Minor
              Found in plugins/categories/classes/yf_cats.class.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

              Identical blocks of code found in 6 locations. Consider refactoring.
              Open

                  public function _count_levels($start_id = 0, &$children, $level = 0)
                  {
                      $ids = [];
                      foreach ((array) $children[$start_id] as $id => $_tmp) {
                          $ids[$id] = $level;
              Severity: Major
              Found in plugins/categories/classes/yf_cats.class.php and 5 other locations - About 1 hr to fix
              plugins/categories/admin_modules/yf_category_editor.class.php on lines 540..552
              plugins/content/admin_modules/yf_manage_faq.class.php on lines 367..379
              plugins/html/classes/yf_html.class.php on lines 104..116
              plugins/sys/admin_modules/yf_menus_editor.class.php on lines 573..585
              plugins/sys/classes/yf_core_menu.class.php on lines 456..468

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 104.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status