railpage/railpagecore

View on GitHub
lib/SiteEvent.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

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

            "args" => is_array($this->args) ? json_encode($this->args) : $this->args,
Severity: Major
Found in lib/SiteEvent.php and 2 other locations - About 1 hr to fix
lib/Ideas/Idea.php on lines 311..311
lib/Railcams/Camera.php on lines 398..398

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

        $this->args = json_decode($row['args'], true);
Severity: Major
Found in lib/SiteEvent.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/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

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

        if (empty($this->key)) {
            throw new Exception("Cannot validate site event - key cannot be empty!"); 
            return false;
        }
Severity: Major
Found in lib/SiteEvent.php and 17 other locations - About 45 mins to fix
lib/Jobs/Job.php on lines 230..233
lib/Jobs/Job.php on lines 243..246
lib/Links/Link.php on lines 136..139
lib/Links/Link.php on lines 141..144
lib/Links/Link.php on lines 146..149
lib/Locations/Location.php on lines 881..884
lib/Locations/Location.php on lines 899..902
lib/Locos/Type.php on lines 117..120
lib/Locos/WheelArrangement.php on lines 161..164
lib/News/Topic.php on lines 337..340
lib/News/Topic.php on lines 356..359
lib/Sightings/Sighting.php on lines 219..222
lib/Sightings/Sighting.php on lines 224..227
lib/Sightings/Sighting.php on lines 229..232
lib/Sightings/Sighting.php on lines 234..237
lib/SiteEvent.php on lines 148..151
lib/SiteEvent.php on lines 153..156

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

        if (empty($this->user_id)) {
            throw new Exception("Cannot validate site event - user ID cannot be empty!"); 
            return false;
        }
Severity: Major
Found in lib/SiteEvent.php and 17 other locations - About 45 mins to fix
lib/Jobs/Job.php on lines 230..233
lib/Jobs/Job.php on lines 243..246
lib/Links/Link.php on lines 136..139
lib/Links/Link.php on lines 141..144
lib/Links/Link.php on lines 146..149
lib/Locations/Location.php on lines 881..884
lib/Locations/Location.php on lines 899..902
lib/Locos/Type.php on lines 117..120
lib/Locos/WheelArrangement.php on lines 161..164
lib/News/Topic.php on lines 337..340
lib/News/Topic.php on lines 356..359
lib/Sightings/Sighting.php on lines 219..222
lib/Sightings/Sighting.php on lines 224..227
lib/Sightings/Sighting.php on lines 229..232
lib/Sightings/Sighting.php on lines 234..237
lib/SiteEvent.php on lines 148..151
lib/SiteEvent.php on lines 158..161

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

        if (empty($this->title)) {
            throw new Exception("Cannot validate site event - title cannot be empty!"); 
            return false;
        }
Severity: Major
Found in lib/SiteEvent.php and 17 other locations - About 45 mins to fix
lib/Jobs/Job.php on lines 230..233
lib/Jobs/Job.php on lines 243..246
lib/Links/Link.php on lines 136..139
lib/Links/Link.php on lines 141..144
lib/Links/Link.php on lines 146..149
lib/Locations/Location.php on lines 881..884
lib/Locations/Location.php on lines 899..902
lib/Locos/Type.php on lines 117..120
lib/Locos/WheelArrangement.php on lines 161..164
lib/News/Topic.php on lines 337..340
lib/News/Topic.php on lines 356..359
lib/Sightings/Sighting.php on lines 219..222
lib/Sightings/Sighting.php on lines 224..227
lib/Sightings/Sighting.php on lines 229..232
lib/Sightings/Sighting.php on lines 234..237
lib/SiteEvent.php on lines 153..156
lib/SiteEvent.php on lines 158..161

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

The parameter $event_id is not named in camelCase.
Open

    public function __construct($event_id = false) {
        
        parent::__construct(); 
        
        /**
Severity: Minor
Found in lib/SiteEvent.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

    }
Severity: Minor
Found in lib/SiteEvent.php by phpcodesniffer

There are no issues that match your filters.

Category
Status