phpbb-extensions/boardrules

View on GitHub
controller/admin_controller.php

Summary

Maintainability
D
2 days
Test Coverage

File admin_controller.php has 405 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
*
* Board Rules extension for the phpBB Forum Software package.
*
Severity: Minor
Found in controller/admin_controller.php - About 5 hrs to fix

    Method add_edit_rule_data has 113 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function add_edit_rule_data($entity, $data)
        {
            // Get form's POST actions (submit or preview)
            $submit = $this->request->is_set_post('submit');
            $preview = $this->request->is_set_post('preview');
    Severity: Major
    Found in controller/admin_controller.php - About 4 hrs to fix

      Function add_edit_rule_data has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function add_edit_rule_data($entity, $data)
          {
              // Get form's POST actions (submit or preview)
              $submit = $this->request->is_set_post('submit');
              $preview = $this->request->is_set_post('preview');
      Severity: Minor
      Found in controller/admin_controller.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

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

      class admin_controller implements admin_interface
      {
          /** @var \phpbb\config\config */
          protected $config;
      
      
      Severity: Minor
      Found in controller/admin_controller.php by phpmd

      Method __construct has 13 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public function __construct(\phpbb\config\config $config, ContainerInterface $container, \phpbb\controller\helper $controller_helper, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $lang, \phpbb\log\log $log, \phpbb\notification\manager $notification_manager, \phpbb\request\request $request, \phpbb\boardrules\operators\rule $rule_operator, \phpbb\template\template $template, \phpbb\user $user, $root_path, $php_ext)
      Severity: Major
      Found in controller/admin_controller.php - About 1 hr to fix

        Method display_rules has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function display_rules($language, $parent_id = 0)
            {
                // Grab all the rules in the current user's language
                $entities = $this->rule_operator->get_rules($language, $parent_id);
        
        
        Severity: Minor
        Found in controller/admin_controller.php - About 1 hr to fix

          Method display_options has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function display_options()
              {
                  // Create a form key for preventing CSRF attacks
                  add_form_key('boardrules_settings');
          
          
          Severity: Minor
          Found in controller/admin_controller.php - About 1 hr to fix

            Function build_parent_select_menu has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function build_parent_select_menu($entity, $parent_id = 0)
                {
                    // Prepare rule pull-down field
                    $rule_menu_items = $this->rule_operator->get_rules($entity->get_language());
            
            
            Severity: Minor
            Found in controller/admin_controller.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

            The method __construct has 13 parameters. Consider reducing the number of parameters to less than 10.
            Open

                public function __construct(\phpbb\config\config $config, ContainerInterface $container, \phpbb\controller\helper $controller_helper, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $lang, \phpbb\log\log $log, \phpbb\notification\manager $notification_manager, \phpbb\request\request $request, \phpbb\boardrules\operators\rule $rule_operator, \phpbb\template\template $template, \phpbb\user $user, $root_path, $php_ext)
                {
                    $this->config = $config;
                    $this->container = $container;
                    $this->controller_helper = $controller_helper;
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

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

                protected function add_edit_rule_data($entity, $data)
                {
                    // Get form's POST actions (submit or preview)
                    $submit = $this->request->is_set_post('submit');
                    $preview = $this->request->is_set_post('preview');
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            The method add_edit_rule_data() has an NPath complexity of 526500. The configured NPath complexity threshold is 200.
            Open

                protected function add_edit_rule_data($entity, $data)
                {
                    // Get form's POST actions (submit or preview)
                    $submit = $this->request->is_set_post('submit');
                    $preview = $this->request->is_set_post('preview');
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            NPathComplexity

            Since: 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 https://phpmd.org/rules/codesize.html#npathcomplexity

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

                protected function add_edit_rule_data($entity, $data)
                {
                    // Get form's POST actions (submit or preview)
                    $submit = $this->request->is_set_post('submit');
                    $preview = $this->request->is_set_post('preview');
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            CyclomaticComplexity

            Since: 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 https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The class admin_controller has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13.
            Open

            class admin_controller implements admin_interface
            {
                /** @var \phpbb\config\config */
                protected $config;
            
            
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            CouplingBetweenObjects

            Since: 1.1.0

            A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

            Example

            class Foo {
                /**
                 * @var \foo\bar\X
                 */
                private $x = null;
            
                /**
                 * @var \foo\bar\Y
                 */
                private $y = null;
            
                /**
                 * @var \foo\bar\Z
                 */
                private $z = null;
            
                public function setFoo(\Foo $foo) {}
                public function setBar(\Bar $bar) {}
                public function setBaz(\Baz $baz) {}
            
                /**
                 * @return \SplObjectStorage
                 * @throws \OutOfRangeException
                 * @throws \InvalidArgumentException
                 * @throws \ErrorException
                 */
                public function process(\Iterator $it) {}
            
                // ...
            }

            Source https://phpmd.org/rules/design.html#couplingbetweenobjects

            Missing class import via use statement (line '626', column '25').
            Open

                        $json_response = new \phpbb\json_response;
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            The method add_edit_rule_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        {
                            // Add a new rule entity to the database
                            try
                            {
                                $this->rule_operator->add_rule($entity, $data['rule_language'], $data['rule_parent_id']);
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            The method display_language_selection uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    {
                        // If there is only one available language its index is 0
                        // and that language is the default board language.
                        // We do not need any loops here to get its iso code.
                        $this->display_rules($rows[0]['lang_iso']);
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            The method send_notification uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    {
                        // Request confirmation from the user to send notification to all users
                        // Build a hidden array of the form data
                        confirm_box(false, $this->lang->lang('ACP_BOARDRULES_NOTIFY_CONFIRM'), build_hidden_fields(array(
                            'action_send_notification' => true,
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            The method delete_rule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    {
                        $is_cat = (int) ($entity->get_right_id() - $entity->get_left_id() > 1);
            
                        // Request confirmation from the user to delete the rule
                        confirm_box(false, $this->lang->lang('ACP_DELETE_RULE_CONFIRM', $is_cat), build_hidden_fields(array(
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid excessively long variable names like $message_parse_options. Keep variable name length under 20.
            Open

                    $message_parse_options = array(
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#longvariable

            Avoid excessively long variable names like $boardrules_list_style. Keep variable name length under 20.
            Open

                    $boardrules_list_style = $this->request->variable('boardrules_list_style', '');
            Severity: Minor
            Found in controller/admin_controller.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#longvariable

            There are no issues that match your filters.

            Category
            Status