railpage/railpagecore

View on GitHub
lib/Content/Page.php

Summary

Maintainability
B
6 hrs
Test Coverage

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

    private function validate() {
        
        if (empty($this->title)) {
            throw new Exception("Title cannot be empty"); 
        }
Severity: Minor
Found in lib/Content/Page.php - About 35 mins to fix

Cognitive Complexity

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

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

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

Further reading

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

    private function fetch() {
        if (!$row = $this->Memcached->fetch($this->mckey)) {
            $query = "SELECT * FROM nuke_pages WHERE pid = ?";
            
            $row = $this->db->fetchRow($query, $this->id);
Severity: Minor
Found in lib/Content/Page.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

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

    private function validate() {
        
        if (empty($this->title)) {
            throw new Exception("Title cannot be empty"); 
        }
Severity: Minor
Found in lib/Content/Page.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

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

        $this->url = new Url(sprintf("/static-%s.htm", $this->permalink));
Severity: Major
Found in lib/Content/Page.php and 9 other locations - About 55 mins to fix
lib/Downloads/Category.php on lines 101..101
lib/Downloads/Category.php on lines 183..183
lib/Feedback/FeedbackItem.php on lines 143..143
lib/Forums/Thread.php on lines 236..236
lib/Forums/Thread.php on lines 358..358
lib/Images/Camera.php on lines 130..130
lib/Locos/Manufacturer.php on lines 114..114
lib/Locos/Manufacturer.php on lines 143..143
lib/Locos/Operator.php on lines 113..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 28.

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

        $this->langauge     = isset($row['clanguage']) ? $row['clanguage'] : NULL;
Severity: Major
Found in lib/Content/Page.php and 5 other locations - About 55 mins to fix
lib/Gallery/Image.php on lines 209..209
lib/Gallery/Image.php on lines 210..210
lib/Gallery/Image.php on lines 211..211
lib/News/Article.php on lines 400..400
lib/News/Article.php on lines 405..405

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

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->id)) {
            $this->mckey = sprintf("railpage:page=%d", $this->id);
            $this->fetch();
        }
Severity: Minor
Found in lib/Content/Page.php and 1 other location - About 55 mins to fix
lib/Jobs/Job.php on lines 151..154

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

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

        if (!$this->date instanceof DateTime) {
            $this->date = new DateTime; 
        }
Severity: Major
Found in lib/Content/Page.php and 13 other locations - About 50 mins to fix
lib/Downloads/Download.php on lines 285..287
lib/Gallery/Image.php on lines 177..179
lib/Gallery/Image.php on lines 326..328
lib/Glossary/Entry.php on lines 266..268
lib/Ideas/Idea.php on lines 252..254
lib/Images/Collection.php on lines 192..194
lib/Locations/Correction.php on lines 172..174
lib/Locos/Correction.php on lines 183..185
lib/News/Article.php on lines 778..780
lib/Notifications/Notification.php on lines 187..189
lib/Railcams/Camera.php on lines 363..365
lib/Railcams/Footage.php on lines 143..145
lib/Warnings/Warning.php on lines 227..229

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

            foreach ($row as $key => $val) {
                $row[$key] = stripslashes($val);
            }
Severity: Major
Found in lib/Content/Page.php and 3 other locations - About 45 mins to fix
lib/Locos/LocoClass.php on lines 351..353
lib/Locos/Maintainers/Finder.php on lines 110..112
lib/News/Article.php on lines 701..703

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

        } elseif (is_string($id) && strlen($id) > 1) {
            $query = "SELECT pid FROM nuke_pages WHERE shortname = ?";
            
            $this->id = $this->db->fetchOne($query, $id); 
        }
Severity: Major
Found in lib/Content/Page.php and 4 other locations - About 40 mins to fix
lib/Events/EventCategory.php on lines 99..101
lib/Ideas/Category.php on lines 80..91
lib/Ideas/Idea.php on lines 136..138
lib/Users/User.php on lines 980..987

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

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("/admin/pages/edit/%d", $this->id);
Severity: Major
Found in lib/Content/Page.php and 30 other locations - About 40 mins to fix
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
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

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

    }
Severity: Minor
Found in lib/Content/Page.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/Content/Page.php by phpcodesniffer

There are no issues that match your filters.

Category
Status