railpage/railpagecore

View on GitHub
lib/Railcams/Storage.php

Summary

Maintainability
D
1 day
Test Coverage

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

    public function setConfig($config = null) {
        
        if ($this->type == "LocalFS") {
            if (substr($config['storageRoot'], -1) != "/") {
                $config['storageRoot'] .= "/"; 
Severity: Minor
Found in lib/Railcams/Storage.php - About 1 hr to fix

    Function setConfig has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setConfig($config = null) {
            
            if ($this->type == "LocalFS") {
                if (substr($config['storageRoot'], -1) != "/") {
                    $config['storageRoot'] .= "/"; 
    Severity: Minor
    Found in lib/Railcams/Storage.php - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

        public function getPrimary() {
            
            if ($this->isPrimary()) {
                return $this;
            }
    Severity: Minor
    Found in lib/Railcams/Storage.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

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

                if (substr($config['webRoot'], -3) != $this->cameraObject->id . "/") {
                   $config['webRoot'] .= $this->cameraObject->id . "/"; 
                }
    Severity: Major
    Found in lib/Railcams/Storage.php and 1 other location - About 2 hrs to fix
    lib/Railcams/Storage.php on lines 153..155

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

                if (substr($config['storageRoot'], -3) != $this->cameraObject->id . "/") {
                   $config['storageRoot'] .= $this->cameraObject->id . "/"; 
                }
    Severity: Major
    Found in lib/Railcams/Storage.php and 1 other location - About 2 hrs to fix
    lib/Railcams/Storage.php on lines 161..163

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

                if (substr($config['storageRoot'], -1) != "/") {
                    $config['storageRoot'] .= "/"; 
                }
    Severity: Major
    Found in lib/Railcams/Storage.php and 1 other location - About 1 hr to fix
    lib/Railcams/Storage.php on lines 157..159

    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 (substr($config['webRoot'], -1) != "/") {
                    $config['webRoot'] .= "/"; 
                }
    Severity: Major
    Found in lib/Railcams/Storage.php and 1 other location - About 1 hr to fix
    lib/Railcams/Storage.php on lines 149..151

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

            if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
                throw new Exception("Cannot set this as the primary storage destination as it has not been saved to database yet"); 
            }
    Severity: Major
    Found in lib/Railcams/Storage.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/Sightings/Sighting.php on lines 133..135
    lib/Users/Group.php on lines 236..238
    lib/Warnings/Warning.php on lines 209..211

    Duplicated Code

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

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

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

    Tuning

    This issue has a mass of 32.

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

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

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

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

    Refactorings

    Further Reading

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

            if (!class_exists($class)) {
                throw new InvalidArgumentException("The desired storage type " . $type . " is invalid"); 
            }
    Severity: Major
    Found in lib/Railcams/Storage.php and 1 other location - About 1 hr to fix
    lib/Railcams/Storage/LocalFS.php on lines 106..108

    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->config = json_decode($row['config'], true); 
    Severity: Major
    Found in lib/Railcams/Storage.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/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 25 locations. Consider refactoring.
    Open

        public function setTimestamp(DateTime $timeStamp) {
            
            $this->timeStamp = $timeStamp; 
            
            return $this;
    Severity: Major
    Found in lib/Railcams/Storage.php and 24 other locations - About 40 mins to fix
    lib/Feedback/Feedback.php on lines 52..56
    lib/Gallery/Album.php on lines 279..285
    lib/Gallery/Album.php on lines 317..323
    lib/Gallery/Image.php on lines 278..284
    lib/Gallery/Image.php on lines 460..466
    lib/Glossary/Entry.php on lines 302..306
    lib/Locations/Correction.php on lines 118..124
    lib/News/Article.php on lines 941..945
    lib/Prerender/Prerender.php on lines 89..94
    lib/Railcams/Footage.php on lines 89..95
    lib/Railcams/Photo.php on lines 143..147
    lib/Railcams/Storage.php on lines 95..101
    lib/SiteMessages/SiteMessage.php on lines 206..210
    lib/Timetables/Timetables.php on lines 52..56
    lib/Timetables/Timetables.php on lines 64..68
    lib/Timetables/Timetables.php on lines 76..80
    lib/Users/SockpuppetManager.php on lines 61..67
    lib/Warnings/Warning.php on lines 249..255
    lib/Warnings/Warning.php on lines 267..273
    lib/AppCore.php on lines 401..407
    lib/AppCore.php on lines 416..422
    lib/AppCore.php on lines 431..437
    lib/AppCore.php on lines 463..469
    lib/AppCore.php on lines 478..484

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

        public function setCamera(Camera $cameraObject) {
            
            $this->cameraObject = $cameraObject; 
            
            return $this;
    Severity: Major
    Found in lib/Railcams/Storage.php and 24 other locations - About 40 mins to fix
    lib/Feedback/Feedback.php on lines 52..56
    lib/Gallery/Album.php on lines 279..285
    lib/Gallery/Album.php on lines 317..323
    lib/Gallery/Image.php on lines 278..284
    lib/Gallery/Image.php on lines 460..466
    lib/Glossary/Entry.php on lines 302..306
    lib/Locations/Correction.php on lines 118..124
    lib/News/Article.php on lines 941..945
    lib/Prerender/Prerender.php on lines 89..94
    lib/Railcams/Footage.php on lines 89..95
    lib/Railcams/Photo.php on lines 143..147
    lib/Railcams/Storage.php on lines 110..116
    lib/SiteMessages/SiteMessage.php on lines 206..210
    lib/Timetables/Timetables.php on lines 52..56
    lib/Timetables/Timetables.php on lines 64..68
    lib/Timetables/Timetables.php on lines 76..80
    lib/Users/SockpuppetManager.php on lines 61..67
    lib/Warnings/Warning.php on lines 249..255
    lib/Warnings/Warning.php on lines 267..273
    lib/AppCore.php on lines 401..407
    lib/AppCore.php on lines 416..422
    lib/AppCore.php on lines 431..437
    lib/AppCore.php on lines 463..469
    lib/AppCore.php on lines 478..484

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

                $this->setCamera(new Camera($row['camera_id']));
    Severity: Minor
    Found in lib/Railcams/Storage.php and 2 other locations - About 30 mins to fix
    lib/Notifications/Notification.php on lines 141..141
    lib/Railcams/Footage.php on lines 168..168

    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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.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/Railcams/Storage.php by phpcodesniffer

    Blank line found at end of control structure
    Open

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

    Line indented incorrectly; expected at least 16 spaces, found 15
    Open

                   $config['webRoot'] .= $this->cameraObject->id . "/"; 
    Severity: Minor
    Found in lib/Railcams/Storage.php by phpcodesniffer

    Line indented incorrectly; expected at least 16 spaces, found 15
    Open

                   $config['storageRoot'] .= $this->cameraObject->id . "/"; 
    Severity: Minor
    Found in lib/Railcams/Storage.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status