ampache/ampache

View on GitHub
src/Module/Catalog/Catalog_subsonic.php

Summary

Maintainability
D
2 days
Test Coverage

Function update_remote_catalog has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    public function update_remote_catalog(): int
    {
        debug_event('subsonic.catalog', 'Updating remote catalog...', 5);

        $subsonic = $this->createClient();
Severity: Minor
Found in src/Module/Catalog/Catalog_subsonic.php - About 1 day 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 class Catalog_subsonic has an overall complexity of 66 which is very high. The configured complexity threshold is 50.
Open

class Catalog_subsonic extends Catalog
{
    private string $version     = '000002';
    private string $type        = 'subsonic';
    private string $description = 'Subsonic Remote Catalog';

The class Catalog_subsonic has 17 public methods. Consider refactoring Catalog_subsonic to keep number of public methods under 10.
Open

class Catalog_subsonic extends Catalog
{
    private string $version     = '000002';
    private string $type        = 'subsonic';
    private string $description = 'Subsonic Remote Catalog';

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

Catalog_subsonic has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class Catalog_subsonic extends Catalog
{
    private string $version     = '000002';
    private string $type        = 'subsonic';
    private string $description = 'Subsonic Remote Catalog';
Severity: Minor
Found in src/Module/Catalog/Catalog_subsonic.php - About 2 hrs to fix

    Function cache_catalog_proc has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        public function cache_catalog_proc(): bool
        {
            $remote = AmpConfig::get('cache_remote');
            $path   = (string)AmpConfig::get('cache_path', '');
            $target = (string)AmpConfig::get('cache_target', '');
    Severity: Minor
    Found in src/Module/Catalog/Catalog_subsonic.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 clean_catalog_proc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function clean_catalog_proc(): int
        {
            $subsonic = $this->createClient();
    
            $dead = 0;
    Severity: Minor
    Found in src/Module/Catalog/Catalog_subsonic.php - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

        public function cache_catalog_proc(): bool
        {
            $remote = AmpConfig::get('cache_remote');
            $path   = (string)AmpConfig::get('cache_path', '');
            $target = (string)AmpConfig::get('cache_target', '');

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

        public function update_remote_catalog(): int
        {
            debug_event('subsonic.catalog', 'Updating remote catalog...', 5);
    
            $subsonic = $this->createClient();

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

                                    } else {
                                        $data['catalog'] = $this->catalog_id;
                                        debug_event('subsonic.catalog', 'Adding song ' . $song['path'], 5);
                                        $song_Id = Song::insert($data);
                                        if (!$song_Id) {

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

            } else {
                $size = array('width' => 275, 'height' => 275);
            }

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

                } else {
                    break;
                }

    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 '497', column '13').
    Open

        public function check_remote_song($song)
        {
            $url = $song['file'];
    
            $sql        = 'SELECT `id` FROM `song` WHERE `file` = ?';

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

                                        } else {
                                            if ($song['coverArt']) {
                                                $this->insertArt($song, $song_Id);
                                            }
                                        }

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

                } else {
                    debug_event('subsonic.catalog', 'removing song', 5);
                    $dead++;
                    Dba::write('DELETE FROM `song` WHERE `id` = ?', array($row['id']));
                }

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

                    } else {
                        try {
                            $filehandle = fopen($target_file, 'w');
                            $curl       = curl_init();
                            curl_setopt_array(

    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 unused parameters such as '$new_path'.
    Open

        public function move_catalog_proc($new_path): bool

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

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

    Avoid unused parameters such as '$media'.
    Open

        public function prepare_media($media): ?array

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

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

    Avoid unused parameters such as '$options'.
    Open

        public function add_to_catalog($options = null): int

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

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

    syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
    Open

        private string $version     = '000002';
    Severity: Critical
    Found in src/Module/Catalog/Catalog_subsonic.php by phan

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

                        try {
                            $filehandle = fopen($target_file, 'w');
                            $curl       = curl_init();
                            curl_setopt_array(
                                $curl,
    Severity: Major
    Found in src/Module/Catalog/Catalog_subsonic.php and 1 other location - About 5 hrs to fix
    src/Module/Catalog/Catalog_remote.php on lines 478..497

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

    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

        public function catalog_fields(): array
        {
            $fields = array();
    
            $fields['uri']      = array('description' => T_('URI'), 'type' => 'url');
    Severity: Major
    Found in src/Module/Catalog/Catalog_subsonic.php and 1 other location - About 1 hr to fix
    src/Module/Catalog/Catalog_remote.php on lines 130..139

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

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

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

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

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

    Refactorings

    Further Reading

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

        public function install(): bool
        {
            $collation = (AmpConfig::get('database_collation', 'utf8mb4_unicode_ci'));
            $charset   = (AmpConfig::get('database_charset', 'utf8mb4'));
            $engine    = ($charset == 'utf8mb4') ? 'InnoDB' : 'MYISAM';
    Severity: Minor
    Found in src/Module/Catalog/Catalog_subsonic.php and 1 other location - About 30 mins to fix
    src/Module/Catalog/Catalog_remote.php on lines 115..125

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

    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 $song_Id is not named in camelCase.
    Open

        public function insertArt($data, $song_Id): bool
        {
            $subsonic = $this->createClient();
            $song     = new Song($song_Id);
            $art      = new Art($song->album, 'album');

    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

    The class Catalog_subsonic is not named in CamelCase.
    Open

    class Catalog_subsonic extends Catalog
    {
        private string $version     = '000002';
        private string $type        = 'subsonic';
        private string $description = 'Subsonic Remote Catalog';

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The parameter $catalog_id is not named in camelCase.
    Open

        public static function create_type($catalog_id, $data): bool
        {
            $uri      = $data['uri'];
            $username = $data['username'];
            $password = $data['password'];

    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

    The parameter $new_path is not named in camelCase.
    Open

        public function move_catalog_proc($new_path): bool
        {
            return false;
        }

    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

    The parameter $catalog_id is not named in camelCase.
    Open

        public function __construct($catalog_id = null)
        {
            if ($catalog_id) {
                $info = $this->get_info($catalog_id, static::DB_TABLENAME);
                foreach ($info as $key => $value) {

    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

    The parameter $file_path is not named in camelCase.
    Open

        public function get_rel_path($file_path): string
        {
            $catalog_path = rtrim($this->uri, "/");
    
            return (str_replace($catalog_path . "/", "", $file_path));

    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

    Class name "Catalog_subsonic" is not in camel caps format
    Open

    class Catalog_subsonic extends Catalog

    There are no issues that match your filters.

    Category
    Status