railpage/railpagecore

View on GitHub
lib/Images/Camera.php

Summary

Maintainability
D
1 day
Test Coverage

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

    private function validate() {
        
        if (empty($this->name)) {
            throw new Exception("Camera name is empty"); 
        }
Severity: Minor
Found in lib/Images/Camera.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

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

            $row['avatar_sizes'] = array(
                "tiny"   => AvatarUtility::Format($row['user_avatar'], 25, 25),
                "thumb"  => AvatarUtility::Format($row['user_avatar'], 50, 50),
                "small"  => AvatarUtility::Format($row['user_avatar'], 75, 75),
                "medium" => AvatarUtility::Format($row['user_avatar'], 100, 100)
Severity: Major
Found in lib/Images/Camera.php and 1 other location - About 3 hrs to fix
lib/PrivateMessages/PrivateMessages.php on lines 288..293

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

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)) {
            $where = [ "id = ?" => $this->id ];
            
            $this->db->update("image_camera", $data, $where); 
        }
Severity: Major
Found in lib/Images/Camera.php and 4 other locations - About 2 hrs to fix
lib/Downloads/Category.php on lines 170..176
lib/Gallery/Album.php on lines 494..497
lib/Images/Collection.php on lines 219..222
lib/Images/Competition.php on lines 321..327

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

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->db->insert("image_camera", $data); 
            $this->id = $this->db->lastInsertId(); 
        }
Severity: Major
Found in lib/Images/Camera.php and 4 other locations - About 1 hr to fix
lib/Downloads/Category.php on lines 178..181
lib/Gallery/Album.php on lines 500..503
lib/Images/Collection.php on lines 224..227
lib/Images/Competition.php on lines 329..332

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

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("/photos/cameras/%s", $this->slug));
Severity: Major
Found in lib/Images/Camera.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/Locos/Manufacturer.php on lines 114..114
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 4 locations. Consider refactoring.
Open

        $this->url->dpreview = sprintf("http://www.dpreview.com/search?query=%s+%s", $this->manufacturer, $this->name);
Severity: Major
Found in lib/Images/Camera.php and 3 other locations - About 55 mins to fix
lib/Images/Competition.php on lines 792..792
lib/Images/Competition.php on lines 793..793
lib/Locations/Location.php on lines 365..365

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 28.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

                if (count($count)) {
                    $this->slug .= count($count); 
                }
Severity: Major
Found in lib/Images/Camera.php and 2 other locations - About 55 mins to fix
lib/Gallery/Album.php on lines 435..437
lib/News/Topic.php on lines 351..353

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 28.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    public function getPhotosForMap() {
        
        $query = "SELECT image.id, image.lat, image.lon, image.title
                    FROM image
                    LEFT JOIN image_exif AS f ON f.image_id = image.id
Severity: Major
Found in lib/Images/Camera.php and 2 other locations - About 50 mins to fix
lib/Images/Competition.php on lines 760..764
lib/Locos/Locomotive.php on lines 787..795

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

        $this->url->edit = sprintf("%s?mode=camera.edit", $this->url); 
Severity: Major
Found in lib/Images/Camera.php and 30 other locations - About 40 mins to fix
lib/Content/Page.php on lines 155..155
lib/Events/EventDate.php on lines 161..161
lib/Feedback/FeedbackItem.php on lines 147..147
lib/Feedback/FeedbackItem.php on lines 148..148
lib/Feedback/FeedbackItem.php on lines 154..154
lib/Feedback/FeedbackItem.php on lines 155..155
lib/Forums/Post.php on lines 749..749
lib/Forums/Post.php on lines 750..750
lib/Forums/Post.php on lines 751..751
lib/Forums/Post.php on lines 752..752
lib/Forums/Post.php on lines 753..753
lib/Forums/Post.php on lines 754..754
lib/Forums/Post.php on lines 755..755
lib/Forums/Post.php on lines 756..756
lib/Ideas/Idea.php on lines 207..207
lib/Images/Competition.php on lines 431..431
lib/Locos/Operator.php on lines 114..114
lib/Locos/Operator.php on lines 115..115
lib/News/Article.php on lines 481..481
lib/News/Article.php on lines 482..482
lib/News/Article.php on lines 483..483
lib/News/Article.php on lines 484..484
lib/News/Article.php on lines 485..485
lib/Newsletters/Newsletter.php on lines 267..267
lib/Newsletters/Newsletter.php on lines 268..268
lib/Newsletters/Newsletter.php on lines 269..269
lib/Newsletters/Newsletter.php on lines 270..270
lib/Reminders/Reminder.php on lines 165..165
lib/SiteMessages/SiteMessage.php on lines 193..193
lib/SiteMessages/SiteMessage.php on lines 194..194

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 23.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        $regkey = sprintf(self::CACHE_KEY, $this->id);
Severity: Major
Found in lib/Images/Camera.php and 7 other locations - About 35 mins to fix
lib/Forums/Post.php on lines 626..626
lib/Forums/Post.php on lines 660..660
lib/Images/Competition.php on lines 338..338
lib/Locos/LocoClass.php on lines 657..657
lib/Locos/Locomotive.php on lines 692..692
lib/Locos/Locomotive.php on lines 1498..1498
lib/Users/User.php on lines 1282..1282

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

        if (!filter_var($id, FILTER_VALIDATE_INT)) {
            return;
        }
Severity: Major
Found in lib/Images/Camera.php and 8 other locations - About 30 mins to fix
lib/Chronicle/Entry.php on lines 140..142
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/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 7 locations. Consider refactoring.
Open

                $count = $this->db->fetchAll("SELECT id FROM image_camera WHERE url_slug = ?", $this->slug); 
Severity: Major
Found in lib/Images/Camera.php and 6 other locations - About 30 mins to fix
lib/Gallery/Image.php on lines 263..263
lib/Gallery/Image.php on lines 401..401
lib/Links/Category.php on lines 97..97
lib/Locos/Date.php on lines 147..147
lib/News/Topic.php on lines 348..348
lib/Railcams/Footage.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 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

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

    }
Severity: Minor
Found in lib/Images/Camera.php by phpcodesniffer

Blank line found at end of control structure
Open

            
Severity: Minor
Found in lib/Images/Camera.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/Images/Camera.php by phpcodesniffer

Blank line found at start of control structure
Open

        foreach ($result as $id => $row) {
Severity: Minor
Found in lib/Images/Camera.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/Images/Camera.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/Images/Camera.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/Images/Camera.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/Images/Camera.php by phpcodesniffer

Blank line found at end of control structure
Open

            
Severity: Minor
Found in lib/Images/Camera.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/Images/Camera.php by phpcodesniffer

There are no issues that match your filters.

Category
Status