ampache/ampache

View on GitHub
src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php

Summary

Maintainability
D
2 days
Test Coverage

AmpacheHttpq has 30 functions (exceeds 20 allowed). Consider refactoring.
Open

class AmpacheHttpq extends localplay_controller
{
    /* Variables */
    private $version     = '000002';
    private $description = "Controls an httpQ instance, requires Ampache's httpQ version";
Severity: Minor
Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php - About 3 hrs to fix

    The class AmpacheHttpq has 22 public methods. Consider refactoring AmpacheHttpq to keep number of public methods under 10.
    Open

    class AmpacheHttpq extends localplay_controller
    {
        /* Variables */
        private $version     = '000002';
        private $description = "Controls an httpQ instance, requires Ampache's httpQ version";

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

    The class AmpacheHttpq has an overall complexity of 61 which is very high. The configured complexity threshold is 50.
    Open

    class AmpacheHttpq extends localplay_controller
    {
        /* Variables */
        private $version     = '000002';
        private $description = "Controls an httpQ instance, requires Ampache's httpQ version";

    Function get has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get(): array
        {
            /* Get the Current Playlist */
            $list = $this->_httpq->get_tracks();
    
    
    Severity: Minor
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.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 status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function status(): array
        {
            $array = array();
            /* Construct the Array */
            $array['state']  = $this->_httpq->state();
    Severity: Minor
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.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 get() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
    Open

        public function get(): array
        {
            /* Get the Current Playlist */
            $list = $this->_httpq->get_tracks();
    
    

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
    Open

        public function get(): array

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Class "AmpacheHttpq" has 30 methods, which is greater than 20 authorized. Split it into smaller classes.
    Open

    class AmpacheHttpq extends localplay_controller

    A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

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

        public function get(): array
        {
            /* Get the Current Playlist */
            $list = $this->_httpq->get_tracks();
    
    

    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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                        } else {
                            $data['name'] = basename($data['raw']);
                            $data['link'] = basename($data['raw']);
                        }

    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

    The method status uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $array['track_title'] = basename($array['track'] ?? '');
            }

    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

    The method status uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $array['track_title']  = $song->title;
                    $array['track_artist'] = $song->get_artist_fullname();
                    $array['track_album']  = $song->get_album_fullname();
                }

    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

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

                $data['track'] = $key + 1;

    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.

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

            $fields['name']     = array('description' => T_('Instance Name'), 'type' => 'text');

    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.

    Define a constant instead of duplicating this literal "httpq_active" 5 times.
    Open

            Preference::insert('httpq_active', T_('HTTPQ Active Instance'), 0, 25, 'integer', 'internal', 'httpq');

    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.

    Define a constant instead of duplicating this literal "Unknown" 3 times.
    Open

                    $array['track_title']  = T_('Unknown');

    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.

    Define a constant instead of duplicating this literal "httpq.controller" 3 times.
    Open

            debug_event('httpq.controller', 'set_active_instance: ' . $uid . ' ' . $user->id, 5);

    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.

    Define a constant instead of duplicating this literal "track_title" 3 times.
    Open

                    $array['track_title']  = T_('Unknown');

    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.

    Define a constant instead of duplicating this literal "password" 5 times.
    Open

            return Dba::write($sql, array($data['name'] ?? null, $data['host'] ?? null, $data['port'] ?? null, $data['password'] ?? null, $user_id));

    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.

    Add a "case default" clause to this "switch" statement.
    Open

                            switch ($row['type']) {

    The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

    Noncompliant Code Example

    switch ($param) {  //missing default clause
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
    }
    
    switch ($param) {
      default: // default clause should be the last one
        error();
        break;
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
    }
    

    Compliant Solution

    switch ($param) {
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
      default:
        error();
        break;
    }
    

    See

    • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
    • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
    • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
    • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
    • MISRA C:2012, 16.1 - All switch statements shall be well-formed
    • MISRA C:2012, 16.4 - Every switch statement shall have a default label
    • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
    • MITRE, CWE-478 - Missing Default Case in Switch Statement
    • CERT, MSC01-C. - Strive for logical completeness
    • CERT, MSC01-CPP. - Strive for logical completeness

    Call to method read from undeclared class \Ampache\Module\System\Dba
    Open

            $db_results = Dba::read($sql);

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

            return Dba::write($sql, array($data['name'] ?? null, $data['host'] ?? null, $data['port'] ?? null, $data['password'] ?? null, $user_id));

    Call to method query from undeclared class \Ampache\Module\System\Dba
    Open

            $db_results = ($instance > 0) ? Dba::query($sql, array($instance)) : Dba::query($sql);

    Reference to instance property f_artist from undeclared class \Ampache\Repository\Model\Song
    Open

                        $data['name'] = $song->get_fullname() . ' - ' . $song->f_album . ' - ' . $song->f_artist;

    Reference to instance property name from undeclared class \Ampache\Repository\Model\Democratic
    Open

                        $data['name'] = T_('Democratic') . ' - ' . $democratic->name;

    Call to method format from undeclared class \Ampache\Repository\Model\Song
    Open

                        $song->format();

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $uid = Dba::escape($uid);

    Call to method get_f_link from undeclared class \Ampache\Repository\Model\Song
    Open

                        $data['link'] = $song->get_f_link();

    Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

                        if ($row = Dba::fetch_assoc($db_results)) {

    Call to method num_rows from undeclared class \Ampache\Module\System\Dba
    Open

            return (Dba::num_rows($db_results) > 0);

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

                debug_event('httpq.controller', 'add_url failed to add ' . (string)$url->url, 1);

    Reference to instance property f_album from undeclared class \Ampache\Repository\Model\Song
    Open

                        $data['name'] = $song->get_fullname() . ' - ' . $song->f_album . ' - ' . $song->f_artist;

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

            debug_event('httpq.controller', 'set_active_instance: ' . $uid . ' ' . $user->id, 5);

    Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

            return Dba::fetch_assoc($db_results);

    Call to method read from undeclared class \Ampache\Module\System\Dba
    Open

                        $db_results = Dba::read($sql);

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

            Dba::write($sql);

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

            Dba::write($sql);

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

                        $filename = Dba::escape($entry['file']);

    Call to method read from undeclared class \Ampache\Module\System\Dba
    Open

            $db_results = Dba::read($sql);

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $port = Dba::escape($data['port']);

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

                debug_event('httpq.controller', 'Unable to delete ' . $object_id . ' from httpQ', 1);

    Reference to instance property title from undeclared class \Ampache\Repository\Model\Song
    Open

                    $array['track_title']  = $song->title;

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

            Dba::write($sql);

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $host = Dba::escape($data['host']);

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $name = Dba::escape($data['name']);

    Possibly zero references to use statement for classlike/namespace Live_Stream (\Ampache\Repository\Model\Live_Stream)
    Open

    use Ampache\Repository\Model\Live_Stream;

    Call to method __construct from undeclared class \Ampache\Repository\Model\Song
    Open

                        $song        = new Song($data['oid']);

    Call to method get_fullname from undeclared class \Ampache\Repository\Model\Song
    Open

                        $data['name'] = $song->get_fullname() . ' - ' . $song->f_album . ' - ' . $song->f_artist;

    Call to method isNew from undeclared class \Ampache\Repository\Model\Song
    Open

                if ($song->isNew()) {

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $uid  = Dba::escape($uid);

    Call to method escape from undeclared class \Ampache\Module\System\Dba
    Open

            $pass = Dba::escape($data['password']);

    When fetching an array index from a value of type string, found an array index of type 'file', but expected the index to be of type int
    Open

                        $filename = Dba::escape($entry['file']);

    Call to method get_artist_fullname from undeclared class \Ampache\Repository\Model\Song
    Open

                    $array['track_artist'] = $song->get_artist_fullname();

    Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

            while ($row = Dba::fetch_assoc($db_results)) {

    Call to method get_album_fullname from undeclared class \Ampache\Repository\Model\Song
    Open

                    $array['track_album']  = $song->get_album_fullname();

    Call to method __construct from undeclared class \Ampache\Repository\Model\Democratic
    Open

                        $democratic   = new Democratic($url_data['demo_id']);

    Call to method query from undeclared class \Ampache\Module\System\Dba
    Open

            Dba::query($sql);

    Call to method __construct from undeclared class \Ampache\Repository\Model\Song
    Open

                $song = new Song($url_data['oid']);

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

                        if ($row = Dba::fetch_assoc($db_results)) {
                            $className = ObjectTypeToClassNameMapper::map($row['type']);
                            $media     = new $className($row['id']);
                            $media->format();
                            switch ($row['type']) {
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 1 other location - About 4 hrs to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 483..506

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

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

        public function instance_fields(): array
        {
            $fields             = array();
            $fields['name']     = array('description' => T_('Instance Name'), 'type' => 'text');
            $fields['host']     = array('description' => T_('Hostname'), 'type' => 'text');
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 208..217
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 181..190

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

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

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

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

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

    Refactorings

    Further Reading

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

        public function install(): bool
        {
            $collation = (AmpConfig::get('database_collation', 'utf8mb4_unicode_ci'));
            $charset   = (AmpConfig::get('database_charset', 'utf8mb4'));
            $engine    = ($charset == 'utf8mb4') ? 'InnoDB' : 'MYISAM';
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 91..104
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 85..98

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

    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 (array_key_exists('oid', $url_data) && !empty($url_data['oid'])) {
                $song = new Song($url_data['oid']);
                if ($song->isNew()) {
                    $array['track_title']  = T_('Unknown');
                    $array['track_artist'] = T_('Unknown');
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 1 other location - About 2 hrs to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 550..577

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

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

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

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

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

    Refactorings

    Further Reading

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

        public function add_instance($data)
        {
            $sql     = "INSERT INTO `localplay_httpq` (`name`, `host`, `port`, `password`, `owner`) VALUES (?, ?, ?, ?, ?)";
            $user_id = !empty(Core::get_global('user'))
                ? Core::get_global('user')->id
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 126..134
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 121..129

    Duplicated Code

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

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

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

    Tuning

    This issue has a mass of 123.

    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

        public function set_active_instance($uid): bool
        {
            $user = Core::get_global('user');
            if ($user == '') {
                return false;
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 3 other locations - About 1 hr to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 224..235
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 212..223
    src/Module/Playback/Localplay/Xbmc/AmpacheXbmc.php on lines 219..230

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

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

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

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

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

    Refactorings

    Further Reading

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

        public function get_instance($instance = ''): array
        {
            $instance   = (is_numeric($instance)) ? (int) $instance : (int) AmpConfig::get('httpq_active', 0);
            $sql        = ($instance > 0) ? "SELECT * FROM `localplay_httpq` WHERE `id` = ?" : "SELECT * FROM `localplay_httpq`";
            $db_results = ($instance > 0) ? Dba::query($sql, array($instance)) : Dba::query($sql);
    Severity: Major
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 4 other locations - About 1 hr to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 175..182
    src/Module/Playback/Localplay/Upnp/AmpacheUPnP.php on lines 197..204
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 198..205
    src/Module/Playback/Localplay/Xbmc/AmpacheXbmc.php on lines 205..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 109.

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

                    case 'oid':
                        $data['oid'] = $url_data['oid'];
                        $song        = new Song($data['oid']);
                        $song->format();
                        $data['name'] = $song->get_fullname() . ' - ' . $song->f_album . ' - ' . $song->f_artist;
    Severity: Minor
    Found in src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php and 2 other locations - About 35 mins to fix
    src/Module/Playback/Localplay/Mpd/AmpacheMpd.php on lines 458..464
    src/Module/Playback/Localplay/Vlc/AmpacheVlc.php on lines 496..502

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

    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

    The parameter $object_id is not named in camelCase.
    Open

        public function delete_track($object_id): bool
        {
            if ($this->_httpq->delete_pos($object_id) === null) {
                debug_event('httpq.controller', 'Unable to delete ' . $object_id . ' from httpQ', 1);
    
    

    CamelCaseParameterName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name parameters.

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

    Property name "$_httpq" should not be prefixed with an underscore to indicate visibility
    Open

        private $_httpq;

    There are no issues that match your filters.

    Category
    Status