ampache/ampache

View on GitHub
src/Module/Playlist/Search/AlbumSearch.php

Summary

Maintainability
F
2 wks
Test Coverage

Function getSql has a Cognitive Complexity of 182 (exceeds 5 allowed). Consider refactoring.
Open

    public function getSql(
        Search $search
    ): array {
        $search_user_id     = $search->search_user->id ?? -1;
        $sql_logic_operator = $search->logic_operator;
Severity: Minor
Found in src/Module/Playlist/Search/AlbumSearch.php - About 3 days 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

Method getSql has 443 lines of code (exceeds 200 allowed). Consider refactoring.
Open

    public function getSql(
        Search $search
    ): array {
        $search_user_id     = $search->search_user->id ?? -1;
        $sql_logic_operator = $search->logic_operator;
Severity: Major
Found in src/Module/Playlist/Search/AlbumSearch.php - About 1 day to fix

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

    final class AlbumSearch implements SearchInterface
    {
        /**
         * Handles the generation of the SQL for album searches.
         * @param Search $search

    The method getSql() has 463 lines of code. Current threshold is set to 100. Avoid really long methods.
    Open

        public function getSql(
            Search $search
        ): array {
            $search_user_id     = $search->search_user->id ?? -1;
            $sql_logic_operator = $search->logic_operator;

    The method getSql() has an NPath complexity of 4754736. The configured NPath complexity threshold is 200.
    Open

        public function getSql(
            Search $search
        ): array {
            $search_user_id     = $search->search_user->id ?? -1;
            $sql_logic_operator = $search->logic_operator;

    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 getSql() has a Cyclomatic Complexity of 140. The configured cyclomatic complexity threshold is 10.
    Open

        public function getSql(
            Search $search
        ): array {
            $search_user_id     = $search->search_user->id ?? -1;
            $sql_logic_operator = $search->logic_operator;

    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

    Reduce the number of switch cases from 46 to at most 30.
    Open

                switch ($rule[0]) {

    When switch statements have large sets of case clauses, it is usually an attempt to map two sets of data. A real map structure would be more readable and maintainable, and should be used instead.

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

        public function getSql(

    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

    This function "getSql" has 461 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
    Open

        public function getSql(
            Search $search
        ): array {

    A function that grows too large tends to aggregate too many responsibilities.

    Such functions inevitably become harder to understand and therefore harder to maintain.

    Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

    Those smaller functions will not only be easier to understand, but also probably easier to test.

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

                        } else {
                            $where[]      = "`album`.`id` IN (SELECT `id` FROM `album` WHERE `id` IN (SELECT `album` FROM `song` WHERE `id` IN (SELECT `object_id` FROM `rating` WHERE `user` = " . $search_user_id . " AND `object_type`='song' AND `rating` $operator_sql ?)))";
                            $parameters[] = $input;
                        }

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

                } else {
                    $where_sql = "`catalog_se`.`id` IN (SELECT `catalog_id` FROM `catalog_filter_group_map` INNER JOIN `user` ON `user`.`catalog_filter_group` = `catalog_filter_group_map`.`group_id` WHERE `user`.`id` = " . $search_user_id . " AND `catalog_filter_group_map`.`enabled`=1)";
                }

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

                        } else {
                            $where[]      = "`rating_" . $my_type . "_" . $search_user_id . "`.`rating` $operator_sql ?";
                            $parameters[] = $input;
                        }

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

                        } else {
                            $where[] = "`song`.`mbid` $operator_sql ?";
                        }

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

                        } else {
                            $where[] = "`album`.`" . $rule[0] . "` $operator_sql ?";
                        }

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

                        } else {
                            $where[] = "(`album`.`name` $operator_sql ? OR LTRIM(CONCAT(COALESCE(`album`.`prefix`, ''), ' ', `album`.`name`)) $operator_sql ?)";
                        }

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

                        } else {
                            $column  = 'id';
                            $my_type = 'album';
                            $where[] = "`rating_album_" . $other_userid . '`.' . $operator_sql . " AND `rating_album_$other_userid`.`user` = $other_userid AND `rating_album_$other_userid`.`object_type` = 'album'";
                            // rating once per user

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

                        } else {
                            $where[] = "`album`.`mbid` $operator_sql ?";
                        }

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

                } else {
                    $where_sql = "`catalog_se`.`enabled` = '1'";
                }

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

                        } else {
                            $where[] = "(`album`.`name` $operator_sql ? OR LTRIM(CONCAT(COALESCE(`album`.`prefix`, ''), ' ', `album`.`name`)) $operator_sql ?) AND `favorite_album_" . $search_user_id . "`.`user` = " . $search_user_id . " AND `favorite_album_" . $search_user_id . "`.`object_type` = 'album'";
                        }

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

                        } else {
                            $where[] = "((`artist`.`name` $operator_sql ? OR LTRIM(CONCAT(COALESCE(`artist`.`prefix`, ''), ' ', `artist`.`name`)) $operator_sql ?) AND `album_map`.`object_type` = 'song')";
                        }

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

                        } else {
                            $where[] = "`song`.`title` $operator_sql ?";
                        }

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

                        } else {
                            $where[] = "`song`.`file` $operator_sql ?";
                        }

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

                        } else {
                            $where[] = "`album`.`id` IN (SELECT `song`.`album` FROM `playlist_data` LEFT JOIN `playlist` ON `playlist_data`.`playlist` = `playlist`.`id` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` AND `playlist_data`.`object_type` = 'song' WHERE `playlist`.`name` $operator_sql ?)";
                        }

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

                        } else {
                            $where[] = "((`artist`.`name` $operator_sql ? OR LTRIM(CONCAT(COALESCE(`artist`.`prefix`, ''), ' ', `artist`.`name`)) $operator_sql ?) AND `album_map`.`object_type` = 'album')";
                        }

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

                        } else {
                            $where[] = "`artist`.`mbid` $operator_sql ?";
                        }

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

                        $my_type = ($looking == 'my') ? 'album' : $looking;

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

                    case 'played':

    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 ($rule[0]) {

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

                    case 'last_play_or_skip':

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

                        if ($my_type == '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 "catalog" 3 times.
    Open

                    case 'catalog':

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

                    case 'favorite':

    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.

    Remove this commented out code.
    Open

                        //debug_event(self::class, '_get_sql_song: SUBSEARCH ' . $input, 5);

    Programmers should not comment out code as it bloats programs and reduces readability.

    Unused code should be deleted and can be retrieved from source control history if required.

    See

    • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
    • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
    • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
    • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

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

                    case 'myplayed':

    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 "NOT SOUNDS LIKE" 14 times.
    Open

                        if ($operator_sql === 'NOT SOUNDS LIKE') {

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

                        $where[] = ($operator_sql == "NOT LIKE")

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

                    case 'last_play':

    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 ".user` = " 3 times.
    Open

                            $where[] = "NOT ((`album`.`name` SOUNDS LIKE ? OR LTRIM(CONCAT(COALESCE(`album`.`prefix`, ''), ' ', `album`.`name`)) SOUNDS LIKE ?) AND `favorite_album_" . $search_user_id . "`.`user` = " . $search_user_id . " AND `favorite_album_" . $search_user_id . "`.`object_type` = '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.

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

                            $join['album_map'] = true;

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

                    case 'rating':

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

                    case 'last_skip':

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

                            if (in_array($operator_sql, array('=', 'LIKE', 'SOUNDS LIKE'))) {

    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 get_subsearch from undeclared class \Ampache\Repository\Model\Search
    Open

                        $results   = $subsearch->get_subsearch('song');
    Severity: Critical
    Found in src/Module/Playlist/Search/AlbumSearch.php by phan

    Reference to instance property basetypes from undeclared class \Ampache\Repository\Model\Search
    Open

                foreach ($search->basetypes[$type] as $baseOperator) {

    Parameter $search has undeclared type \Ampache\Repository\Model\Search
    Open

        public function getSql(

    Call to method get_rule_type from undeclared class \Ampache\Repository\Model\Search
    Open

                $type     = $search->get_rule_type($rule[0]);
    Severity: Critical
    Found in src/Module/Playlist/Search/AlbumSearch.php by phan

    Reference to instance property search_user from undeclared class \Ampache\Repository\Model\Search
    Open

            $search_user_id     = $search->search_user->id ?? -1;

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

                $operator_sql = $operator['sql'] ?? '';

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

                        $subsearch = new Search((int)$input, 'song', $search->search_user);
    Severity: Critical
    Found in src/Module/Playlist/Search/AlbumSearch.php by phan

    Reference to instance property rules from undeclared class \Ampache\Repository\Model\Search
    Open

            foreach ($search->rules as $rule) {

    Call to method filter_data from undeclared class \Ampache\Repository\Model\Search
    Open

                $input        = $search->filter_data((string)$rule[2], $type, $operator);
    Severity: Critical
    Found in src/Module/Playlist/Search/AlbumSearch.php by phan

    Reference to instance property search_user from undeclared class \Ampache\Repository\Model\Search
    Open

                        $subsearch = new Search((int)$input, 'song', $search->search_user);

    Reference to instance property logic_operator from undeclared class \Ampache\Repository\Model\Search
    Open

            $sql_logic_operator = $search->logic_operator;

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

                    case 'artistrating':
                        // combine these as they all do the same thing just different tables
                        $looking = str_replace('rating', '', $rule[0]);
                        $column  = ($looking == 'my') ? '`album`.`id`' : '`album_map`.`object_id`';
                        $my_type = ($looking == 'my') ? 'album' : $looking;
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 1 other location - About 2 days to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 125..160

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

    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

                    case 'other_user':
                        $other_userid = $input;
                        if ($operator_sql == 'userflag') {
                            $where[] = "`favorite_album_$other_userid`.`user` = $other_userid AND `favorite_album_$other_userid`.`object_type` = 'album'";
                            // flag once per user
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 2 other locations - About 1 day to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 255..278
    src/Module/Playlist/Search/ArtistSearch.php on lines 332..355

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

    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

                    case 'myplayedartist':
                        // combine these as they all do the same thing just different tables
                        $looking      = str_replace('myplayed', '', $rule[0]);
                        $column       = ($looking == 'artist') ? 'album_artist' : 'id';
                        $my_type      = ($looking == 'artist') ? 'artist' : 'album';
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 1 other location - About 1 day to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 184..198

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

    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

                    case 'songrating':
                        if ($input == 0 && $operator_sql == '>=') {
                            break;
                        }
                        if ($input == 0 && $operator_sql == '<') {
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 1 other location - About 7 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 161..182

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

    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

                    case 'favorite':
                        if ($operator_sql === 'NOT SOUNDS LIKE') {
                            $where[] = "NOT ((`album`.`name` SOUNDS LIKE ? OR LTRIM(CONCAT(COALESCE(`album`.`prefix`, ''), ' ', `album`.`name`)) SOUNDS LIKE ?) AND `favorite_album_" . $search_user_id . "`.`user` = " . $search_user_id . " AND `favorite_album_" . $search_user_id . "`.`object_type` = 'album')";
                        } else {
                            $where[] = "(`album`.`name` $operator_sql ? OR LTRIM(CONCAT(COALESCE(`album`.`prefix`, ''), ' ', `album`.`name`)) $operator_sql ?) AND `favorite_album_" . $search_user_id . "`.`user` = " . $search_user_id . " AND `favorite_album_" . $search_user_id . "`.`object_type` = 'album'";
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 2 other locations - About 6 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 109..123
    src/Module/Playlist/Search/ArtistSearch.php on lines 143..157

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

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

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

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

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

    Refactorings

    Further Reading

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

                    case 'last_skip':
                        $my_type = 'album';
                        if (!array_key_exists('last_skip', $table)) {
                            $table['last_skip'] = '';
                        }
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 5 other locations - About 5 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 223..234
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 235..246
    src/Module/Playlist/Search/AlbumSearch.php on lines 235..246
    src/Module/Playlist/Search/ArtistSearch.php on lines 277..288
    src/Module/Playlist/Search/ArtistSearch.php on lines 289..300

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

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

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

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

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

    Refactorings

    Further Reading

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

                    case 'last_play_or_skip':
                        $my_type = 'album';
                        if (!array_key_exists('last_play_or_skip', $table)) {
                            $table['last_play_or_skip'] = '';
                        }
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 5 other locations - About 5 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 223..234
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 235..246
    src/Module/Playlist/Search/AlbumSearch.php on lines 223..234
    src/Module/Playlist/Search/ArtistSearch.php on lines 277..288
    src/Module/Playlist/Search/ArtistSearch.php on lines 289..300

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

    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

                    case 'last_play':
                        $my_type = 'album';
                        if (!array_key_exists('last_play', $table)) {
                            $table['last_play'] = '';
                        }
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 2 other locations - About 5 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 212..222
    src/Module/Playlist/Search/ArtistSearch.php on lines 266..276

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

    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

                    case 'played':
                        $column       = 'id';
                        $my_type      = 'album';
                        $operator_sql = ((int)$operator_sql == 0) ? 'IS NULL' : 'IS NOT NULL';
                        // played once per user
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 1 other location - About 3 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 199..211

    Duplicated Code

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

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

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

    Tuning

    This issue has a mass of 161.

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

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

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

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

    Refactorings

    Further Reading

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

                    case 'mbid_song':
                        if (!$input || $input == '%%' || $input == '%') {
                            if (in_array($operator_sql, array('=', 'LIKE', 'SOUNDS LIKE'))) {
                                $where[] = "`song`.`mbid` IS NULL";
                                break;
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 6 other locations - About 3 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 383..401
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 402..420
    src/Module/Playlist/Search/AlbumSearch.php on lines 415..433
    src/Module/Playlist/Search/ArtistSearch.php on lines 384..402
    src/Module/Playlist/Search/ArtistSearch.php on lines 403..421
    src/Module/Playlist/Search/SongSearch.php on lines 543..561

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

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

                    case 'mbid_artist':
                        if (!$input || $input == '%%' || $input == '%') {
                            if (in_array($operator_sql, array('=', 'LIKE', 'SOUNDS LIKE'))) {
                                $where[] = "`artist`.`mbid` IS NULL";
                                break;
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 6 other locations - About 3 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 383..401
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 402..420
    src/Module/Playlist/Search/AlbumSearch.php on lines 396..414
    src/Module/Playlist/Search/ArtistSearch.php on lines 384..402
    src/Module/Playlist/Search/ArtistSearch.php on lines 403..421
    src/Module/Playlist/Search/SongSearch.php on lines 543..561

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

    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

                    case 'mbid':
                        if (!$input || $input == '%%' || $input == '%') {
                            if (in_array($operator_sql, array('=', 'LIKE', 'SOUNDS LIKE'))) {
                                $where[] = "`album`.`mbid` IS NULL";
                                break;
    Severity: Major
    Found in src/Module/Playlist/Search/AlbumSearch.php and 3 other locations - About 2 hrs to fix
    src/Module/Playlist/Search/AlbumDiskSearch.php on lines 365..382
    src/Module/Playlist/Search/ArtistSearch.php on lines 366..383
    src/Module/Playlist/Search/SongSearch.php on lines 506..523

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

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

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

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

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

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status