ampache/ampache

View on GitHub
src/Module/Api/Method/Api5/Ping5Method.php

Summary

Maintainability
D
2 days
Test Coverage

ping accesses the super-global variable $_SERVER.
Open

    public static function ping(array $input): void
    {
        $version       = (isset($input['version'])) ? $input['version'] : Api5::$version;
        Api5::$version = ((int)$version >= 350001) ? Api5::$version_numeric : Api5::$version;
        $data_version  = (int)substr($version, 0, 1);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

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

    public static function ping(array $input): void
    {
        $version       = (isset($input['version'])) ? $input['version'] : Api5::$version;
        Api5::$version = ((int)$version >= 350001) ? Api5::$version_numeric : Api5::$version;
        $data_version  = (int)substr($version, 0, 1);
Severity: Minor
Found in src/Module/Api/Method/Api5/Ping5Method.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

Reference to static property version_numeric from undeclared class \Ampache\Module\Api\Api5
Open

        Api5::$version = ((int)$version >= 350001) ? Api5::$version_numeric : Api5::$version;
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Reference to static property version from undeclared class \Ampache\Module\Api\Api5
Open

            'version' => Api5::$version,
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to method write from undeclared class \Ampache\Module\System\Session
Open

                Session::write($input['auth'], $data_version, $perpetual);
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to method exists from undeclared class \Ampache\Module\System\Session
Open

        if (array_key_exists('auth', $input) && Session::exists('api', $input['auth'])) {
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to method keyed_array from undeclared class \Ampache\Module\Api\Xml5_Data
Open

                echo Xml5_Data::keyed_array($results);
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to method extend from undeclared class \Ampache\Module\System\Session
Open

            Session::extend($input['auth'], 'api');
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Reference to constant API_VERSIONS from undeclared class \Ampache\Module\Api\Api
Open

            if (in_array($data_version, Api::API_VERSIONS)) {
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Reference to static property version from undeclared class \Ampache\Module\Api\Api5
Open

        Api5::$version = ((int)$version >= 350001) ? Api5::$version_numeric : Api5::$version;
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to method server_details from undeclared class \Ampache\Module\Api\Api5
Open

                Api5::server_details($input['auth'])
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
Open

        debug_event(self::class, "Ping$data_version Received from " . filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP), 5);

Reference to static property version from undeclared class \Ampache\Module\Api\Api5
Open

        $version       = (isset($input['version'])) ? $input['version'] : Api5::$version;
Severity: Critical
Found in src/Module/Api/Method/Api5/Ping5Method.php by phan

Define a constant instead of duplicating this literal "version" 4 times.
Open

        $version       = (isset($input['version'])) ? $input['version'] : Api5::$version;

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

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

<?php

declare(strict_types=0);

/**
Severity: Major
Found in src/Module/Api/Method/Api5/Ping5Method.php and 1 other location - About 2 days to fix
src/Module/Api/Method/PingMethod.php on lines 1..92

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

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