ampache/ampache

View on GitHub
src/Module/Playback/Localplay/Mpd/AmpacheMpd.php

Summary

Maintainability
F
3 days
Test Coverage

AmpacheMpd has 31 functions (exceeds 20 allowed). Consider refactoring.
Open

class AmpacheMpd extends localplay_controller
{
    /* Variables */
    private $version     = '000003';
    private $description = 'Controls an instance of MPD';
Severity: Minor
Found in src/Module/Playback/Localplay/Mpd/AmpacheMpd.php - About 3 hrs to fix

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

    class AmpacheMpd extends localplay_controller
    {
        /* Variables */
        private $version     = '000003';
        private $description = 'Controls an instance of MPD';

    The class AmpacheMpd has 23 public methods. Consider refactoring AmpacheMpd to keep number of public methods under 10.
    Open

    class AmpacheMpd extends localplay_controller
    {
        /* Variables */
        private $version     = '000003';
        private $description = 'Controls an instance of MPD';

    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

    Function status has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        public function status(): array
        {
            $array = array();
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return $array;
    Severity: Minor
    Found in src/Module/Playback/Localplay/Mpd/AmpacheMpd.php - About 2 hrs 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 get has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get(): array
        {
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return array();
            }
    Severity: Minor
    Found in src/Module/Playback/Localplay/Mpd/AmpacheMpd.php - About 2 hrs 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 status() has an NPath complexity of 204. The configured NPath complexity threshold is 200.
    Open

        public function status(): array
        {
            $array = array();
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return $array;

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

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

    The method get() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10.
    Open

        public function get(): array
        {
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return array();
            }

    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

    The method status() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
    Open

        public function status(): array
        {
            $array = array();
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return $array;

    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

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

    class AmpacheMpd 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.

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

        public function status(): 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

    Refactor this function to reduce its Cognitive Complexity from 26 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

    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

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

        public function get(): array
        {
            if (!$this->_mpd || ($this->_mpd && !$this->_mpd->status)) {
                return array();
            }

    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 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'] = $playlist_item['file'] ?? '';
                    }

    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 {
                    if (!empty($playlist_item['Name'])) {
                        $array['track_title'] = $playlist_item['Name'];
                    } else {
                        $array['track_title'] = $playlist_item['file'] ?? '';

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

                        } else {
                            $title_string = (isset($entry['Title']) && isset($entry['Album']) && isset($entry['Artist']))
                                ? $entry['Title'] . ' - ' . $entry['Album'] . ' - ' . $entry['Artist']
                                : T_('Unknown');
                            $data['name'] = $title_string;

    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 "random" 3 times.
    Open

                    case 'random':

    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 "Artist" 4 times.
    Open

                            $title_string = (isset($entry['Title']) && isset($entry['Album']) && isset($entry['Artist']))

    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" 4 times.
    Open

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

    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

    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.

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

            $array['track_title']  = '';

    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 "mpd_active" 5 times.
    Open

            Preference::insert('mpd_active', T_('MPD Active Instance'), 0, 25, 'integer', 'internal', 'mpd');

    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 "Title" 4 times.
    Open

                            $title_string = (isset($entry['Title']) && isset($entry['Album']) && isset($entry['Artist']))

    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 "Album" 4 times.
    Open

                            $title_string = (isset($entry['Title']) && isset($entry['Album']) && isset($entry['Artist']))

    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 "track_artist" 4 times.
    Open

            $array['track_artist'] = '';

    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 "mdp.controller" 3 times.
    Open

            debug_event('mdp.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 "state" 3 times.
    Open

                if ($this->_mpd->status['state'] == mpd::STATE_STOPPED) {

    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_album" 4 times.
    Open

            $array['track_album']  = '';

    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.

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

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

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

                        $song->format();

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

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

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

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

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

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

    Invalid offset "file" of array type array{}
    Open

                        $array['track_title'] = $playlist_item['file'] ?? '';

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

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

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

                debug_event('mdp.controller', 'add_url failed to add: ' . json_encode($url), 1);

    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 escape from undeclared class \Ampache\Module\System\Dba
    Open

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

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

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

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

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

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

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

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

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

    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 fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

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

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

            debug_event('mdp.controller', 'Status result. Current song (' . $track . ') info: ' . json_encode($playlist_item), 5);

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

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

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

    use Ampache\Repository\Model\Live_Stream;

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

    use Ampache\Repository\Model\Random;

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

            Dba::query($sql);

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

    use Ampache\Repository\Model\library_item;

    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);

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

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

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

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

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

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

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

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

    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;

    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();

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

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

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

                if ($song->isNew()) {

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

            return Dba::fetch_assoc($db_results);

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

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

    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 = $data['host'] ? Dba::escape($data['host']) : '127.0.0.1';

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

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

    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 method read from undeclared class \Ampache\Module\System\Dba
    Open

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

    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/Mpd/AmpacheMpd.php and 1 other location - About 4 hrs to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 484..504

    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/Mpd/AmpacheMpd.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 191..200
    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/Mpd/AmpacheMpd.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 88..101
    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 (count($url_data) > 0 && 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/Mpd/AmpacheMpd.php and 1 other location - About 2 hrs to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 533..546

    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_mpd` (`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/Mpd/AmpacheMpd.php and 2 other locations - About 2 hrs to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 124..132
    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/Mpd/AmpacheMpd.php and 3 other locations - About 1 hr to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 222..233
    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('mpd_active', 0);
            $sql        = ($instance > 0) ? "SELECT * FROM `localplay_mpd` WHERE `id` = ?" : "SELECT * FROM `localplay_mpd`";
            $db_results = ($instance > 0) ? Dba::query($sql, array($instance)) : Dba::query($sql);
    Severity: Major
    Found in src/Module/Playback/Localplay/Mpd/AmpacheMpd.php and 4 other locations - About 1 hr to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 208..215
    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/Mpd/AmpacheMpd.php and 2 other locations - About 35 mins to fix
    src/Module/Playback/Localplay/HttpQ/AmpacheHttpq.php on lines 462..468
    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)
        {
            return $this->_mpd->PLRemove($object_id);
        }

    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 "$_add_count" should not be prefixed with an underscore to indicate visibility
    Open

        private $_add_count = 0;

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

        private $_mpd;

    There are no issues that match your filters.

    Category
    Status