ampache/ampache

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

Summary

Maintainability
B
5 hrs
Test Coverage

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

class Song_Preview extends database_object implements Media, playable_item
{
    protected const DB_TABLENAME = 'song_preview';

    public int $id = 0;
Severity: Minor
Found in src/Repository/Model/Song_Preview.php - About 3 hrs to fix

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

    class Song_Preview extends database_object implements Media, playable_item
    {
        protected const DB_TABLENAME = 'song_preview';
    
        public int $id = 0;
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    The class Song_Preview has 22 fields. Consider redesigning Song_Preview to keep the number of fields under 15.
    Open

    class Song_Preview extends database_object implements Media, playable_item
    {
        protected const DB_TABLENAME = 'song_preview';
    
        public int $id = 0;
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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

    The class Song_Preview has 51 public methods and attributes. Consider reducing the number of public items to less than 45.
    Open

    class Song_Preview extends database_object implements Media, playable_item
    {
        protected const DB_TABLENAME = 'song_preview';
    
        public int $id = 0;
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    ExcessivePublicCount

    Since: 0.1

    A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

    Example

    public class Foo {
        public $value;
        public $something;
        public $var;
        // [... more more public attributes ...]
    
        public function doWork() {}
        public function doMoreWork() {}
        public function doWorkAgain() {}
        // [... more more public methods ...]
    }

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

    Function has_info has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        private function has_info($preview_id = 0): array
        {
            if ($preview_id === null) {
                return array();
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.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

    Function stream has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function stream(): void
        {
            foreach (Plugin::get_plugins('stream_song_preview') as $plugin_name) {
                $plugin = new Plugin($plugin_name);
                if ($plugin->_plugin !== null && $plugin->load(Core::get_global('user'))) {
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.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

    Avoid unused parameters such as '$player'.
    Open

        public function get_transcode_settings($target = null, $player = null, $options = array()): array
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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 get_transcode_settings($target = null, $player = null, $options = array()): array
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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 '$target'.
    Open

        public function get_transcode_settings($target = null, $player = null, $options = array()): array
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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 '$player'.
    Open

        public function play_url($additional_params = '', $player = '', $local = false): string
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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 '$player'.
    Open

        public function get_stream_types($player = null): array
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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

    FIXME found
    Open

         * FIXME: Song Preview transcoding is not implemented
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by fixme

    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/Song_Preview.php by phan

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

        private function has_info($preview_id = 0): array
        {
            if ($preview_id === null) {
                return array();
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

            } else {
                $wartist = $this->getMissingArtistRetriever()->retrieve((string) $this->artist_mbid);
    
                return $wartist['name'] ?? '';
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

            } else {
                $wartist             = $this->getMissingArtistRetriever()->retrieve((string) $this->artist_mbid);
                $this->f_artist_link = $wartist['link'] ?? '';
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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 class Song_Preview is not named in CamelCase.
    Open

    class Song_Preview extends database_object implements Media, playable_item
    {
        protected const DB_TABLENAME = 'song_preview';
    
        public int $id = 0;
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    The parameter $album_mbid is not named in camelCase.
    Open

        public static function get_song_previews($album_mbid): array
        {
            $songs = array();
    
            $sql        = "SELECT `id` FROM `song_preview` WHERE `session` = ? AND `album_mbid` = ?";
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

        public function __construct($object_id = 0)
        {
            if (!$object_id) {
                return;
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

        private function has_info($preview_id = 0): array
        {
            if ($preview_id === null) {
                return array();
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

        public function set_played($user_id, $agent, $location, $date): bool
        {
            // Do nothing
            unset($user_id, $agent, $location, $date);
    
    
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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
        {
            $medias = array();
            if ($filter_type === null || $filter_type === 'song_preview') {
                $medias[] = array(
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

    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

    Avoid variables with short names like $id. Configured minimum length is 3.
    Open

        public int $id = 0;
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

        public function play_url($additional_params = '', $player = '', $local = false): string
        {
            $user_id = (!empty(Core::get_global('user')))
                ? scrub_out(Core::get_global('user')->id)
                : '-1';
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

        public static function build_cache($song_ids): bool
        {
            if (empty($song_ids)) {
                return false;
            }
    Severity: Minor
    Found in src/Repository/Model/Song_Preview.php by phpmd

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

    class Song_Preview extends database_object implements Media, playable_item

    There are no issues that match your filters.

    Category
    Status