ampache/ampache

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

Summary

Maintainability
A
3 hrs
Test Coverage

Democratic has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

class Democratic extends Tmp_Playlist
{
    protected const DB_TABLENAME = 'democratic';

    public ?string $name      = null;
Severity: Minor
Found in src/Repository/Model/Democratic.php - About 3 hrs to fix

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

    class Democratic extends Tmp_Playlist
    {
        protected const DB_TABLENAME = 'democratic';
    
        public ?string $name      = null;
    Severity: Minor
    Found in src/Repository/Model/Democratic.php by phpmd

    The class Democratic has 15 public methods. Consider refactoring Democratic to keep number of public methods under 10.
    Open

    class Democratic extends Tmp_Playlist
    {
        protected const DB_TABLENAME = 'democratic';
    
        public ?string $name      = null;
    Severity: Minor
    Found in src/Repository/Model/Democratic.php by phpmd

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

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

    Function get_next_object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get_next_object($offset = 0): ?int
        {
            // FIXME: Shouldn't this return object_type?
    
            $offset     = (int)($offset);
    Severity: Minor
    Found in src/Repository/Model/Democratic.php - About 25 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 get_next_object uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $sql = "SELECT `id` FROM `song` WHERE `enabled`='1'";
                if (AmpConfig::get('catalog_filter') && !empty(Core::get_global('user')) && Core::get_global('user')->id > 0) {
                    $sql .= " AND" . Catalog::get_user_filter("song", Core::get_global('user')->id);
                }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 delete_from_oid uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                debug_event(self::class, 'Unable to find Votes for ' . $object_id . ' of type ' . $object_type, 3);
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 remove_vote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $sql .= "AND `user_vote`.`sid` = ? ";
                $params[] = session_id();
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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

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

        private function _add_vote($object_id, $object_type = 'song'): bool
        {
            if (!$this->tmp_playlist) {
                return false;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 has_vote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $sql .= "AND `user_vote`.`sid` = ? ";
                $params[] = session_id();
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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

    FIXME found
    Open

            // FIXME: Shouldn't this return object_type?
    Severity: Minor
    Found in src/Repository/Model/Democratic.php by fixme

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

        public ?string $name      = null;
    Severity: Critical
    Found in src/Repository/Model/Democratic.php by phan

    The parameter $object_type is not named in camelCase.
    Open

        public function get_uid_from_object_id($object_id, $object_type = 'song'): ?int
        {
            if (!$object_id) {
                return null;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 $democratic_id is not named in camelCase.
    Open

        public function __construct($democratic_id = 0)
        {
            if (!$democratic_id) {
                return;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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_type is not named in camelCase.
    Open

        private function _add_vote($object_id, $object_type = 'song'): bool
        {
            if (!$this->tmp_playlist) {
                return false;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 delete_from_oid($object_id, $object_type): bool
        {
            $row_id = $this->get_uid_from_object_id($object_id, $object_type);
            if ($row_id) {
                debug_event(self::class, 'Removing Votes for ' . $object_id . ' of type ' . $object_type, 5);
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 $row_id is not named in camelCase.
    Open

        public function delete_votes($row_id): bool
        {
            $sql = "DELETE FROM `user_vote` WHERE `object_id` = ?";
            Dba::write($sql, array($row_id));
    
    
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 get_vote($object_id): int
        {
            if (parent::is_cached('democratic_vote', $object_id)) {
                return (int)(parent::get_from_cache('democratic_vote', $object_id))[0];
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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_type is not named in camelCase.
    Open

        public function delete_from_oid($object_id, $object_type): bool
        {
            $row_id = $this->get_uid_from_object_id($object_id, $object_type);
            if ($row_id) {
                debug_event(self::class, 'Removing Votes for ' . $object_id . ' of type ' . $object_type, 5);
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 $democratic_id is not named in camelCase.
    Open

        public static function delete($democratic_id): bool
        {
            $sql = "DELETE FROM `democratic` WHERE `id` = ?;";
            Dba::write($sql, array($democratic_id));
    
    
    Severity: Minor
    Found in src/Repository/Model/Democratic.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

        private function _add_vote($object_id, $object_type = 'song'): bool
        {
            if (!$this->tmp_playlist) {
                return false;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 $row_id is not named in camelCase.
    Open

        public function remove_vote($row_id): bool
        {
            $sql    = "DELETE FROM `user_vote` WHERE `object_id` = ? ";
            $params = array($row_id);
            if (Core::get_global('user')->id > 0) {
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 get_uid_from_object_id($object_id, $object_type = 'song'): ?int
        {
            if (!$object_id) {
                return null;
            }
    Severity: Minor
    Found in src/Repository/Model/Democratic.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 has_vote($object_id, $type = 'song'): bool
        {
            $params = array($type, $object_id, $this->tmp_playlist);
    
            /* Query vote table */
    Severity: Minor
    Found in src/Repository/Model/Democratic.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

    Method name "_add_vote" should not be prefixed with an underscore to indicate visibility
    Open

        private function _add_vote($object_id, $object_type = 'song'): bool

    There are no issues that match your filters.

    Category
    Status