plugins/categories/admin_modules/yf_category_editor.class.php

Summary

Maintainability
F
6 days
Test Coverage

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

<?php

/**
 * Categories editor.
 *
Severity: Major
Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 day to fix

    yf_category_editor has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class yf_category_editor
    {
        /** @var int */
        public $ITEMS_PER_PAGE = 100;
        /** @var bool */
    Severity: Minor
    Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 3 hrs to fix

      Method _show_category_contents has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function _show_category_contents($params = [])
          {
              $ICONS_PATH = 'uploads/icons/';
              $MEDIA_PATH = WEB_PATH;
              $force_stpl_name = isset($params['force_stpl_name']) ? $params['force_stpl_name'] : false;
      Severity: Major
      Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 2 hrs to fix

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

            public function _show_category_contents($params = [])
            {
                $ICONS_PATH = 'uploads/icons/';
                $MEDIA_PATH = WEB_PATH;
                $force_stpl_name = isset($params['force_stpl_name']) ? $params['force_stpl_name'] : false;
        Severity: Minor
        Found in plugins/categories/admin_modules/yf_category_editor.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 drag_items has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            public function drag_items()
            {
                $cat_info = db()->get('SELECT * FROM ' . db('categories') . ' WHERE name="' . db()->es($_GET['id']) . '" OR id=' . (int) ($_GET['id']));
                if ( ! $cat_info) {
                    return _e('No such category');
        Severity: Minor
        Found in plugins/categories/admin_modules/yf_category_editor.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

        Method drag_items has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function drag_items()
            {
                $cat_info = db()->get('SELECT * FROM ' . db('categories') . ' WHERE name="' . db()->es($_GET['id']) . '" OR id=' . (int) ($_GET['id']));
                if ( ! $cat_info) {
                    return _e('No such category');
        Severity: Minor
        Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 2 hrs to fix

          Method edit_item has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function edit_item()
              {
                  $item_info = db()->query_fetch('SELECT * FROM ' . db('category_items') . ' WHERE id=' . (int) ($_GET['id']));
                  if ( ! $item_info['id']) {
                      return _e('No such item!');
          Severity: Minor
          Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 hr to fix

            Method _drag_tpl_items has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function _drag_tpl_items(&$items)
                {
                    $body = [];
            
                    $form = _class('form2');
            Severity: Minor
            Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 hr to fix

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

                  public function show_items()
                  {
                      $cat_info = db()->get('SELECT * FROM ' . db('categories') . ' WHERE name="' . db()->es($_GET['id']) . '" OR id=' . (int) ($_GET['id']));
                      if ( ! $cat_info) {
                          return _e('No such category');
              Severity: Minor
              Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 hr to fix

                Method add_item has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function add_item()
                    {
                        $cat_info = db()->query_fetch('SELECT * FROM ' . db('categories') . ' WHERE id=' . (int) ($_GET['id']));
                        if (empty($cat_info['id'])) {
                            return _e('No such category!');
                Severity: Minor
                Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 hr to fix

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

                      public function edit_item()
                      {
                          $item_info = db()->query_fetch('SELECT * FROM ' . db('category_items') . ' WHERE id=' . (int) ($_GET['id']));
                          if ( ! $item_info['id']) {
                              return _e('No such item!');
                  Severity: Minor
                  Found in plugins/categories/admin_modules/yf_category_editor.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 clone_cat has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function clone_cat()
                      {
                          $_GET['id'] = (int) ($_GET['id']);
                          if ( ! empty($_GET['id'])) {
                              $cat_info = db()->query_fetch('SELECT * FROM ' . db('categories') . ' WHERE id=' . (int) ($_GET['id']));
                  Severity: Minor
                  Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 1 hr to fix

                    Function _drag_tpl_items has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function _drag_tpl_items(&$items)
                        {
                            $body = [];
                    
                            $form = _class('form2');
                    Severity: Minor
                    Found in plugins/categories/admin_modules/yf_category_editor.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 add_item has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function add_item()
                        {
                            $cat_info = db()->query_fetch('SELECT * FROM ' . db('categories') . ' WHERE id=' . (int) ($_GET['id']));
                            if (empty($cat_info['id'])) {
                                return _e('No such category!');
                    Severity: Minor
                    Found in plugins/categories/admin_modules/yf_category_editor.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 show_items has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function show_items()
                        {
                            $cat_info = db()->get('SELECT * FROM ' . db('categories') . ' WHERE name="' . db()->es($_GET['id']) . '" OR id=' . (int) ($_GET['id']));
                            if ( ! $cat_info) {
                                return _e('No such category');
                    Severity: Minor
                    Found in plugins/categories/admin_modules/yf_category_editor.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 _auto_update_items_orders has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function _auto_update_items_orders($cat_id)
                        {
                            if ( ! $cat_id) {
                                return false;
                            }
                    Severity: Minor
                    Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 45 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 clone_cat has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function clone_cat()
                        {
                            $_GET['id'] = (int) ($_GET['id']);
                            if ( ! empty($_GET['id'])) {
                                $cat_info = db()->query_fetch('SELECT * FROM ' . db('categories') . ' WHERE id=' . (int) ($_GET['id']));
                    Severity: Minor
                    Found in plugins/categories/admin_modules/yf_category_editor.class.php - About 35 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/admin_modules/yf_category_editor.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 2 locations. Consider refactoring.
                    Open

                                foreach ((array) json_decode((string) $_POST['items'], $assoc = true) as $order_id => $info) {
                                    $item_id = (int) $info['item_id'];
                                    if ( ! $item_id || ! isset($items[$item_id])) {
                                        continue;
                                    }
                    plugins/sys/admin_modules/yf_menus_editor.class.php on lines 291..311

                    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 172.

                    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

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        public function _auto_update_items_orders($cat_id)
                        {
                            if ( ! $cat_id) {
                                return false;
                            }
                    plugins/sys/admin_modules/yf_menus_editor.class.php on lines 350..375

                    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 146.

                    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

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

                        public function _recursive_sort_items($items = [], $skip_item_id = 0, $parent_id = 0, $level = 0)
                        {
                            $children = [];
                            foreach ((array) $items as $id => $info) {
                                $parent_id = $info['parent_id'];
                    plugins/content/admin_modules/yf_manage_faq.class.php on lines 345..361
                    plugins/sys/admin_modules/yf_menus_editor.class.php on lines 551..567

                    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 145.

                    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

                    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;
                    plugins/categories/classes/yf_cats.class.php on lines 137..149
                    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

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            if ( ! empty($cat_info)) {
                                db()->UPDATE('categories', ['active' => (int) ! $cat_info['active']], 'id=' . (int) ($cat_info['id']));
                                common()->admin_wall_add(['category ' . $cat_info['name'] . ' ' . ($cat_info['active'] ? 'inactivated' : 'activated'), $_GET['id']]);
                            }
                    plugins/sys/admin_modules/yf_menus_editor.class.php on lines 743..746
                    plugins/user/admin_modules/yf_user_groups.class.php on lines 104..109

                    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 102.

                    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

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

                                if ($icon) {
                                    // Icon class from bootstrap icon class names
                                    if (preg_match('/^icon\-[a-z0-9_-]+$/i', $icon) || (strpos($icon, '.') === false)) {
                                        $icon_class = $icon;
                                    } else {
                    Severity: Major
                    Found in plugins/categories/admin_modules/yf_category_editor.class.php and 2 other locations - About 45 mins to fix
                    plugins/sys/admin_modules/yf_menus_editor.class.php on lines 478..488
                    plugins/sys/classes/yf_core_menu.class.php on lines 119..129

                    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 96.

                    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