railpage/railpagecore

View on GitHub
lib/Jobs/Classification.php

Summary

Maintainability
D
1 day
Test Coverage

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

    public function fetch() {

        if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
            throw new Exception("Cannot populate Railpage\Jobs\Classification - Classification ID empty or not given");
        }
Severity: Minor
Found in lib/Jobs/Classification.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 '63', column '18').
Open

    public function __construct($id) {

        parent::__construct();

        if (filter_var($id, FILTER_VALIDATE_INT)) {
Severity: Minor
Found in lib/Jobs/Classification.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

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 {
            // Insert
            $this->db->insert("jn_classifications", $data);
            $this->id = $this->db->lastInsertId();
        }
Severity: Minor
Found in lib/Jobs/Classification.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 commit() {

        $this->validate();

        $data = array(
Severity: Major
Found in lib/Jobs/Classification.php and 1 other location - About 5 hrs to fix
lib/Locos/Type.php on lines 145..165

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

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

    public function __construct($id) {

        parent::__construct();

        if (filter_var($id, FILTER_VALIDATE_INT)) {
Severity: Major
Found in lib/Jobs/Classification.php and 1 other location - About 4 hrs to fix
lib/Jobs/Location.php on lines 54..69

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

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

    public function validate() {

        if (empty( $this->name )) {
            throw new Exception("Cannot validate Railpage\Jobs\Classification - Classification name cannot be empty");
        }
Severity: Major
Found in lib/Jobs/Classification.php and 1 other location - About 2 hrs to fix
lib/Jobs/Location.php on lines 100..111

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

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 ($row = $this->db->fetchRow($query, $this->id)) {
            $this->name = $row['jn_classification_name'];
            $this->parent_id = $row['jn_parent_id'];
        }
Severity: Major
Found in lib/Jobs/Classification.php and 4 other locations - About 1 hr to fix
lib/Chronicle/EntryType.php on lines 88..91
lib/Help/Category.php on lines 83..86
lib/Jobs/Location.php on lines 86..89
lib/Railcams/Type.php on lines 78..81

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

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

        if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
            throw new Exception("Cannot populate Railpage\Jobs\Classification - Classification ID empty or not given");
        }
Severity: Major
Found in lib/Jobs/Classification.php and 24 other locations - About 1 hr to fix
lib/Downloads/Download.php on lines 313..315
lib/Events/Event.php on lines 425..427
lib/Events/Events.php on lines 130..132
lib/Images/Competition.php on lines 624..626
lib/Images/Competition.php on lines 654..656
lib/Images/Competition.php on lines 823..825
lib/Images/Competition.php on lines 860..862
lib/Images/Favourites.php on lines 112..114
lib/Images/Favourites.php on lines 178..180
lib/Locations/Location.php on lines 406..408
lib/Locations/Location.php on lines 410..412
lib/Locos/Locomotive.php on lines 622..624
lib/Locos/Locomotive.php on lines 626..628
lib/Locos/Locomotive.php on lines 897..899
lib/News/Article.php on lines 361..363
lib/News/Article.php on lines 834..836
lib/Newsletters/Newsletters.php on lines 135..137
lib/PrivateMessages/Message.php on lines 244..246
lib/PrivateMessages/Message.php on lines 452..454
lib/Railcams/Photo.php on lines 330..332
lib/Railcams/Storage.php on lines 224..226
lib/Sightings/Sighting.php on lines 133..135
lib/Users/Group.php on lines 236..238
lib/Warnings/Warning.php on lines 209..211

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

There are no issues that match your filters.

Category
Status