railpage/railpagecore

View on GitHub
lib/Forums/Forum.php

Summary

Maintainability
F
4 days
Test Coverage

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

class Forum extends Forums {
    
    /**
     * Forum status: unlocked
     * @since Version 3.9.1
Severity: Minor
Found in lib/Forums/Forum.php by phpmd

File Forum.php has 279 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Forums API
 * @since Version 3.0.1
Severity: Minor
Found in lib/Forums/Forum.php - About 2 hrs to fix

    Method load has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function load($id = false, $getParent = false) {
            if ($id === false) {
                throw new InvalidArgumentException("No valid forum ID or shortname was provided");
            }
            
    Severity: Minor
    Found in lib/Forums/Forum.php - About 1 hr to fix

      Method topics has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function topics($items_per_page = 25, $page_num = 1, $sort = "DESC") {
              
              $query = "SELECT 
                              SQL_CALC_FOUND_ROWS 
                              t.*, 
      Severity: Minor
      Found in lib/Forums/Forum.php - About 1 hr to fix

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

            public function get_permission($permission_name = false, $permissions_object = false) {
                if ($permissions_object) {
                    $this->permissions = $permissions_object;
                }
                
        Severity: Minor
        Found in lib/Forums/Forum.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 validate has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function validate() {
                
                if (!filter_var($this->catid, FILTER_VALIDATE_INT) && !$this->category instanceof Category) {
                    throw new Exception("No valid forum category has been set (hint: Forum::setCategory");
                }
        Severity: Minor
        Found in lib/Forums/Forum.php - About 1 hr to fix

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

              public function load($id = false, $getParent = false) {
                  if ($id === false) {
                      throw new InvalidArgumentException("No valid forum ID or shortname was provided");
                  }
                  
          Severity: Minor
          Found in lib/Forums/Forum.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 validate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function validate() {
                  
                  if (!filter_var($this->catid, FILTER_VALIDATE_INT) && !$this->category instanceof Category) {
                      throw new Exception("No valid forum category has been set (hint: Forum::setCategory");
                  }
          Severity: Minor
          Found in lib/Forums/Forum.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

          Avoid too many return statements within this method.
          Open

                  return false;
          Severity: Major
          Found in lib/Forums/Forum.php - About 30 mins to fix

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

                public function load($id = false, $getParent = false) {
                    if ($id === false) {
                        throw new InvalidArgumentException("No valid forum ID or shortname was provided");
                    }
                    
            Severity: Minor
            Found in lib/Forums/Forum.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 method get_permission() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
                    if ($permissions_object) {
                        $this->permissions = $permissions_object;
                    }
                    
            Severity: Minor
            Found in lib/Forums/Forum.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

            Avoid using undefined variables such as '$total' which will lead to PHP notices.
            Open

                    $topics['total_pages'] = ceil($total['total'] / $items_per_page);
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

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

            Missing class import via use statement (line '356', column '23').
            Open

                        throw new \Exception("No post ID specified for " . __CLASS__ . "::" . __FUNCTION__ . "()"); 
            Severity: Minor
            Found in lib/Forums/Forum.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 get_permission has a boolean flag argument $permission_name, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method addPost has a boolean flag argument $postID, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function addPost($postID = false) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method __construct has a boolean flag argument $forumid, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function __construct($forumid = false, $getParent = true) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method load has a boolean flag argument $getParent, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function load($id = false, $getParent = false) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method __construct has a boolean flag argument $getParent, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function __construct($forumid = false, $getParent = true) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method get_permission has a boolean flag argument $permissions_object, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method load has a boolean flag argument $id, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function load($id = false, $getParent = false) {
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Avoid assigning values to variables in if clauses and the like (line '166', column '19').
            Open

                public function __construct($forumid = false, $getParent = true) {
                    
                    parent::__construct();
                    
                    $timer = Debug::GetTimer(); 
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            IfStatementAssignment

            Since: 2.7.0

            Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($foo = 'bar') { // possible typo
                        // ...
                    }
                    if ($baz = 0) { // always false
                        // ...
                    }
                }
            }

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

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

                    } else {
                        $this->db->insert("nuke_bbforums", $data); 
                        $this->id = intval($this->db->lastInsertId());
                    }
            Severity: Minor
            Found in lib/Forums/Forum.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 unused local variables such as '$total'.
            Open

                    $topics['total_pages'] = ceil($total['total'] / $items_per_page);
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

                    if (filter_var($this->id, FILTER_VALIDATE_INT)) {
                        $where = array(
                            "forum_id = ?" => $this->id
                        );
                        
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 3 hrs to fix
            lib/Forums/Category.php on lines 188..197

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

            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 getThreads($items_per_page = 25, $page = 1) {
                    $query = "SELECT topic_id FROM nuke_bbtopics WHERE forum_id = ? LIMIT ?, ?";
                    
                    foreach ($this->db->fetchAll($query, array($this->id, ($page - 1) * $items_per_page, $items_per_page)) as $row) {
                        yield new Thread($row['topic_id']);
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 3 hrs to fix
            lib/Forums/Thread.php on lines 562..568

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

            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

                    foreach ($vars as $var) {
                        if (!filter_var($this->$var, FILTER_VALIDATE_INT)) {
                            $this->$var = 0;
                        }
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 1 hr to fix
            lib/Locos/Locomotive.php on lines 636..640

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

            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

                        $this->name         = function_exists("html_entity_decode_utf8") ? html_entity_decode_utf8($row["forum_name"]) : $row['forum_name'];
            Severity: Major
            Found in lib/Forums/Forum.php and 2 other locations - About 1 hr to fix
            lib/Forums/Forum.php on lines 210..210
            lib/Forums/Thread.php on lines 234..234

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

            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

                        $this->description  = function_exists("html_entity_decode_utf8") ? html_entity_decode_utf8($row["forum_desc"]) : $row['forum_desc'];
            Severity: Major
            Found in lib/Forums/Forum.php and 2 other locations - About 1 hr to fix
            lib/Forums/Forum.php on lines 209..209
            lib/Forums/Thread.php on lines 234..234

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

            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 7 locations. Consider refactoring.
            Open

                    if (!filter_var($this->status, FILTER_VALIDATE_INT)) {
                        $this->status = self::FORUM_UNLOCKED;
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 6 other locations - About 1 hr to fix
            lib/Events/EventDate.php on lines 219..221
            lib/Ideas/Idea.php on lines 264..266
            lib/Locations/Correction.php on lines 180..182
            lib/Notifications/Notification.php on lines 179..181
            lib/Notifications/Notification.php on lines 183..185
            lib/Users/Group.php on lines 384..386

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

            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

                    foreach ($vars as $var) {
                        $this->$var = filter_var($this->$var, FILTER_SANITIZE_STRING); 
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 1 hr to fix
            lib/Locos/Locomotive.php on lines 402..404

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

            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

                    if (empty($postID) || !$postID) {
                        throw new \Exception("No post ID specified for " . __CLASS__ . "::" . __FUNCTION__ . "()"); 
                        return false;
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 1 hr to fix
            lib/Forums/Permissions.php on lines 49..52

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

            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

                    if (!filter_var($this->catid, FILTER_VALIDATE_INT) && !$this->category instanceof Category) {
                        throw new Exception("No valid forum category has been set (hint: Forum::setCategory");
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 1 hr to fix
            lib/Users/User.php on lines 1190..1192

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

            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

                        if (filter_var($row['forum_parent'], FILTER_VALIDATE_INT) && $row['forum_parent'] > 0) {
                            $this->Parent = new Forum($row['forum_parent']);
                        }
            Severity: Major
            Found in lib/Forums/Forum.php and 1 other location - About 1 hr to fix
            lib/Feedback/Feedback.php on lines 104..115

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

            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

                    $params = array(
                        $this->id,
                        ($page_num - 1) * $items_per_page,
                        $items_per_page
                    );
            Severity: Minor
            Found in lib/Forums/Forum.php and 1 other location - About 50 mins to fix
            lib/Users/User.php on lines 1761..1765

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

            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 4 locations. Consider refactoring.
            Open

                    $topics['total_pages'] = ceil($total['total'] / $items_per_page);
            Severity: Major
            Found in lib/Forums/Forum.php and 3 other locations - About 45 mins to fix
            lib/Forums/Thread.php on lines 423..423
            lib/SiteEvent/Base.php on lines 57..57
            lib/Users/Admin.php on lines 165..165

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

            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 4 locations. Consider refactoring.
            Open

                    if (filter_var($id, FILTER_VALIDATE_INT)) {
                        #$query = "SELECT * FROM nuke_bbforums f LEFT JOIN (nuke_bbtopics t, nuke_bbposts p, nuke_bbposts_text pt) ON (f.forum_last_post_id = p.post_id AND p.topic_id = t.topic_id AND pt.post_id = p.post_id) WHERE f.forum_id = ? LIMIT 1";
                        
                        $query = "SELECT f.*, p.post_time, p.poster_id, p.post_username, pt.post_subject, pt.post_text, pt.bbcode_uid,
                                        t.topic_id, t.topic_title, t.topic_time,
            Severity: Major
            Found in lib/Forums/Forum.php and 3 other locations - About 45 mins to fix
            lib/Locos/Manufacturer.php on lines 86..92
            lib/Locos/Manufacturer.php on lines 89..92
            lib/BanControl/BanControl.php on lines 441..445

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

            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

                    $this->url = new Url(sprintf("/f-f%d.htm", $id));
            Severity: Minor
            Found in lib/Forums/Forum.php and 1 other location - About 45 mins to fix
            lib/PrivateMessages/Folder.php on lines 61..61

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

            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

                    foreach ($result as $row) {
                        $topics['topics'][$row['topic_id']] = $row;
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 2 other locations - About 45 mins to fix
            lib/Users/Group.php on lines 260..262
            lib/Users/Utility/UserUtility.php on lines 211..213

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

            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 4 locations. Consider refactoring.
            Open

                    $where = array(
                        $this->id,
                        $this->id,
                        $this->id
                    );
            Severity: Major
            Found in lib/Forums/Forum.php and 3 other locations - About 40 mins to fix
            lib/Forums/Thread.php on lines 536..540
            lib/Images/Competition.php on lines 448..452
            lib/News/Article.php on lines 1156..1160

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

            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 6 locations. Consider refactoring.
            Open

                    if ($id === false) {
                        throw new InvalidArgumentException("No valid forum ID or shortname was provided");
                    }
            Severity: Major
            Found in lib/Forums/Forum.php and 5 other locations - About 35 mins to fix
            lib/Forums/Category.php on lines 88..90
            lib/Images/Favourites.php on lines 108..110
            lib/Images/Favourites.php on lines 116..118
            lib/Images/Favourites.php on lines 174..176
            lib/Images/Favourites.php on lines 182..184

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

            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 4 locations. Consider refactoring.
            Open

                        "forum_parent" => $this->Parent instanceof Forum ? $this->Parent->id : 0
            Severity: Major
            Found in lib/Forums/Forum.php and 3 other locations - About 35 mins to fix
            lib/Downloads/Category.php on lines 167..167
            lib/Downloads/Download.php on lines 332..332
            lib/Locos/Utility/LocomotiveUtility.php on lines 92..92

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

            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 9 locations. Consider refactoring.
            Open

                    $vars = array(
                        "order", 
                        "posts",
                        "topics", 
                        "last_post",
            Severity: Major
            Found in lib/Forums/Forum.php and 8 other locations - About 30 mins to fix
            lib/Downloads/Base.php on lines 141..146
            lib/Formatting/BbcodeUtility.php on lines 111..116
            lib/Formatting/MakeClickable.php on lines 256..256
            lib/Gallery/Utility/CreateSizes.php on lines 153..153
            lib/Images/Competition.php on lines 258..258
            lib/Images/Utility/Tagger.php on lines 131..136
            lib/Locos/Locomotive.php on lines 634..634
            lib/Locos/Locomotive.php on lines 646..646

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

            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

            The parameter $page_num is not named in camelCase.
            Open

                public function topics($items_per_page = 25, $page_num = 1, $sort = "DESC") {
                    
                    $query = "SELECT 
                                    SQL_CALC_FOUND_ROWS 
                                    t.*, 
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            The parameter $items_per_page is not named in camelCase.
            Open

                public function getThreads($items_per_page = 25, $page = 1) {
                    $query = "SELECT topic_id FROM nuke_bbtopics WHERE forum_id = ? LIMIT ?, ?";
                    
                    foreach ($this->db->fetchAll($query, array($this->id, ($page - 1) * $items_per_page, $items_per_page)) as $row) {
                        yield new Thread($row['topic_id']);
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            The parameter $items_per_page is not named in camelCase.
            Open

                public function topics($items_per_page = 25, $page_num = 1, $sort = "DESC") {
                    
                    $query = "SELECT 
                                    SQL_CALC_FOUND_ROWS 
                                    t.*, 
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            The parameter $permissions_object is not named in camelCase.
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
                    if ($permissions_object) {
                        $this->permissions = $permissions_object;
                    }
                    
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            The parameter $permission_name is not named in camelCase.
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
                    if ($permissions_object) {
                        $this->permissions = $permissions_object;
                    }
                    
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            The parameter $Category is not named in camelCase.
            Open

                public function setCategory(Category $Category) {
                    
                    $this->catid = $Category->id;
                    $this->category = $Category;
                    
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            CamelCaseParameterName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name parameters.

            Example

            class ClassName {
                public function doSomething($user_name) {
                }
            }

            Source

            Function closing brace must go on the next line following the body; found 1 blank lines before brace
            Open

                }
            Severity: Minor
            Found in lib/Forums/Forum.php by phpcodesniffer

            Blank line found at end of control structure
            Open

                                
            Severity: Minor
            Found in lib/Forums/Forum.php by phpcodesniffer

            Function closing brace must go on the next line following the body; found 1 blank lines before brace
            Open

                }
            Severity: Minor
            Found in lib/Forums/Forum.php by phpcodesniffer

            The 'get_permission()' method which returns a boolean should be named 'is...()' or 'has...()'
            Open

                public function get_permission($permission_name = false, $permissions_object = false) {
                    if ($permissions_object) {
                        $this->permissions = $permissions_object;
                    }
                    
            Severity: Minor
            Found in lib/Forums/Forum.php by phpmd

            BooleanGetMethodName

            Since: 0.2

            Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

            Example

            class Foo {
                /**
                 * @return boolean
                 */
                public function getFoo() {} // bad
                /**
                 * @return bool
                 */
                public function isFoo(); // ok
                /**
                 * @return boolean
                 */
                public function getFoo($bar); // ok, unless checkParameterizedMethods=true
            }

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

            There are no issues that match your filters.

            Category
            Status