railpage/railpagecore

View on GitHub
lib/SiteMessages/SiteMessage.php

Summary

Maintainability
C
1 day
Test Coverage

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

        public function __construct($id = false) {
            parent::__construct(); 
            
            if ($id && filter_var($id, FILTER_VALIDATE_INT)) {
                $this->id = $id;
Severity: Minor
Found in lib/SiteMessages/SiteMessage.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 __construct has a boolean flag argument $id, which is a certain sign of a Single Responsibility Principle violation.
Open

        public function __construct($id = false) {
Severity: Minor
Found in lib/SiteMessages/SiteMessage.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 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("messages", $data);
                $this->id = $this->db->lastInsertId();
                
                $this->makeURLs();
Severity: Minor
Found in lib/SiteMessages/SiteMessage.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

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

            if (empty($this->status) || !filter_var($this->status, FILTER_VALIDATE_INT)) {
                $this->status = self::STATUS_ACTIVE;
            }
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 2 other locations - About 1 hr to fix
lib/Glossary/Entry.php on lines 274..276
lib/Images/Competition.php on lines 237..239

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

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 ($row['date_start'] != "0000-00-00") {
                    $this->Start = new DateTime($row['date_start']);
                }
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 2 other locations - About 1 hr to fix
lib/Jobs/Job.php on lines 187..189
lib/SiteMessages/SiteMessage.php on lines 115..117

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

                if ($row['date_end'] != "0000-00-00") {
                    $this->End = new DateTime($row['date_end']);
                }
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 2 other locations - About 1 hr to fix
lib/Jobs/Job.php on lines 187..189
lib/SiteMessages/SiteMessage.php on lines 111..113

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

                "date_start" => $this->Start instanceof DateTime ? $this->Start->format("Y-m-d") : "0000-00-00",
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 7 other locations - About 45 mins to fix
lib/Images/Competition.php on lines 314..314
lib/Images/Competition.php on lines 315..315
lib/Images/Competition.php on lines 316..316
lib/Images/Competition.php on lines 317..317
lib/Notifications/Notification.php on lines 225..225
lib/Reminders/Reminder.php on lines 224..224
lib/SiteMessages/SiteMessage.php on lines 159..159

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

                "date_end" => $this->End instanceof DateTime ? $this->End->format("Y-m-d") : "0000-00-00"
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 7 other locations - About 45 mins to fix
lib/Images/Competition.php on lines 314..314
lib/Images/Competition.php on lines 315..315
lib/Images/Competition.php on lines 316..316
lib/Images/Competition.php on lines 317..317
lib/Notifications/Notification.php on lines 225..225
lib/Reminders/Reminder.php on lines 224..224
lib/SiteMessages/SiteMessage.php on lines 158..158

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

                $this->title = isset($row['message_title']) ? $row['message_title'] : "";
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 2 other locations - About 45 mins to fix
lib/News/Topic.php on lines 164..164
lib/Timetables/Point.php on lines 107..107

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

            $this->url->edit = sprintf("/administrators?mode=messages.edit&id=%d", $this->id);
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 30 other locations - About 40 mins to fix
lib/Content/Page.php on lines 155..155
lib/Events/EventDate.php on lines 161..161
lib/Feedback/FeedbackItem.php on lines 147..147
lib/Feedback/FeedbackItem.php on lines 148..148
lib/Feedback/FeedbackItem.php on lines 154..154
lib/Feedback/FeedbackItem.php on lines 155..155
lib/Forums/Post.php on lines 749..749
lib/Forums/Post.php on lines 750..750
lib/Forums/Post.php on lines 751..751
lib/Forums/Post.php on lines 752..752
lib/Forums/Post.php on lines 753..753
lib/Forums/Post.php on lines 754..754
lib/Forums/Post.php on lines 755..755
lib/Forums/Post.php on lines 756..756
lib/Ideas/Idea.php on lines 207..207
lib/Images/Camera.php on lines 131..131
lib/Images/Competition.php on lines 431..431
lib/Locos/Operator.php on lines 114..114
lib/Locos/Operator.php on lines 115..115
lib/News/Article.php on lines 481..481
lib/News/Article.php on lines 482..482
lib/News/Article.php on lines 483..483
lib/News/Article.php on lines 484..484
lib/News/Article.php on lines 485..485
lib/Newsletters/Newsletter.php on lines 267..267
lib/Newsletters/Newsletter.php on lines 268..268
lib/Newsletters/Newsletter.php on lines 269..269
lib/Newsletters/Newsletter.php on lines 270..270
lib/Reminders/Reminder.php on lines 165..165
lib/SiteMessages/SiteMessage.php on lines 194..194

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

            $this->url->dismiss = sprintf("/messages/dismiss/%d", $this->id);
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 30 other locations - About 40 mins to fix
lib/Content/Page.php on lines 155..155
lib/Events/EventDate.php on lines 161..161
lib/Feedback/FeedbackItem.php on lines 147..147
lib/Feedback/FeedbackItem.php on lines 148..148
lib/Feedback/FeedbackItem.php on lines 154..154
lib/Feedback/FeedbackItem.php on lines 155..155
lib/Forums/Post.php on lines 749..749
lib/Forums/Post.php on lines 750..750
lib/Forums/Post.php on lines 751..751
lib/Forums/Post.php on lines 752..752
lib/Forums/Post.php on lines 753..753
lib/Forums/Post.php on lines 754..754
lib/Forums/Post.php on lines 755..755
lib/Forums/Post.php on lines 756..756
lib/Ideas/Idea.php on lines 207..207
lib/Images/Camera.php on lines 131..131
lib/Images/Competition.php on lines 431..431
lib/Locos/Operator.php on lines 114..114
lib/Locos/Operator.php on lines 115..115
lib/News/Article.php on lines 481..481
lib/News/Article.php on lines 482..482
lib/News/Article.php on lines 483..483
lib/News/Article.php on lines 484..484
lib/News/Article.php on lines 485..485
lib/Newsletters/Newsletter.php on lines 267..267
lib/Newsletters/Newsletter.php on lines 268..268
lib/Newsletters/Newsletter.php on lines 269..269
lib/Newsletters/Newsletter.php on lines 270..270
lib/Reminders/Reminder.php on lines 165..165
lib/SiteMessages/SiteMessage.php on lines 193..193

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

        public function targetUser(User $User) {
            $this->User = $User;
            
            return $this;
        }
Severity: Major
Found in lib/SiteMessages/SiteMessage.php and 24 other locations - About 40 mins to fix
lib/Feedback/Feedback.php on lines 52..56
lib/Gallery/Album.php on lines 279..285
lib/Gallery/Album.php on lines 317..323
lib/Gallery/Image.php on lines 278..284
lib/Gallery/Image.php on lines 460..466
lib/Glossary/Entry.php on lines 302..306
lib/Locations/Correction.php on lines 118..124
lib/News/Article.php on lines 941..945
lib/Prerender/Prerender.php on lines 89..94
lib/Railcams/Footage.php on lines 89..95
lib/Railcams/Photo.php on lines 143..147
lib/Railcams/Storage.php on lines 95..101
lib/Railcams/Storage.php on lines 110..116
lib/Timetables/Timetables.php on lines 52..56
lib/Timetables/Timetables.php on lines 64..68
lib/Timetables/Timetables.php on lines 76..80
lib/Users/SockpuppetManager.php on lines 61..67
lib/Warnings/Warning.php on lines 249..255
lib/Warnings/Warning.php on lines 267..273
lib/AppCore.php on lines 401..407
lib/AppCore.php on lines 416..422
lib/AppCore.php on lines 431..437
lib/AppCore.php on lines 463..469
lib/AppCore.php on lines 478..484

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

The parameter $User is not named in camelCase.
Open

        public function targetUser(User $User) {
            $this->User = $User;
            
            return $this;
        }
Severity: Minor
Found in lib/SiteMessages/SiteMessage.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

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (empty($this->title)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $Start;

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function __construct($id = false) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if ($id && filter_var($id, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (is_object($this->Object)) {

Line indented incorrectly; expected 12 spaces, found 16
Open

                }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function makeURLs() {

Line indented incorrectly; expected 12 spaces, found 16
Open

                }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function commit() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $text;

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $status;

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (empty($this->status) || !filter_var($this->status, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $id;

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (empty($this->text)) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

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

        public function targetUser(User $User) {

Line indented incorrectly; expected 0 spaces, found 4
Open

    class SiteMessage extends AppCore {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $Object;

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $title;

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $End;

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (filter_var($this->id, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 12 spaces, found 16
Open

                if ($row['date_end'] != "0000-00-00") {

Line indented incorrectly; expected 12 spaces, found 16
Open

                if ($row['date_start'] != "0000-00-00") {

Line indented incorrectly; expected 4 spaces, found 8
Open

        private function validate() {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            } else {

There are no issues that match your filters.

Category
Status