railpage/railpagecore

View on GitHub
lib/Newsletters/Newsletter.php

Summary

Maintainability
C
1 day
Test Coverage

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/Newsletters/Newsletter.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("newsletter", $data); 
                $this->id = $this->db->lastInsertId();
            }
Severity: Minor
Found in lib/Newsletters/Newsletter.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 2 locations. Consider refactoring.
Open

        public function __construct($id = false) {
            parent::__construct(); 
            
            if (filter_var($id, FILTER_VALIDATE_INT)) {
                $this->id = $id;
Severity: Major
Found in lib/Newsletters/Newsletter.php and 1 other location - About 2 hrs to fix
lib/PrivateMessages/Message.php on lines 227..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 53.

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

                "status" => array(
                    "id" => $this->status,
                    "text" => ($this->status == self::STATUS_SENT) ? "Sent" : "Draft"
                ),
Severity: Major
Found in lib/Newsletters/Newsletter.php and 2 other locations - About 1 hr to fix
lib/Events/Event.php on lines 502..505
lib/Events/EventDate.php on lines 330..333

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

                "url" => isset($this->url) && $this->url instanceof Url ? $this->url->getUrls() : array(),
Severity: Major
Found in lib/Newsletters/Newsletter.php and 1 other location - About 1 hr to fix
lib/Images/Competition.php on lines 911..911

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

            if (!is_array($this->content) || count($this->content) === 0) {
                throw new Exception("No newsletter content provided");
            }
Severity: Major
Found in lib/Newsletters/Newsletter.php and 2 other locations - About 1 hr to fix
lib/Locos/Date.php on lines 201..203
lib/Submenu.php on lines 223..225

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

            if (!filter_var($this->status)) {
                $this->status = self::STATUS_DRAFT;
            }
Severity: Major
Found in lib/Newsletters/Newsletter.php and 4 other locations - About 55 mins to fix
lib/Events/Event.php on lines 262..264
lib/Locations/Location.php on lines 444..446
lib/Locos/Correction.php on lines 187..189
lib/News/Article.php on lines 782..784

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

            if (!is_array($this->template)) {
                throw new Exception("Invalid template specified");
            }
Severity: Major
Found in lib/Newsletters/Newsletter.php and 7 other locations - About 45 mins to fix
lib/Forums/Thread.php on lines 445..447
lib/Images/Image.php on lines 446..448
lib/Jobs/Scraper.php on lines 96..98
lib/Jobs/Scraper.php on lines 192..194
lib/Locos/Date.php on lines 258..260
lib/News/Scraper.php on lines 86..88
lib/Notifications/Transport/Email.php on lines 167..169

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

            $this->recipients = json_decode($result['recipients'], true); 
Severity: Major
Found in lib/Newsletters/Newsletter.php and 22 other locations - About 45 mins to fix
lib/Assets/Asset.php on lines 150..150
lib/Chronicle/Entry.php on lines 156..156
lib/Events/Event.php on lines 207..207
lib/Events/EventDate.php on lines 154..154
lib/Gallery/Album.php on lines 136..136
lib/Gallery/Image.php on lines 208..208
lib/Ideas/Idea.php on lines 166..166
lib/Images/Camera.php on lines 116..116
lib/Images/Competition.php on lines 180..180
lib/Images/Competition.php on lines 790..790
lib/Locos/Date.php on lines 158..158
lib/Locos/LocoClass.php on lines 417..417
lib/News/Feed.php on lines 234..234
lib/News/Feed.php on lines 235..235
lib/Newsletters/Newsletter.php on lines 128..128
lib/Railcams/Storage.php on lines 201..201
lib/Sightings/Sighting.php on lines 161..161
lib/Sightings/Sighting.php on lines 162..162
lib/Timetables/Train.php on lines 174..174
lib/Users/Group.php on lines 168..168
lib/Users/User.php on lines 1068..1068
lib/SiteEvent.php on lines 135..135

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

            $this->content = json_decode($result['content'], true);
Severity: Major
Found in lib/Newsletters/Newsletter.php and 22 other locations - About 45 mins to fix
lib/Assets/Asset.php on lines 150..150
lib/Chronicle/Entry.php on lines 156..156
lib/Events/Event.php on lines 207..207
lib/Events/EventDate.php on lines 154..154
lib/Gallery/Album.php on lines 136..136
lib/Gallery/Image.php on lines 208..208
lib/Ideas/Idea.php on lines 166..166
lib/Images/Camera.php on lines 116..116
lib/Images/Competition.php on lines 180..180
lib/Images/Competition.php on lines 790..790
lib/Locos/Date.php on lines 158..158
lib/Locos/LocoClass.php on lines 417..417
lib/News/Feed.php on lines 234..234
lib/News/Feed.php on lines 235..235
lib/Newsletters/Newsletter.php on lines 129..129
lib/Railcams/Storage.php on lines 201..201
lib/Sightings/Sighting.php on lines 161..161
lib/Sightings/Sighting.php on lines 162..162
lib/Timetables/Train.php on lines 174..174
lib/Users/Group.php on lines 168..168
lib/Users/User.php on lines 1068..1068
lib/SiteEvent.php on lines 135..135

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

            if (isset($this->content['hero']) && isset($this->content['hero']['id'])) {
Severity: Minor
Found in lib/Newsletters/Newsletter.php and 1 other location - About 45 mins to fix
lib/Locos/Utility/CoverImageUtility.php on lines 38..38

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->dispatch = sprintf("/administrators?mode=newsletters.dispatch&id=%d", $this->id);
Severity: Major
Found in lib/Newsletters/Newsletter.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/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

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

            $this->url->preview = sprintf("/administrators?mode=newsletters.preview&id=%d", $this->id);
Severity: Major
Found in lib/Newsletters/Newsletter.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 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

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

            $this->url->sendtest = sprintf("/administrators?mode=newsletters.sendtest&id=%d", $this->id);
Severity: Major
Found in lib/Newsletters/Newsletter.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 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

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

            $this->url->edit = sprintf("/administrators?mode=newsletters.edit&id=%d", $this->id);
Severity: Major
Found in lib/Newsletters/Newsletter.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 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

The parameter $Image is not named in camelCase.
Open

        public function setHeroImage(Image $Image) {
            $this->content['hero'] = $Image->getArray(); 
            
            if (strpos($this->content['hero']['url']['canonical'], ":///") !== false) {
                $this->content['hero']['url']['canonical'] = sprintf("http://www.railpage.com.au/photos/%d", $this->content['hero']['id']);
Severity: Minor
Found in lib/Newsletters/Newsletter.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

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (strpos($this->content['hero']['url']['canonical'], ":///") !== false) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function getHeroImage() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        private function makeURLs() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!is_array($this->template)) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!is_array($this->content) || count($this->content) === 0) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $id;

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (isset($this->content['hero']) && isset($this->content['hero']['id'])) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function commit() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        private function load() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $status;

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $subject;

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 $recipients = [];

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (filter_var($id, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        private function validate() {

Line indented incorrectly; expected 8 spaces, found 12
Open

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

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function setHeroImage(Image $Image) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

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

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function __construct($id = false) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!filter_var($this->status)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $template;

Line indented incorrectly; expected 4 spaces, found 8
Open

        public $content;

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if ($hero instanceof Image) {

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

            } else {

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

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function getArray() {

Line indented incorrectly; expected 0 spaces, found 4
Open

    class Newsletter extends AppCore {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

There are no issues that match your filters.

Category
Status