ampache/ampache

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

Summary

Maintainability
D
3 days
Test Coverage

Tag has 45 functions (exceeds 20 allowed). Consider refactoring.
Open

class Tag extends database_object implements library_item, GarbageCollectibleInterface
{
    protected const DB_TABLENAME = 'tag';

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

    File Tag.php has 640 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=0);
    
    /**
    Severity: Major
    Found in src/Repository/Model/Tag.php - About 5 hrs to fix

      Function update_tag_list has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
          {
              if (!strlen((string) $tags_comma) > 0) {
                  return self::remove_all_map($object_type, $object_id);
              }
      Severity: Minor
      Found in src/Repository/Model/Tag.php - About 3 hrs 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 Tag has 22 public methods. Consider refactoring Tag to keep number of public methods under 10.
      Open

      class Tag extends database_object implements library_item, GarbageCollectibleInterface
      {
          protected const DB_TABLENAME = 'tag';
      
          public int $id = 0;
      Severity: Minor
      Found in src/Repository/Model/Tag.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

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

      class Tag extends database_object implements library_item, GarbageCollectibleInterface
      {
          protected const DB_TABLENAME = 'tag';
      
          public int $id = 0;
      Severity: Minor
      Found in src/Repository/Model/Tag.php by phpmd

      Function update has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function update(array $data)
          {
              if (!strlen((string)$data['name'])) {
                  return false;
              }
      Severity: Minor
      Found in src/Repository/Model/Tag.php - About 2 hrs 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 Tag has 49 public methods and attributes. Consider reducing the number of public items to less than 45.
      Open

      class Tag extends database_object implements library_item, GarbageCollectibleInterface
      {
          protected const DB_TABLENAME = 'tag';
      
          public int $id = 0;
      Severity: Minor
      Found in src/Repository/Model/Tag.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 clean_to_existing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function clean_to_existing($tags)
          {
              if (is_array($tags)) {
                  $taglist = $tags;
              } else {
      Severity: Minor
      Found in src/Repository/Model/Tag.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 add has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function add($type, $object_id, $value, $user = true)
          {
              if (!InterfaceImplementationChecker::is_library_item($type)) {
                  return false;
              }
      Severity: Minor
      Found in src/Repository/Model/Tag.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 get_tag_objects has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_tag_objects($type, $tag_id, $count = 0, $offset = 0): array
          {
              if (!InterfaceImplementationChecker::is_library_item($type)) {
                  return array();
              }
      Severity: Minor
      Found in src/Repository/Model/Tag.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

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

          public static function get_tags($type = '', $limit = 0, $order = 'count'): array
          {
              if (parent::is_cached('tags_list', 'no_name')) {
                  //debug_event(self::class, 'Tags list found into cache memory!', 5);
                  return parent::get_from_cache('tags_list', 'no_name');
      Severity: Minor
      Found in src/Repository/Model/Tag.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

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

          public static function add_tag_map($type, $object_id, $tag_id, $user = true)
          {
              if ($user === true) {
                  $uid = (int)(Core::get_global('user')->id);
              } else {
      Severity: Minor
      Found in src/Repository/Model/Tag.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

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

          public static function get_tag_ids($type, $count = '', $offset = ''): array
          {
              if (!InterfaceImplementationChecker::is_library_item($type)) {
                  return array();
              }
      Severity: Minor
      Found in src/Repository/Model/Tag.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 (int)$map_id;
      Severity: Major
      Found in src/Repository/Model/Tag.php - About 30 mins to fix

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

            public static function build_map_cache($type, $ids): bool
            {
                if (empty($ids)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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

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

            public static function get_display($tags, $link = false, $filter_type = ''): string
            {
                //debug_event(self::class, 'Get display tags called...', 5);
                if (!is_array($tags)) {
                    return '';
        Severity: Minor
        Found in src/Repository/Model/Tag.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 update() has an NPath complexity of 640. The configured NPath complexity threshold is 200.
        Open

            public function update(array $data)
            {
                if (!strlen((string)$data['name'])) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        NPathComplexity

        Since: 0.1

        The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

        Example

        class Foo {
            function bar() {
                // lots of complicated code
            }
        }

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

        The class Tag has 1042 lines of code. Current threshold is 1000. Avoid really long classes.
        Open

        class Tag extends database_object implements library_item, GarbageCollectibleInterface
        {
            protected const DB_TABLENAME = 'tag';
        
            public int $id = 0;
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        The method update_tag_list() has an NPath complexity of 888. The configured NPath complexity threshold is 200.
        Open

            public static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
            {
                if (!strlen((string) $tags_comma) > 0) {
                    return self::remove_all_map($object_type, $object_id);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        NPathComplexity

        Since: 0.1

        The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

        Example

        class Foo {
            function bar() {
                // lots of complicated code
            }
        }

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

        The method update() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
        Open

            public function update(array $data)
            {
                if (!strlen((string)$data['name'])) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

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

        The method update_tag_list() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
        Open

            public static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
            {
                if (!strlen((string) $tags_comma) > 0) {
                    return self::remove_all_map($object_type, $object_id);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

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

        The method get_tags() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
        Open

            public static function get_tags($type = '', $limit = 0, $order = 'count'): array
            {
                if (parent::is_cached('tags_list', 'no_name')) {
                    //debug_event(self::class, 'Tags list found into cache memory!', 5);
                    return parent::get_from_cache('tags_list', 'no_name');
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

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

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

            public static function get_merged_count(): int
            {
                $results    = 0;
                $sql        = "SELECT COUNT(DISTINCT `tag_id`) AS `tag_count` FROM `tag_merge`;";
                $db_results = Dba::read($sql);
        Severity: Minor
        Found in src/Repository/Model/Tag.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 add uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $uid = (int)($user);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 update uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                        } else {
                            $sql = "UPDATE `tag` SET `is_hidden` = 1 WHERE `tag`.`id` = ? ";
                            Dba::write($sql, array($this->id));
                        }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 '215', column '14').
        Open

            public static function add($type, $object_id, $value, $user = true)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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

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

            public static function add($type, $object_id, $value, $user = true)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 clean_to_existing uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $filterfolk  = str_replace('Folk, World, & Country', 'Folk World & Country', $tags);
                    $filterunder = str_replace('_', ', ', $filterfolk);
                    $filter      = str_replace(';', ', ', $filterunder);
                    $filter_list = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $filter);
        Severity: Minor
        Found in src/Repository/Model/Tag.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 add_tag_map uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $uid = (int)($user);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 get_tags uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $type_sql = (!empty($type))
                        ? "AND `tag_map`.`object_type` = '" . (string)scrub_in($type) . "'"
                        : "";
        
        
        Severity: Minor
        Found in src/Repository/Model/Tag.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 unused local variables such as '$ctid'.
        Open

                foreach ($ctags as $ctid => $ctv) {
        Severity: Minor
        Found in src/Repository/Model/Tag.php by phpmd

        UnusedLocalVariable

        Since: 0.2

        Detects when a local variable is declared and/or assigned, but not used.

        Example

        class Foo {
            public function doSomething()
            {
                $i = 5; // Unused
            }
        }

        Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

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

            public static function build_cache($ids): bool
            {
                if (empty($ids)) {
                    return false;
                }
        Severity: Major
        Found in src/Repository/Model/Tag.php and 3 other locations - About 1 hr to fix
        src/Repository/Model/Playlist.php on lines 91..105
        src/Repository/Model/Useractivity.php on lines 70..85
        src/Repository/Model/Video.php on lines 208..223

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

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

            public static function add($type, $object_id, $value, $user = true)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $tag_id is not named in camelCase.
        Open

            public function __construct($tag_id = 0)
            {
                if (!$tag_id) {
                    return;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function add_tag_map($type, $object_id, $tag_id, $user = true)
            {
                if ($user === true) {
                    $uid = (int)(Core::get_global('user')->id);
                } else {
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $merge_to is not named in camelCase.
        Open

            public function merge($merge_to, $is_persistent): void
            {
                if ($this->id != $merge_to) {
                    debug_event(self::class, 'Merging tag ' . $this->id . ' into ' . $merge_to . ')...', 5);
        
        
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $is_persistent is not named in camelCase.
        Open

            public function merge($merge_to, $is_persistent): void
            {
                if ($this->id != $merge_to) {
                    debug_event(self::class, 'Merging tag ' . $this->id . ' into ' . $merge_to . ')...', 5);
        
        
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $tag_id is not named in camelCase.
        Open

            public static function add_tag_map($type, $object_id, $tag_id, $user = true)
            {
                if ($user === true) {
                    $uid = (int)(Core::get_global('user')->id);
                } else {
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function tag_map_exists($type, $object_id, $tag_id, $user)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    debug_event(__CLASS__, 'Requested type is not a library item.', 3);
        
        
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function remove_all_map($object_type, $object_id): bool
            {
                if (!InterfaceImplementationChecker::is_library_item($object_type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $old_object_id is not named in camelCase.
        Open

            public static function migrate($object_type, $old_object_id, $new_object_id)
            {
                $sql = "UPDATE IGNORE `tag_map` SET `object_id` = ? WHERE `object_type` = ? AND `object_id` = ?";
        
                return Dba::write($sql, array($new_object_id, $object_type, $old_object_id));
        Severity: Minor
        Found in src/Repository/Model/Tag.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/Tag.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 $filter_type is not named in camelCase.
        Open

            public function get_medias(?string $filter_type = null): array
            {
                $medias = array();
                if ($filter_type) {
                    $ids = self::get_tag_objects($filter_type, $this->id);
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
            {
                if (!strlen((string) $tags_comma) > 0) {
                    return self::remove_all_map($object_type, $object_id);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function get_object_tags($type, $object_id = null)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function migrate($object_type, $old_object_id, $new_object_id)
            {
                $sql = "UPDATE IGNORE `tag_map` SET `object_id` = ? WHERE `object_type` = ? AND `object_id` = ?";
        
                return Dba::write($sql, array($new_object_id, $object_type, $old_object_id));
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
            {
                if (!strlen((string) $tags_comma) > 0) {
                    return self::remove_all_map($object_type, $object_id);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 remove_map($type, $object_id, $user = true): bool
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function remove_all_map($object_type, $object_id): bool
            {
                if (!InterfaceImplementationChecker::is_library_item($object_type)) {
                    return false;
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $tag_id is not named in camelCase.
        Open

            public static function tag_map_exists($type, $object_id, $tag_id, $user)
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    debug_event(__CLASS__, 'Requested type is not a library item.', 3);
        
        
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $new_object_id is not named in camelCase.
        Open

            public static function migrate($object_type, $old_object_id, $new_object_id)
            {
                $sql = "UPDATE IGNORE `tag_map` SET `object_id` = ? WHERE `object_type` = ? AND `object_id` = ?";
        
                return Dba::write($sql, array($new_object_id, $object_type, $old_object_id));
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $tags_comma is not named in camelCase.
        Open

            public static function update_tag_list($tags_comma, $object_type, $object_id, $overwrite): bool
            {
                if (!strlen((string) $tags_comma) > 0) {
                    return self::remove_all_map($object_type, $object_id);
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 count($type = '', $user_id = 0): array
            {
                $params = array($this->id);
        
                $filter_sql = "";
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function get_display($tags, $link = false, $filter_type = ''): string
            {
                //debug_event(self::class, 'Get display tags called...', 5);
                if (!is_array($tags)) {
                    return '';
        Severity: Minor
        Found in src/Repository/Model/Tag.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 static function get_top_tags($type, $object_id, $limit = 10): array
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return array();
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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 $tag_id is not named in camelCase.
        Open

            public static function get_tag_objects($type, $tag_id, $count = 0, $offset = 0): array
            {
                if (!InterfaceImplementationChecker::is_library_item($type)) {
                    return array();
                }
        Severity: Minor
        Found in src/Repository/Model/Tag.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

        There are no issues that match your filters.

        Category
        Status