railpage/railpagecore

View on GitHub
lib/Locations/Country.php

Summary

Maintainability
F
4 days
Test Coverage

Method getRegions has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function getRegions($country = false) {
            $query = "SELECT COUNT(l.id) AS count, l.region_slug AS slug,
                g.region_name AS name, g.region_code, g.timezone
                FROM location AS l 
                    LEFT JOIN geoplace AS g ON l.geoplace = g.id 
Severity: Major
Found in lib/Locations/Country.php - About 3 hrs to fix

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

            public function __construct($code) {
    
                parent::__construct();
    
                $this->code = $code;
    Severity: Minor
    Found in lib/Locations/Country.php - About 1 hr to fix

      Method loadFromCache has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              private function loadFromCache() {
      
                  $mckey = sprintf("railpage:locations.country=%s", strtoupper($this->code));
                  
                  #printArray($mckey);die;
      Severity: Minor
      Found in lib/Locations/Country.php - About 1 hr to fix

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

                public function __construct($code) {
        
                    parent::__construct();
        
                    $this->code = $code;
        Severity: Minor
        Found in lib/Locations/Country.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

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

                public function getRegions($country = false) {
                    $query = "SELECT COUNT(l.id) AS count, l.region_slug AS slug,
                        g.region_name AS name, g.region_code, g.timezone
                        FROM location AS l 
                            LEFT JOIN geoplace AS g ON l.geoplace = g.id 
        Severity: Minor
        Found in lib/Locations/Country.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

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

                private function loadFromCache() {
        
                    $mckey = sprintf("railpage:locations.country=%s", strtoupper($this->code));
                    
                    #printArray($mckey);die;
        Severity: Minor
        Found in lib/Locations/Country.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 getRegions() has 138 lines of code. Current threshold is set to 100. Avoid really long methods.
        Open

                public function getRegions($country = false) {
                    $query = "SELECT COUNT(l.id) AS count, l.region_slug AS slug,
                        g.region_name AS name, g.region_code, g.timezone
                        FROM location AS l 
                            LEFT JOIN geoplace AS g ON l.geoplace = g.id 
        Severity: Minor
        Found in lib/Locations/Country.php by phpmd

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

                public function getRegions($country = false) {
        Severity: Minor
        Found in lib/Locations/Country.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

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

                public function getLocations($region = false, $country = false) {
        Severity: Minor
        Found in lib/Locations/Country.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

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

                public function getLocations($region = false, $country = false) {
        Severity: Minor
        Found in lib/Locations/Country.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 '165', column '61').
        Open

                private function loadFromCache() {
        
                    $mckey = sprintf("railpage:locations.country=%s", strtoupper($this->code));
                    
                    #printArray($mckey);die;
        Severity: Minor
        Found in lib/Locations/Country.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

                private function loadFromCache() {
        
                    $mckey = sprintf("railpage:locations.country=%s", strtoupper($this->code));
                    
                    #printArray($mckey);die;
        Severity: Minor
        Found in lib/Locations/Country.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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        foreach ($countries as $cc => $data) {
                            if (strtolower($data['name']) == strtolower($this->code)) {
                                $this->code = $cc;
                                $this->url = new Url("/locations/" . strtolower($this->code));
        Severity: Minor
        Found in lib/Locations/Country.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

        Avoid unused parameters such as '$country'.
        Open

                public function getLocations($region = false, $country = false) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpmd

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

        Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

        Avoid unused parameters such as '$region'.
        Open

                public function getLocations($region = false, $country = false) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpmd

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

        Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

        Avoid unused parameters such as '$country'.
        Open

                public function getRegions($country = false) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpmd

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

        Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

                                $replace = array(
                                    "ak", "al", "az", "ar", "ca", "co", "ct", "de", "dc", "fl", "ga", "hi", "id", "il", "in", "ia", "ks", "ky",
                                    "la", "me", "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh", "nj", "nm", "ny", "nc", "nd", "oh",
                                    "ok", "or", "pa", "ri", "sc", "sd", "tn", "tx", "ut", "vt", "va", "wa", "wv", "wi", "wy"
                                );
        Severity: Major
        Found in lib/Locations/Country.php and 1 other location - About 7 hrs to fix
        lib/Locations/Country.php on lines 285..337

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

        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

                                $find = array(
                                    "alaska",
                                    "alabama",
                                    "arizona",
                                    "arkansas",
        Severity: Major
        Found in lib/Locations/Country.php and 1 other location - About 7 hrs to fix
        lib/Locations/Country.php on lines 339..343

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

        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

                                "bb_southwest" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['southWest']['latitude'], $woe['boundingBox']['southWest']['longitude'])),
        Severity: Major
        Found in lib/Locations/Country.php and 1 other location - About 1 hr to fix
        lib/Locations/Country.php on lines 118..118

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

        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

                                "bb_northeast" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['northEast']['latitude'], $woe['boundingBox']['northEast']['longitude'])),
        Severity: Major
        Found in lib/Locations/Country.php and 1 other location - About 1 hr to fix
        lib/Locations/Country.php on lines 117..117

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

        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

                                "point"        => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['centroid']['latitude'], $woe['centroid']['longitude'])),
        Severity: Major
        Found in lib/Locations/Country.php and 3 other locations - About 1 hr to fix
        lib/PlaceUtility.php on lines 210..210
        lib/PlaceUtility.php on lines 211..211
        lib/PlaceUtility.php on lines 212..212

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

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

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

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

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

        Refactorings

        Further Reading

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

                    if (!isset( $row ) || !is_array($row) || count($row) === 0) {
        Severity: Major
        Found in lib/Locations/Country.php and 1 other location - About 1 hr to fix
        lib/Locations/Location.php on lines 319..319

        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

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

                                $this->url = new Url("/locations/" . strtolower($this->code));
        Severity: Minor
        Found in lib/Locations/Country.php and 1 other location - About 55 mins to fix
        lib/Locations/Country.php on lines 89..89

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 29.

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

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

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

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

        Refactorings

        Further Reading

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

                    $this->url = new Url("/locations/" . strtolower($this->code));
        Severity: Minor
        Found in lib/Locations/Country.php and 1 other location - About 55 mins to fix
        lib/Locations/Country.php on lines 99..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 29.

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

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

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

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

        Refactorings

        Further Reading

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

                    $mckey = sprintf("railpage:locations.country=%s", strtoupper($this->code));
        Severity: Major
        Found in lib/Locations/Country.php and 5 other locations - About 45 mins to fix
        lib/Users/Group.php on lines 144..144
        lib/Users/Group.php on lines 291..291
        lib/Users/Group.php on lines 431..431
        lib/Users/Group.php on lines 511..511
        lib/Users/Group.php on lines 537..537

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

                            $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude'];
        Severity: Major
        Found in lib/Locations/Country.php and 7 other locations - About 45 mins to fix
        lib/Locations/Country.php on lines 134..134
        lib/Locations/Country.php on lines 138..138
        lib/Locations/Country.php on lines 139..139
        lib/Locations/Region.php on lines 157..157
        lib/Locations/Region.php on lines 158..158
        lib/Locations/Region.php on lines 161..161
        lib/Locations/Region.php on lines 162..162

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

                            $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude'];
        Severity: Major
        Found in lib/Locations/Country.php and 7 other locations - About 45 mins to fix
        lib/Locations/Country.php on lines 134..134
        lib/Locations/Country.php on lines 135..135
        lib/Locations/Country.php on lines 139..139
        lib/Locations/Region.php on lines 157..157
        lib/Locations/Region.php on lines 158..158
        lib/Locations/Region.php on lines 161..161
        lib/Locations/Region.php on lines 162..162

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

                            $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude'];
        Severity: Major
        Found in lib/Locations/Country.php and 7 other locations - About 45 mins to fix
        lib/Locations/Country.php on lines 134..134
        lib/Locations/Country.php on lines 135..135
        lib/Locations/Country.php on lines 138..138
        lib/Locations/Region.php on lines 157..157
        lib/Locations/Region.php on lines 158..158
        lib/Locations/Region.php on lines 161..161
        lib/Locations/Region.php on lines 162..162

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

                            $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude'];
        Severity: Major
        Found in lib/Locations/Country.php and 7 other locations - About 45 mins to fix
        lib/Locations/Country.php on lines 135..135
        lib/Locations/Country.php on lines 138..138
        lib/Locations/Country.php on lines 139..139
        lib/Locations/Region.php on lines 157..157
        lib/Locations/Region.php on lines 158..158
        lib/Locations/Region.php on lines 161..161
        lib/Locations/Region.php on lines 162..162

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

                        $row['url'] = $this->url . "/" . $row['slug'];
        Severity: Major
        Found in lib/Locations/Country.php and 2 other locations - About 45 mins to fix
        lib/Locations/Region.php on lines 226..226
        lib/Locos/LocoClass.php on lines 520..520

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

                        $row = $this->db->fetchRow($query, strtoupper($this->code));
        Severity: Minor
        Found in lib/Locations/Country.php and 1 other location - About 45 mins to fix
        lib/Users/User.php on lines 1946..1946

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

                            $this->Memcached->save($mckey, $row, strtotime("+1 year"));
        Severity: Major
        Found in lib/Locations/Country.php and 21 other locations - About 40 mins to fix
        lib/Chronicle/Chronicle.php on lines 119..119
        lib/Config/Base.php on lines 40..40
        lib/Config/Base.php on lines 111..111
        lib/Downloads/Download.php on lines 530..530
        lib/Glossary/Glossary.php on lines 107..107
        lib/Images/Images.php on lines 110..110
        lib/Links/Links.php on lines 94..94
        lib/Links/Links.php on lines 129..129
        lib/Locations/Country.php on lines 180..180
        lib/Locations/Location.php on lines 811..811
        lib/Locations/Locations.php on lines 76..76
        lib/Locations/Locations.php on lines 127..127
        lib/Locations/Locations.php on lines 161..161
        lib/Locations/Locations.php on lines 474..474
        lib/Locos/Locomotive.php on lines 1227..1227
        lib/Locos/Locomotive.php on lines 1538..1538
        lib/Locos/Locos.php on lines 238..238
        lib/PrivateMessages/Folder.php on lines 259..259
        lib/Users/Base.php on lines 82..82
        lib/Users/Timeline.php on lines 241..241
        lib/Place.php on lines 600..600

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 24.

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

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

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

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

        Refactorings

        Further Reading

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

                            $this->Redis->save($mckey, $row, strtotime("+1 year"));
        Severity: Major
        Found in lib/Locations/Country.php and 21 other locations - About 40 mins to fix
        lib/Chronicle/Chronicle.php on lines 119..119
        lib/Config/Base.php on lines 40..40
        lib/Config/Base.php on lines 111..111
        lib/Downloads/Download.php on lines 530..530
        lib/Glossary/Glossary.php on lines 107..107
        lib/Images/Images.php on lines 110..110
        lib/Links/Links.php on lines 94..94
        lib/Links/Links.php on lines 129..129
        lib/Locations/Country.php on lines 179..179
        lib/Locations/Location.php on lines 811..811
        lib/Locations/Locations.php on lines 76..76
        lib/Locations/Locations.php on lines 127..127
        lib/Locations/Locations.php on lines 161..161
        lib/Locations/Locations.php on lines 474..474
        lib/Locos/Locomotive.php on lines 1227..1227
        lib/Locos/Locomotive.php on lines 1538..1538
        lib/Locos/Locos.php on lines 238..238
        lib/PrivateMessages/Folder.php on lines 259..259
        lib/Users/Base.php on lines 82..82
        lib/Users/Timeline.php on lines 241..241
        lib/Place.php on lines 600..600

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 24.

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

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

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

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

        Refactorings

        Further Reading

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

                        if (isset( $woe['places']['place'][0]['name'] )) {
                            $woe = $woe['places']['place'][0];
        
                            $data = [
                                "point"        => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['centroid']['latitude'], $woe['centroid']['longitude'])),
        Severity: Minor
        Found in lib/Locations/Country.php and 2 other locations - About 30 mins to fix
        lib/Images/Image.php on lines 697..697
        lib/Locations/Region.php on lines 192..197

        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 end of control structure
        Open

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

        Blank line found at end of control structure
        Open

        
        
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        There must be one blank line after the last USE statement; 2 found;
        Open

            use Zend_Db_Expr;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Blank line found at start of control structure
        Open

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

        Blank line found at start of control structure
        Open

                        switch (strtolower($this->code)) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    } else {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $url;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 16 spaces, found 20
        Open

                            case "gb" :
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    foreach ($this->db->fetchAll($query, array( $this->code )) as $row) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $boundingBox;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        if (is_array($row)) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 16 spaces, found 20
        Open

                            case "au" :
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 16 spaces, found 20
        Open

                            case "us" :
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function __toString() {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 16 spaces, found 20
        Open

                            if (strtolower($data['name']) == strtolower($this->code)) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function getRegions($country = false) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        if (empty( $row['slug'] )) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (strlen($this->code) == 2) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        if (isset( $woe['places']['place'][0]['name'] )) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                private function loadFromCache() {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

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

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $timezone;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $code;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!$this->loadFromCache() || empty( $this->name )) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function getLocations($region = false, $country = false) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 0 spaces, found 4
        Open

            }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 0 spaces, found 4
        Open

            class Country extends Locations {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $centre;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 16 spaces, found 20
        Open

                            }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    if (!isset( $row ) || !is_array($row) || count($row) === 0) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        switch (strtolower($this->code)) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public function __construct($code) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 4 spaces, found 8
        Open

                public $name;
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        foreach ($countries as $cc => $data) {
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        Line indented incorrectly; expected 12 spaces, found 16
        Open

                        }
        Severity: Minor
        Found in lib/Locations/Country.php by phpcodesniffer

        There are no issues that match your filters.

        Category
        Status