railpage/railpagecore

View on GitHub
lib/Locos/Operator.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

    private function fetch($operator_id = false) {
Severity: Minor
Found in lib/Locos/Operator.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 __construct has a boolean flag argument $operator_id, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function __construct($operator_id = false) {
Severity: Minor
Found in lib/Locos/Operator.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("operators", $data); 
            $this->id = $this->db->lastInsertId(); 
        }
Severity: Minor
Found in lib/Locos/Operator.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 12 locations. Consider refactoring.
Open

        if (!filter_var($this->organisation_id, FILTER_VALIDATE_INT)) {
            $this->organisation_id = 0;
        }
Severity: Major
Found in lib/Locos/Operator.php and 11 other locations - About 1 hr to fix
lib/Downloads/Download.php on lines 297..299
lib/Downloads/Download.php on lines 301..303
lib/Downloads/Download.php on lines 305..307
lib/Feedback/FeedbackItem.php on lines 184..186
lib/Forums/Category.php on lines 166..168
lib/Gallery/Image.php on lines 334..336
lib/Ideas/Idea.php on lines 268..270
lib/Ideas/Idea.php on lines 272..274
lib/Locations/Location.php on lines 440..442
lib/Locations/Location.php on lines 452..454
lib/Users/User.php on lines 1208..1210

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

        $this->url = new Url(sprintf("/locos/browse/operator/%d", $this->id));
Severity: Major
Found in lib/Locos/Operator.php and 9 other locations - About 55 mins to fix
lib/Content/Page.php on lines 154..154
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

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

        if (filter_var($operator_id, FILTER_VALIDATE_INT)) {
            $this->fetch($operator_id);
        }
Severity: Major
Found in lib/Locos/Operator.php and 2 other locations - About 50 mins to fix
lib/Forums/Category.php on lines 74..76
lib/PrivateMessages/Conversation.php on lines 55..57

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

        $this->url->operator = sprintf("/locos/browse/operator/%d", $this->id);
Severity: Major
Found in lib/Locos/Operator.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 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

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

        $this->url->owner = sprintf("/locos/browse/owner/%d", $this->id);
Severity: Major
Found in lib/Locos/Operator.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/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

The parameter $operator_id is not named in camelCase.
Open

    private function fetch($operator_id = false) {
        
        // Fetch the data
        $query = "SELECT * FROM operators WHERE operator_id = ?";
        
Severity: Minor
Found in lib/Locos/Operator.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 $operator_id is not named in camelCase.
Open

    public function __construct($operator_id = false) {
        
        $timer = Debug::getTimer(); 
        
        parent::__construct(); 
Severity: Minor
Found in lib/Locos/Operator.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

There are no issues that match your filters.

Category
Status