railpage/railpagecore

View on GitHub
lib/Locos/Manufacturer.php

Summary

Maintainability
D
1 day
Test Coverage

Function __construct has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function __construct($id = NULL) {

        $timer = Debug::getTimer();

        parent::__construct();
Severity: Minor
Found in lib/Locos/Manufacturer.php - About 1 hr 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

Method __construct has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __construct($id = NULL) {

        $timer = Debug::getTimer();

        parent::__construct();
Severity: Minor
Found in lib/Locos/Manufacturer.php - About 1 hr to fix

    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("loco_manufacturer", $data);
                $this->id = $this->db->lastInsertId();
            }
    Severity: Minor
    Found in lib/Locos/Manufacturer.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

                    if (empty( $this->slug )) {
                        $proposal = ContentUtility::generateUrlSlug($this->name, 30);
    
                        $query = "SELECT manufacturer_id FROM loco_manufacturer WHERE slug = ?";
                        $result = $this->db->fetchAll($query, $proposal);
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 1 other location - About 4 hrs to fix
    lib/Locos/Type.php on lines 92..104

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

    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

            return array(
                "id"          => $this->id,
                "name"        => $this->name,
                "description" => $this->desc,
                "url"         => $this->url->getURLs()
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 2 other locations - About 1 hr to fix
    lib/Locos/LocoClass.php on lines 1169..1174
    lib/Locos/Maintainers/Finder.php on lines 152..157

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

    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

            foreach ($this->db->fetchAll($query, array( $this->id, $this->id )) as $row) {
                $LocoClass = new LocoClass($row['id']);
    
                $return[] = $LocoClass->getArray();
            }
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 4 other locations - About 1 hr to fix
    lib/Images/Competitions.php on lines 123..126
    lib/Locos/Type.php on lines 191..195
    lib/Newsletters/Newsletters.php on lines 85..88
    lib/Sightings/Sightings.php on lines 119..122

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

            $data = array(
                "manufacturer_name" => $this->name,
                "manufacturer_desc" => $this->desc,
                "slug"              => $this->slug
            );
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 5 other locations - About 55 mins to fix
    lib/Events/EventCategory.php on lines 149..153
    lib/Images/Collection.php on lines 268..272
    lib/Images/Collection.php on lines 291..295
    lib/News/Topic.php on lines 375..379
    lib/PrivateMessages/Message.php on lines 504..508

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

    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/builder/%s", $this->slug));
    Severity: Major
    Found in lib/Locos/Manufacturer.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 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 10 locations. Consider refactoring.
    Open

                $this->url = new Url(sprintf("/locos/builder/%s", $this->slug));
    Severity: Major
    Found in lib/Locos/Manufacturer.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/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 4 locations. Consider refactoring.
    Open

                } elseif (is_string($id)) {
                    $query = "SELECT * FROM loco_manufacturer WHERE slug = ?";
                    $row = $this->db->fetchRow($query, $id);
                }
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 3 other locations - About 45 mins to fix
    lib/Forums/Forum.php on lines 191..204
    lib/Locos/Manufacturer.php on lines 86..92
    lib/BanControl/BanControl.php on lines 441..445

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

                if (filter_var($id, FILTER_VALIDATE_INT)) {
                    $query = "SELECT * FROM loco_manufacturer WHERE manufacturer_id = ?";
                    $row = $this->db->fetchRow($query, $id);
                } elseif (is_string($id)) {
                    $query = "SELECT * FROM loco_manufacturer WHERE slug = ?";
    Severity: Major
    Found in lib/Locos/Manufacturer.php and 3 other locations - About 45 mins to fix
    lib/Forums/Forum.php on lines 191..204
    lib/Locos/Manufacturer.php on lines 89..92
    lib/BanControl/BanControl.php on lines 441..445

    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

    There are no issues that match your filters.

    Category
    Status