ampache/ampache

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

Summary

Maintainability
C
1 day
Test Coverage

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

class TVShow_Season extends database_object implements
    library_item,
    GarbageCollectibleInterface,
    CatalogItemInterface
{
Severity: Minor
Found in src/Repository/Model/TVShow_Season.php - About 3 hrs to fix

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

    class TVShow_Season extends database_object implements
        library_item,
        GarbageCollectibleInterface,
        CatalogItemInterface
    {

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

        public static function check($tvshow, $season_number, $readonly = false): ?int
        {
            $name = $tvshow . '_' . $season_number;
            // null because we don't have any unique id like mbid for now
            if (isset(self::$_mapcache[$name]['null'])) {
    Severity: Minor
    Found in src/Repository/Model/TVShow_Season.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 remove has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function remove(): bool
        {
            $deleted = true;
            $videos  = $this->get_episodes();
            foreach ($videos as $video_id) {
    Severity: Minor
    Found in src/Repository/Model/TVShow_Season.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

    Avoid too many return statements within this method.
    Open

                return null;
    Severity: Major
    Found in src/Repository/Model/TVShow_Season.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return (int)$object_id;
      Severity: Major
      Found in src/Repository/Model/TVShow_Season.php - About 30 mins to fix

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

                } else {
                    $sql = "SELECT COUNT(`tvshow_episode`.`id`) AS `episode_count`, `video`.`catalog` AS `catalog_id` FROM `tvshow_episode` LEFT JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` WHERE `tvshow_episode`.`season` = ? GROUP BY `catalog_id`";
        
                    $db_results = Dba::read($sql, array($this->id));
                    $row        = Dba::fetch_assoc($db_results);

        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

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

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

                if ($deleted) {
                    $sql     = "DELETE FROM `tvshow_season` WHERE `id` = ?";
                    $deleted = (Dba::write($sql, array($this->id)) !== false);
                    if ($deleted) {
                        $this->getArtCleanup()->collectGarbageForObject('tvshow_season', $this->id);
        Severity: Major
        Found in src/Repository/Model/TVShow_Season.php and 1 other location - About 2 hrs to fix
        src/Repository/Model/TvShow.php on lines 503..513

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

        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 get_episodes(): array
            {
                $sql = (AmpConfig::get('catalog_disable'))
                    ? "SELECT `tvshow_episode`.`id` FROM `tvshow_episode` LEFT JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` LEFT JOIN `catalog` ON `catalog`.`id` = `video`.`catalog` WHERE `tvshow_episode`.`season`='" . Dba::escape($this->id) . "' AND `catalog`.`enabled` = '1' "
                    : "SELECT `tvshow_episode`.`id` FROM `tvshow_episode` WHERE `tvshow_episode`.`season`='" . Dba::escape($this->id) . "' ";
        Severity: Major
        Found in src/Repository/Model/TVShow_Season.php and 1 other location - About 1 hr to fix
        src/Repository/Model/TvShow.php on lines 120..134

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

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

            public static function update_tvshow($tvshow_id, $season_id)
            {
                $sql = "UPDATE `tvshow_season` SET `tvshow` = ? WHERE `id` = ?";
        
                return Dba::write($sql, array($tvshow_id, $season_id));

        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 === 'video') {
                    $episodes = $this->get_episodes();

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

            public static function check($tvshow, $season_number, $readonly = false): ?int
            {
                $name = $tvshow . '_' . $season_number;
                // null because we don't have any unique id like mbid for now
                if (isset(self::$_mapcache[$name]['null'])) {

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

            public function __construct($show_id = 0)
            {
                if (!$show_id) {
                    return;
                }

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

        class TVShow_Season extends database_object implements
            library_item,
            GarbageCollectibleInterface,
            CatalogItemInterface
        {

        CamelCaseClassName

        Since: 0.2

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

        Example

        class class_name {
        }

        Source

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

            public static function update_tvshow($tvshow_id, $season_id)
            {
                $sql = "UPDATE `tvshow_season` SET `tvshow` = ? WHERE `id` = ?";
        
                return Dba::write($sql, array($tvshow_id, $season_id));

        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

        Property name "$_mapcache" should not be prefixed with an underscore to indicate visibility
        Open

            private static $_mapcache = array();

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

            private function _get_extra_info(): array

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

        class TVShow_Season extends database_object implements

        There are no issues that match your filters.

        Category
        Status