railpage/railpagecore

View on GitHub
lib/API.php

Summary

Maintainability
C
1 day
Test Coverage

Avoid using undefined variables such as '$api_secret' which will lead to PHP notices.
Open

        if (is_null($api_secret)) {
Severity: Minor
Found in lib/API.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid unused local variables such as '$api_secret'.
Open

        if (is_null($api_secret)) {
Severity: Minor
Found in lib/API.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

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

        if (is_null($apiKey)) { 
            return false;
            throw new Exception("Cannot instantiate " . __CLASS__ . " because no API key was provided");
        }
Severity: Major
Found in lib/API.php and 1 other location - About 1 hr to fix
lib/API.php on lines 97..100

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 (is_null($api_secret)) {
            return false;
            throw new Exception("Cannot instantiate " . __CLASS__ . " because no API secret was provided");
        }
Severity: Major
Found in lib/API.php and 1 other location - About 1 hr to fix
lib/API.php on lines 92..95

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

        if (RP_DEBUG) {
            global $site_debug;
            $debug_timer_start = microtime(true);
        }
Severity: Major
Found in lib/API.php and 11 other locations - About 55 mins to fix
lib/Events/Event.php on lines 341..344
lib/Events/Event.php on lines 381..384
lib/Forums/Post.php on lines 434..437
lib/Forums/Thread.php on lines 209..212
lib/Images/Image.php on lines 611..614
lib/Links/Links.php on lines 278..281
lib/News/Article.php on lines 365..368
lib/News/Base.php on lines 310..313
lib/PrivateMessages/Folder.php on lines 86..89
lib/API.php on lines 260..263
lib/Template.php on lines 332..335

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

        if (RP_DEBUG) {
            global $site_debug;
            $debug_timer_start = microtime(true);
        }
Severity: Major
Found in lib/API.php and 11 other locations - About 55 mins to fix
lib/Events/Event.php on lines 341..344
lib/Events/Event.php on lines 381..384
lib/Forums/Post.php on lines 434..437
lib/Forums/Thread.php on lines 209..212
lib/Images/Image.php on lines 611..614
lib/Links/Links.php on lines 278..281
lib/News/Article.php on lines 365..368
lib/News/Base.php on lines 310..313
lib/PrivateMessages/Folder.php on lines 86..89
lib/API.php on lines 128..131
lib/Template.php on lines 332..335

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

        if (!$response->getStatusCode() == 200) {
            throw new Exception(sprintf("Failed to execute API call: HTTP error %s", $response->getStatusCode()));
        }
Severity: Minor
Found in lib/API.php and 1 other location - About 40 mins to fix
lib/Railcams/Camera.php on lines 440..442

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

        if (is_null($method)) {
            throw new InvalidArgumentException("No API method specified");
        }
Severity: Major
Found in lib/API.php and 20 other locations - About 35 mins to fix
lib/Events/EventDate.php on lines 372..374
lib/Images/Image.php on lines 963..965
lib/Images/Image.php on lines 1095..1097
lib/Images/Images.php on lines 96..98
lib/Images/Images.php on lines 137..139
lib/Locations/Region.php on lines 93..95
lib/Locos/Locos.php on lines 590..592
lib/Locos/Locos.php on lines 901..903
lib/Locos/Locos.php on lines 925..927
lib/Railcams/Storage/LocalFS.php on lines 127..129
lib/Users/User.php on lines 2572..2574
lib/Users/User.php on lines 2576..2578
lib/Users/User.php on lines 2584..2586
lib/Users/Utility/PasswordUtility.php on lines 70..72
lib/Users/Utility/PasswordUtility.php on lines 74..76
lib/Users/Utility/PasswordUtility.php on lines 78..80
lib/API.php on lines 124..126
lib/BanControl/BanControl.php on lines 243..245
lib/BanControl/BanControl.php on lines 354..356
lib/BanControl/BanControl.php on lines 358..360

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

        if (is_null($method)) {
            throw new InvalidArgumentException("No API method specified"); 
        }
Severity: Major
Found in lib/API.php and 20 other locations - About 35 mins to fix
lib/Events/EventDate.php on lines 372..374
lib/Images/Image.php on lines 963..965
lib/Images/Image.php on lines 1095..1097
lib/Images/Images.php on lines 96..98
lib/Images/Images.php on lines 137..139
lib/Locations/Region.php on lines 93..95
lib/Locos/Locos.php on lines 590..592
lib/Locos/Locos.php on lines 901..903
lib/Locos/Locos.php on lines 925..927
lib/Railcams/Storage/LocalFS.php on lines 127..129
lib/Users/User.php on lines 2572..2574
lib/Users/User.php on lines 2576..2578
lib/Users/User.php on lines 2584..2586
lib/Users/Utility/PasswordUtility.php on lines 70..72
lib/Users/Utility/PasswordUtility.php on lines 74..76
lib/Users/Utility/PasswordUtility.php on lines 78..80
lib/API.php on lines 194..196
lib/BanControl/BanControl.php on lines 243..245
lib/BanControl/BanControl.php on lines 354..356
lib/BanControl/BanControl.php on lines 358..360

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

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

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Severity: Minor
Found in lib/API.php and 1 other location - About 35 mins to fix
lib/API.php on lines 159..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 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

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

        curl_setopt($curl, CURLOPT_POST, true);
Severity: Minor
Found in lib/API.php and 1 other location - About 35 mins to fix
lib/API.php on lines 161..161

Duplicated Code

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

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

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

Tuning

This issue has a mass of 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 2 locations. Consider refactoring.
Open

            $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "(" . $method . ") completed in " . number_format(microtime(true) - $debug_timer_start, 8) . "s";
Severity: Minor
Found in lib/API.php and 1 other location - About 35 mins to fix
lib/API.php on lines 282..282

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

            $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "(" . $method . "::" . implode(", ", $args) . ") completed in " . number_format(microtime(true) - $debug_timer_start, 8) . "s";
Severity: Minor
Found in lib/API.php and 1 other location - About 35 mins to fix
lib/API.php on lines 181..181

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

There are no issues that match your filters.

Category
Status