railpage/railpagecore

View on GitHub
lib/Chronicle/Entry.php

Summary

Maintainability
D
1 day
Test Coverage

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

    public function commit() {
        
        $this->validate(); 
        
        /**
Severity: Minor
Found in lib/Chronicle/Entry.php - About 1 hr to fix

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

        public function __construct($id = null) {
            
            parent::__construct(); 
            
            if (!filter_var($id, FILTER_VALIDATE_INT)) {
    Severity: Minor
    Found in lib/Chronicle/Entry.php - About 45 mins 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

    Function validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        private function validate() {
            
            if (!$this->Author instanceof User) {
                throw new Exception("A valid user object must be set using " . __CLASS__ . "::setAuthor()");
            }
    Severity: Minor
    Found in lib/Chronicle/Entry.php - About 35 mins 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

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

        public function __construct($id = null) {
            
            parent::__construct(); 
            
            if (!filter_var($id, FILTER_VALIDATE_INT)) {
    Severity: Minor
    Found in lib/Chronicle/Entry.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 '245', column '13').
    Open

        public function commit() {
            
            $this->validate(); 
            
            /**
    Severity: Minor
    Found in lib/Chronicle/Entry.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

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

                if (filter_var($this->lat, FILTER_VALIDATE_FLOAT) && filter_var($this->lon, FILTER_VALIDATE_FLOAT)) {
                    $this->Place = new Place($this->lat, $this->lon);
                }
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 1 hr to fix
    lib/Chronicle/Entry.php on lines 259..261
    lib/Images/Image.php on lines 1540..1542

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

    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

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            if (filter_var($this->lat, FILTER_VALIDATE_FLOAT) && filter_var($this->lon, FILTER_VALIDATE_FLOAT)) {
                $data['point'] = new Zend_Db_Expr(sprintf("POINT(%s, %s)", $this->lat, $this->lon));
            }
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 1 hr to fix
    lib/Chronicle/Entry.php on lines 162..164
    lib/Images/Image.php on lines 1540..1542

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

    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 (empty($this->text) || trim($this->text) == "x") {
                $this->text = "";
            }
    Severity: Major
    Found in lib/Chronicle/Entry.php and 1 other location - About 1 hr to fix
    lib/Jobs/Job.php on lines 239..241

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

    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 (!$this->Author instanceof User) {
                throw new Exception("A valid user object must be set using " . __CLASS__ . "::setAuthor()");
            }
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 1 hr to fix
    lib/Images/Provider/Flickr.php on lines 565..567
    lib/Users/Timeline.php on lines 44..46

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

            if (filter_var($this->id, FILTER_VALIDATE_INT) && $this->id > 0) {
                $where = array(
                    "id = ?" => $this->id
                );
                
    Severity: Major
    Found in lib/Chronicle/Entry.php and 4 other locations - About 50 mins to fix
    lib/Ideas/Idea.php on lines 574..576
    lib/Jobs/Job.php on lines 278..284
    lib/Locations/Location.php on lines 659..673
    lib/Railcams/Camera.php on lines 282..284

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

                $this->meta = json_decode($row['meta'], true);
    Severity: Major
    Found in lib/Chronicle/Entry.php and 22 other locations - About 45 mins to fix
    lib/Assets/Asset.php on lines 150..150
    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
    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

            $baseurl = sprintf("%s?id=%d", $this->Module->url, $this->id);
    Severity: Minor
    Found in lib/Chronicle/Entry.php and 1 other location - About 45 mins to fix
    lib/PrivateMessages/Folder.php on lines 248..248

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

            $this->url->approve = sprintf("%s&mode=%s", $baseurl, "entry.approve");
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 40 mins to fix
    lib/Chronicle/Entry.php on lines 182..182
    lib/Chronicle/Entry.php on lines 183..183

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

    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

            $this->url->delete = sprintf("%s&mode=%s", $baseurl, "entry.delete");
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 40 mins to fix
    lib/Chronicle/Entry.php on lines 181..181
    lib/Chronicle/Entry.php on lines 182..182

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

    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

            $this->url->edit = sprintf("%s&mode=%s", $baseurl, "entry.edit");
    Severity: Major
    Found in lib/Chronicle/Entry.php and 2 other locations - About 40 mins to fix
    lib/Chronicle/Entry.php on lines 181..181
    lib/Chronicle/Entry.php on lines 183..183

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

    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

                    $this->Place = new Place($this->lat, $this->lon);
    Severity: Minor
    Found in lib/Chronicle/Entry.php and 2 other locations - About 40 mins to fix
    lib/GTFS/StandardStop.php on lines 114..114
    lib/Locations/Location.php on lines 359..359

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

            if (!filter_var($id, FILTER_VALIDATE_INT)) {
                return;
            }
    Severity: Major
    Found in lib/Chronicle/Entry.php and 8 other locations - About 30 mins to fix
    lib/Chronicle/EntryType.php on lines 80..82
    lib/Events/EventDate.php on lines 143..145
    lib/Feedback/FeedbackItem.php on lines 120..122
    lib/GTFS/StandardRoute.php on lines 68..70
    lib/GTFS/StandardStop.php on lines 97..99
    lib/Ideas/Ideas.php on lines 185..187
    lib/Images/Camera.php on lines 98..100
    lib/Users/Group.php on lines 127..129

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

    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 (empty($this->status)) {
                $this->status = self::STATUS_INACTIVE;
            }
    Severity: Minor
    Found in lib/Chronicle/Entry.php and 2 other locations - About 30 mins to fix
    lib/Chronicle/EntryType.php on lines 107..109
    lib/Users/User.php on lines 1220..1222

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

    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

    Function closing brace must go on the next line following the body; found 1 blank lines before brace
    Open

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

    Function closing brace must go on the next line following the body; found 1 blank lines before brace
    Open

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

    There are no issues that match your filters.

    Category
    Status