railpage/railpagecore

View on GitHub
lib/Forums/Utility/ForumsUtility.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

    public static function updateUserThreadView(Thread $Thread, $User = false) {
        
        // Prevent browser prefetch/preview from creating a timestamp
        if (
            (isset($_SERVER["HTTP_X_PURPOSE"]) && (strtolower($_SERVER["HTTP_X_PURPOSE"]) == "preview")) || 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.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

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

    public static function updateUserThreadView(Thread $Thread, $User = false) {
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.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

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

        $query = sprintf("INSERT INTO nuke_bbtopics_view (topic_id, user_id, viewed) VALUES (%d, %d, CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE viewed = CURRENT_TIMESTAMP()",
            $Database->quote(intval($Thread->id)),
            $Database->quote(intval($User->id))
        );
Severity: Major
Found in lib/Forums/Utility/ForumsUtility.php and 1 other location - About 1 hr to fix
lib/News/Utility/ArticleUtility.php on lines 39..42

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

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

        if (!$User instanceof User || $User->id == 0 || $User->guest) {
            return;
        }
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.php and 1 other location - About 55 mins to fix
lib/News/Utility/ArticleUtility.php on lines 33..35

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

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

            (isset($_SERVER["HTTP_X_MOZ"]) && (strtolower($_SERVER["HTTP_X_MOZ"]) == "prefetch")) 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.php and 1 other location - About 45 mins to fix
lib/Forums/Utility/ForumsUtility.php on lines 40..40

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

            (isset($_SERVER["HTTP_X_PURPOSE"]) && (strtolower($_SERVER["HTTP_X_PURPOSE"]) == "preview")) || 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.php and 1 other location - About 45 mins to fix
lib/Forums/Utility/ForumsUtility.php on lines 41..41

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

The parameter $Thread is not named in camelCase.
Open

    public static function updateUserThreadView(Thread $Thread, $User = false) {
        
        // Prevent browser prefetch/preview from creating a timestamp
        if (
            (isset($_SERVER["HTTP_X_PURPOSE"]) && (strtolower($_SERVER["HTTP_X_PURPOSE"]) == "preview")) || 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.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 $User is not named in camelCase.
Open

    public static function updateUserThreadView(Thread $Thread, $User = false) {
        
        // Prevent browser prefetch/preview from creating a timestamp
        if (
            (isset($_SERVER["HTTP_X_PURPOSE"]) && (strtolower($_SERVER["HTTP_X_PURPOSE"]) == "preview")) || 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.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 $User is not named in camelCase.
Open

    public static function getForumNotifications(User $User) {
        
        $query = "SELECT t.topic_title, t.topic_id, CONCAT('/f-t', t.topic_id, '.htm') AS topic_url, t.topic_last_post_id, 
                        CONCAT('/f-p', t.topic_last_post_id, '.htm#', t.topic_last_post_id) AS topic_last_post_url,
                        CONCAT('/f-t', t.topic_id, '-newest.htm') AS topic_url_newest, 
Severity: Minor
Found in lib/Forums/Utility/ForumsUtility.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

    }

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

    }

Expected 0 spaces after opening bracket; newline found
Open

        if (

Opening parenthesis of a multi-line function call must be the last content on the line
Open

        $query = sprintf("INSERT INTO nuke_bbtopics_view (topic_id, user_id, viewed) VALUES (%d, %d, CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE viewed = CURRENT_TIMESTAMP()",

There are no issues that match your filters.

Category
Status