ampache/ampache

View on GitHub
src/Repository/UserActivityRepository.php

Summary

Maintainability
C
1 day
Test Coverage

Method registerGenericEntry has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

        int $userId,
        string $action,
        string $object_type,
        int $objectId,
        int $date
Severity: Minor
Found in src/Repository/UserActivityRepository.php - About 35 mins to fix

    Function collectGarbage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function collectGarbage(
            ?string $object_type = null,
            ?int $object_id = null
        ): void {
            $types = array(
    Severity: Minor
    Found in src/Repository/UserActivityRepository.php - About 35 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 collectGarbage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    debug_event(__CLASS__, 'Garbage collect on type `' . $object_type . '` is not supported.', 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 collectGarbage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                foreach ($types as $type) {
                    Dba::write("DELETE FROM `user_activity` WHERE `object_type` = ? AND `user_activity`.`object_id` NOT IN (SELECT `$type`.`id` FROM `$type`);", array($type));
                }
                // accidental plays

    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

    Call to method read from undeclared class \Ampache\Module\System\Dba
    Open

            $db_results = Dba::read($sql, $params);
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

            Dba::write(
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

                Dba::write("DELETE FROM `user_activity` WHERE `object_type` IN ('album', 'artist') AND `action` = 'play';");
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

            Dba::write(
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

            while ($row = Dba::fetch_assoc($db_results)) {
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
    Open

            while ($row = Dba::fetch_assoc($db_results)) {
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
    Open

                    debug_event(__CLASS__, 'Garbage collect on type `' . $object_type . '` is not supported.', 1);

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

                    Dba::write("DELETE FROM `user_activity` WHERE `object_type` = ? AND `user_activity`.`object_id` NOT IN (SELECT `$type`.`id` FROM `$type`);", array($type));
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

                Dba::write("DELETE FROM `user_activity` WHERE `user` NOT IN (SELECT `id` FROM `user`);");
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method write from undeclared class \Ampache\Module\System\Dba
    Open

                    Dba::write($sql, array($object_type, $object_id));
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

    Call to method read from undeclared class \Ampache\Module\System\Dba
    Open

            $db_results = Dba::read($sql, $params);
    Severity: Critical
    Found in src/Repository/UserActivityRepository.php by phan

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

        public function getActivities(
            int $user_id,
            int $limit = 0,
            int $since = 0
        ): array {
    Severity: Major
    Found in src/Repository/UserActivityRepository.php and 1 other location - About 3 hrs to fix
    src/Repository/UserActivityRepository.php on lines 36..56

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

    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 getFriendsActivities(int $user_id, int $limit = 0, int $since = 0): array
        {
            if ($limit < 1) {
                $limit = AmpConfig::get('popular_threshold', 10);
            }
    Severity: Major
    Found in src/Repository/UserActivityRepository.php and 1 other location - About 3 hrs to fix
    src/Repository/UserActivityRepository.php on lines 61..84

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

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

        public function registerGenericEntry(
            int $userId,
            string $action,
            string $object_type,
            int $objectId,

    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 collectGarbage(
            ?string $object_type = null,
            ?int $object_id = null
        ): void {
            $types = array(

    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 getFriendsActivities(int $user_id, int $limit = 0, int $since = 0): array
        {
            if ($limit < 1) {
                $limit = AmpConfig::get('popular_threshold', 10);
            }

    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 getActivities(
            int $user_id,
            int $limit = 0,
            int $since = 0
        ): array {

    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 deleteByDate(
            int $date,
            string $action,
            int $user_id = 0
        ): void {

    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 collectGarbage(
            ?string $object_type = null,
            ?int $object_id = null
        ): void {
            $types = array(

    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

    There are no issues that match your filters.

    Category
    Status