ampache/ampache

View on GitHub
src/Repository/Model/playlist_object.php

Summary

Maintainability
A
1 hr
Test Coverage

Function gather_art has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function gather_art($limit): array
    {
        $medias   = $this->get_medias();
        $count    = 0;
        $images   = array();
Severity: Minor
Found in src/Repository/Model/playlist_object.php - About 1 hr to fix

Cognitive Complexity

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

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

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

Further reading

The class playlist_object has 16 fields. Consider redesigning playlist_object to keep the number of fields under 15.
Open

abstract class playlist_object extends database_object implements library_item
{
    // Database variables
    public int $id = 0;
    public ?string $name;

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

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

Avoid unused parameters such as '$details'.
Open

    public function format($details = true): void

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 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open

    public int $id = 0;
Severity: Critical
Found in src/Repository/Model/playlist_object.php by phan

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

        } else {
            return $this->get_items();
        }

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 variables with short names like $id. Configured minimum length is 3.
Open

    public int $id = 0;

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

The class playlist_object is not named in CamelCase.
Open

abstract class playlist_object extends database_object implements library_item
{
    // Database variables
    public int $id = 0;
    public ?string $name;

CamelCaseClassName

Since: 0.2

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

Example

class class_name {
}

Source

The parameter $user_id is not named in camelCase.
Open

    public function has_access($user_id = null): bool
    {
        if (Access::check('interface', 100)) {
            return true;
        }

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

    public function get_medias(?string $filter_type = null): array
    {
        if ($filter_type) {
            return array_filter(
                $this->get_items(),

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 "playlist_object" is not in camel caps format
Open

abstract class playlist_object extends database_object implements library_item

There are no issues that match your filters.

Category
Status