railpage/railpagecore

View on GitHub
lib/Sightings/Sighting.php

Summary

Maintainability
D
2 days
Test Coverage

Method fetch has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function fetch() {
            if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
                throw new Exception("Cannot fetch sighting - no ID given"); 
            }
            
Severity: Minor
Found in lib/Sightings/Sighting.php - About 1 hr to fix

    Method getArray has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function getArray() {
                
                $array = array(
                    "id" => $this->id,
                    "lat" => $this->lat,
    Severity: Minor
    Found in lib/Sightings/Sighting.php - About 1 hr to fix

      Avoid too many return statements within this method.
      Open

                  return true;
      Severity: Major
      Found in lib/Sightings/Sighting.php - About 30 mins to fix

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

                public function validate() {
                    if (empty($this->lat)) {
                        throw new Exception("Cannot validate sighting - latitude cannot be empty"); 
                        return false;
                    }
        Severity: Minor
        Found in lib/Sightings/Sighting.php - About 25 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

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

                public function __construct($id = false) {
        Severity: Minor
        Found in lib/Sightings/Sighting.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

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

                public function fetch() {
                    if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
                        throw new Exception("Cannot fetch sighting - no ID given"); 
                    }
                    
        Severity: Minor
        Found in lib/Sightings/Sighting.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 {
                        $this->db->insert("sighting", $data);
                        $this->id = $this->db->lastInsertId(); 
                    }
        Severity: Minor
        Found in lib/Sightings/Sighting.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 (!$row = $this->Memcached->fetch($mckey)) {
                    
                        $query = "SELECT s.id, s.date, s.date_added, s.lat, s.lon, s.text, s.user_id, s.timezone, u.username, s.loco_ids, s.meta
                            FROM sighting AS s
                            LEFT JOIN nuke_users AS u ON s.user_id = u.user_id
        Severity: Major
        Found in lib/Sightings/Sighting.php and 1 other location - About 2 hrs to fix
        lib/Users/Group.php on lines 146..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 63.

        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 = false) {
                    
                    parent::__construct(); 
                    
                    if ($id) {
        Severity: Major
        Found in lib/Sightings/Sighting.php and 1 other location - About 1 hr to fix
        lib/Links/Link.php on lines 92..99

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

        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

                            "added" => array(
                                "absolute" => $this->date_added->format("Y-m-d H:i:s"),
                                "relative" => ContentUtility::relativeTime($this->date_added),
                            ),
        Severity: Major
        Found in lib/Sightings/Sighting.php and 3 other locations - About 1 hr to fix
        lib/Images/Collection.php on lines 318..321
        lib/Images/Collection.php on lines 322..325
        lib/Sightings/Sighting.php on lines 197..200

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

        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

                            "seen" => array(
                                "absolute" => $this->date->format("Y-m-d H:i:s"),
                                "relative" => ContentUtility::relativeTime($this->date),
                            ),
        Severity: Major
        Found in lib/Sightings/Sighting.php and 3 other locations - About 1 hr to fix
        lib/Images/Collection.php on lines 318..321
        lib/Images/Collection.php on lines 322..325
        lib/Sightings/Sighting.php on lines 193..196

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

        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 fetch sighting - no ID given"); 
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.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/Jobs/Classification.php on lines 80..82
        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/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

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

                    $this->date_added   = new DateTime($row['date_added'], new DateTimeZone($this->timezone));
        Severity: Major
        Found in lib/Sightings/Sighting.php and 1 other location - About 1 hr to fix
        lib/Sightings/Sighting.php on lines 164..164

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

                    $this->date         = new DateTime($row['date'], new DateTimeZone($this->timezone));
        Severity: Major
        Found in lib/Sightings/Sighting.php and 1 other location - About 1 hr to fix
        lib/Sightings/Sighting.php on lines 165..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 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 23 locations. Consider refactoring.
        Open

                    $this->meta = json_decode($row['meta'], true);
        Severity: Major
        Found in lib/Sightings/Sighting.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 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 23 locations. Consider refactoring.
        Open

                    $this->loco_ids = json_decode($row['loco_ids'], true);
        Severity: Major
        Found in lib/Sightings/Sighting.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/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 18 locations. Consider refactoring.
        Open

                    if (empty($this->lon)) {
                        throw new Exception("Cannot validate sighting - longitude cannot be empty"); 
                        return false;
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.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 229..232
        lib/Sightings/Sighting.php on lines 234..237
        lib/SiteEvent.php on lines 148..151
        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

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

                    if (empty($this->loco_ids)) {
                        throw new Exception("Cannot validate sighting - loco_ids cannot be empty"); 
                        return false;
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.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/SiteEvent.php on lines 148..151
        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

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

                    if (empty($this->lat)) {
                        throw new Exception("Cannot validate sighting - latitude cannot be empty"); 
                        return false;
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.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 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
        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->user_id)) {
                        throw new Exception("Cannot validate sighting - user_id cannot be empty"); 
                        return false;
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.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 234..237
        lib/SiteEvent.php on lines 148..151
        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

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

                    if (is_null($this->text)) {
                        $this->text = "";
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.php and 11 other locations - About 40 mins to fix
        lib/Downloads/Download.php on lines 293..295
        lib/Feedback/FeedbackItem.php on lines 180..182
        lib/Forums/Post.php on lines 351..353
        lib/Glossary/Entry.php on lines 262..264
        lib/Locos/Date.php on lines 266..268
        lib/Locos/WheelArrangement.php on lines 170..172
        lib/News/Article.php on lines 766..768
        lib/News/Article.php on lines 770..772
        lib/News/Article.php on lines 786..788
        lib/PrivateMessages/Message.php on lines 302..304
        lib/Sightings/Sighting.php on lines 243..245

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

                    if (is_null($this->train_number)) {
                        $this->train_number = "";
                    }
        Severity: Major
        Found in lib/Sightings/Sighting.php and 11 other locations - About 40 mins to fix
        lib/Downloads/Download.php on lines 293..295
        lib/Feedback/FeedbackItem.php on lines 180..182
        lib/Forums/Post.php on lines 351..353
        lib/Glossary/Entry.php on lines 262..264
        lib/Locos/Date.php on lines 266..268
        lib/Locos/WheelArrangement.php on lines 170..172
        lib/News/Article.php on lines 766..768
        lib/News/Article.php on lines 770..772
        lib/News/Article.php on lines 786..788
        lib/PrivateMessages/Message.php on lines 302..304
        lib/Sightings/Sighting.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 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 2 locations. Consider refactoring.
        Open

                        $row['loco_url'] = sprintf("/locos/%s/%s", $row['class_slug'], $row['loco_num']);
        Severity: Minor
        Found in lib/Sightings/Sighting.php and 1 other location - About 40 mins to fix
        lib/Images/Utility/ImageUtility.php on lines 51..51

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

                    $this->url = new Url("/sightings/view/" . $this->id); 
        Severity: Major
        Found in lib/Sightings/Sighting.php and 3 other locations - About 35 mins to fix
        lib/Assets/Asset.php on lines 156..156
        lib/Locos/Liveries/Livery.php on lines 163..163
        lib/Locos/Liveries/Livery.php on lines 200..200

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

        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

                        "author" => array(
                            "id" => $this->user_id,
                            "username" => $this->username
                        ),
        Severity: Major
        Found in lib/Sightings/Sighting.php and 4 other locations - About 30 mins to fix
        lib/Images/Image.php on lines 1013..1016
        lib/Jobs/Jobs.php on lines 210..213
        lib/Jobs/Scraper.php on lines 278..281
        lib/Locos/Locomotive.php on lines 1415..1418

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

        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

        Blank line found at start of control structure
        Open

                    if (!$row = $this->Memcached->fetch($mckey)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.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/Sightings/Sighting.php by phpcodesniffer

        Expected 1 blank line at end of file; 3 found
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $date;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $date_added;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if ($id) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (empty($this->lon)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function commit() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $text;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!$this->id) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function validate() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (empty($this->loco_ids)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    foreach ($this->db->fetchAll($query, $this->id) as $row) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function fetch() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (filter_var($this->id, FILTER_VALIDATE_INT)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $loco_ids;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!isset($row) || !is_array($row)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function locos() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 0 spaces, found 4
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (empty($this->lat)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (empty($this->user_id)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function delete() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    } else {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $user_id;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function getArray() {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function __construct($id = false) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $lon;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $train_number;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (is_null($this->text)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (is_null($this->train_number)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 0 spaces, found 4
        Open

            class Sighting extends AppCore {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $lat;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $timezone;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $id;
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!$row = $this->Memcached->fetch($mckey)) {
        Severity: Minor
        Found in lib/Sightings/Sighting.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

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

        There are no issues that match your filters.

        Category
        Status