railpage/railpagecore

View on GitHub
lib/Notifications/Notifications.php

Summary

Maintainability
C
1 day
Test Coverage

Function setPushSubscription has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

        public static function setPushSubscription(User $User, $subscription, $enabled = null) {
            
            $endpoint = false;
            $registration_id = false;
            $provider = false;
Severity: Minor
Found in lib/Notifications/Notifications.php - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method setPushSubscription has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public static function setPushSubscription(User $User, $subscription, $enabled = null) {
            
            $endpoint = false;
            $registration_id = false;
            $provider = false;
Severity: Minor
Found in lib/Notifications/Notifications.php - About 1 hr to fix

    The method setPushSubscription() has an NPath complexity of 336. The configured NPath complexity threshold is 200.
    Open

            public static function setPushSubscription(User $User, $subscription, $enabled = null) {
                
                $endpoint = false;
                $registration_id = false;
                $provider = false;
    Severity: Minor
    Found in lib/Notifications/Notifications.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 setPushSubscription() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
    Open

            public static function setPushSubscription(User $User, $subscription, $enabled = null) {
                
                $endpoint = false;
                $registration_id = false;
                $provider = false;
    Severity: Minor
    Found in lib/Notifications/Notifications.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

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

            public function getNotificationsByTransport($transport = self::TRANSPORT_EMAIL) {
                $query = "SELECT * FROM notifications WHERE transport = ?";
                
                return $this->db->fetchAll($query, $transport);
            }
    Severity: Major
    Found in lib/Notifications/Notifications.php and 1 other location - About 1 hr to fix
    lib/Notifications/Notifications.php on lines 70..74

    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

            public function getNotificationsWithStatus($status = self::STATUS_QUEUED) {
                $query = "SELECT * FROM notifications WHERE status = ?";
                
                return $this->db->fetchAll($query, $status);
            }
    Severity: Major
    Found in lib/Notifications/Notifications.php and 1 other location - About 1 hr to fix
    lib/Notifications/Notifications.php on lines 83..87

    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

                $return = array(
                    "page" => $page, 
                    "limit" => $items_per_page,
                    "total" => $this->db->fetchOne("SELECT FOUND_ROWS() AS total"),
                    "notifications" => $result
    Severity: Major
    Found in lib/Notifications/Notifications.php and 1 other location - About 1 hr to fix
    lib/Forums/Forums.php on lines 1026..1031

    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

                    $data = [
                        "user_id" => $User->id,
                        "provider" => $provider,
                        "endpoint" => $endpoint,
                        "registration_id" => $registration_id
    Severity: Minor
    Found in lib/Notifications/Notifications.php and 1 other location - About 1 hr to fix
    lib/Locos/Locomotive.php on lines 1074..1079

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

    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 ($row['endpoint'] == $endpoint && $row['registration_id'] == $registration_id) {
                            return;
                        }
    Severity: Minor
    Found in lib/Notifications/Notifications.php and 1 other location - About 35 mins to fix
    lib/Users/Utility/AvatarUtility.php on lines 62..64

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

                if (!isset($this->Recipient) || !$this->Recipient instanceof User) {
                    throw new Exception("\$this->Recipient is not an instance of \\Railpage\\Users\\User");
                }
    Severity: Minor
    Found in lib/Notifications/Notifications.php and 2 other locations - About 30 mins to fix
    lib/Forums/Forums.php on lines 732..734
    lib/News/Article.php on lines 774..776

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

    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 $User is not named in camelCase.
    Open

            public static function setPushSubscription(User $User, $subscription, $enabled = null) {
                
                $endpoint = false;
                $registration_id = false;
                $provider = false;
    Severity: Minor
    Found in lib/Notifications/Notifications.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 getPushSubscriptions(User $User) {
                
                $Database = AppCore::GetDatabase(); 
                
                $rs = $Database->fetchAll("SELECT * FROM nuke_user_push WHERE user_id = ?", $User->id); 
    Severity: Minor
    Found in lib/Notifications/Notifications.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 function getPastNotificationsForUser(User $User) {
                
                $query = "SELECT n.id, n.author, n.transport, n.status, n.date_queued, n.date_sent, n.subject, r.destination, r.date_sent
                            FROM notifications AS n 
                            LEFT JOIN notifications_recipients AS r ON r.notification_id = n.id
    Severity: Minor
    Found in lib/Notifications/Notifications.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 getAllNotifications($page = 1, $items_per_page = 25) {
                $query = "SELECT SQL_CALC_FOUND_ROWS * FROM notifications ORDER BY date_queued DESC LIMIT ?, ?";
                
                $where = array(
                    ($page - 1) * $items_per_page, 
    Severity: Minor
    Found in lib/Notifications/Notifications.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

    Blank line found at end of control structure
    Open

                    

    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

            }

    Blank line found at start of control structure
    Open

                if (strpos($subscription, "https://android.googleapis.com/gcm/send/") !== false) {

    Blank line found at end of control structure
    Open

                        

    Blank line found at start of control structure
    Open

                    foreach ($result as $row) {

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

            }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                if (!$endpoint || !$registration_id || !$provider) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                if (strpos($subscription, "https://android.googleapis.com/gcm/send/") !== false) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public function getNotificationsForUser() {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public function getNotificationsWithStatus($status = self::STATUS_QUEUED) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public static function setPushSubscription(User $User, $subscription, $enabled = null) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public function getAllNotifications($page = 1, $items_per_page = 25) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        try {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

        }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public function getNotificationsByTransport($transport = self::TRANSPORT_EMAIL) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                if (!isset($this->Recipient) || !$this->Recipient instanceof User) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                if ($enabled) {

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        } catch (Exception $e) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public function getPastNotificationsForUser(User $User) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                if ($enabled == false) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                foreach ($rs as $key => $val) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            public static function getPushSubscriptions(User $User) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            }

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

        class Notifications extends AppCore {

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    foreach ($result as $row) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        if ($row['endpoint'] == $endpoint && $row['registration_id'] == $registration_id) {

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    if ($val['endpoint'] == "https://android.googleapis.com/gcm/send/") {

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    if ((!$result || count($result) === 0) && filter_var($id, FILTER_VALIDATE_INT)) {

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    }

    There are no issues that match your filters.

    Category
    Status