ampache/ampache

View on GitHub
src/Plugin/AmpacheRatingMatch.php

Summary

Maintainability
D
1 day
Test Coverage

Function save_rating has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    public function save_rating($rating, $new_rating): void
    {
        if ($this->min_stars > 0 && $new_rating >= $this->min_stars) {
            if ($rating->type == 'song') {
                $song = new Song($rating->id);
Severity: Minor
Found in src/Plugin/AmpacheRatingMatch.php - About 4 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 AmpacheRatingMatch has an overall complexity of 88 which is very high. The configured complexity threshold is 50.
Open

class AmpacheRatingMatch extends AmpachePlugin implements PluginSaveMediaplayInterface
{
    public string $name        = 'RatingMatch';

    public string $categories  = 'scrobbling';
Severity: Minor
Found in src/Plugin/AmpacheRatingMatch.php by phpmd

Consider simplifying this complex logical expression.
Open

                if (
                    (
                        $play > 0 &&
                        $play_count >= $play &&
                        $skip == 0
Severity: Critical
Found in src/Plugin/AmpacheRatingMatch.php - About 2 hrs to fix

    The class AmpacheRatingMatch has 17 fields. Consider redesigning AmpacheRatingMatch to keep the number of fields under 15.
    Open

    class AmpacheRatingMatch extends AmpachePlugin implements PluginSaveMediaplayInterface
    {
        public string $name        = 'RatingMatch';
    
        public string $categories  = 'scrobbling';
    Severity: Minor
    Found in src/Plugin/AmpacheRatingMatch.php by phpmd

    TooManyFields

    Since: 0.1

    Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

    Example

    class Person {
       protected $one;
       private $two;
       private $three;
       [... many more fields ...]
    }

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

    Function save_mediaplay has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function save_mediaplay(Song $song): bool
        {
            // Only support songs
            if ($song::class !== Song::class) {
                return false;
    Severity: Minor
    Found in src/Plugin/AmpacheRatingMatch.php - About 1 hr 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 set_flag has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public function set_flag($song, $flagged): void
        {
            if ($this->match_flags > 0 && $flagged) {
                $album = new Album($song->album);
                // flag the album
    Severity: Minor
    Found in src/Plugin/AmpacheRatingMatch.php - About 1 hr 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 install has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function install(): bool
        {
            if (!Preference::insert('ratingmatch_stars', T_('Minimum star rating to match'), 0, AccessLevelEnum::USER->value, 'integer', 'plugins', $this->name)) {
                return false;
            }
    Severity: Minor
    Found in src/Plugin/AmpacheRatingMatch.php - About 1 hr 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 rule_process has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function rule_process($rule_array, $play_count, $skip_count): bool
        {
            switch (count($rule_array)) {
                case 1:
                    $play = (int) $rule_array[0];
    Severity: Minor
    Found in src/Plugin/AmpacheRatingMatch.php - About 1 hr 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 false;
    Severity: Major
    Found in src/Plugin/AmpacheRatingMatch.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return Preference::insert('ratingmatch_write_tags', T_('Save ratings to file tags when changed'), '0', AccessLevelEnum::USER->value, 'boolean', 'plugins', $this->name);
      Severity: Major
      Found in src/Plugin/AmpacheRatingMatch.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return false;
        Severity: Major
        Found in src/Plugin/AmpacheRatingMatch.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return false;
          Severity: Major
          Found in src/Plugin/AmpacheRatingMatch.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return false;
            Severity: Major
            Found in src/Plugin/AmpacheRatingMatch.php - About 30 mins to fix

              The method install() has an NPath complexity of 1944. The configured NPath complexity threshold is 200.
              Open

                  public function install(): bool
                  {
                      if (!Preference::insert('ratingmatch_stars', T_('Minimum star rating to match'), 0, AccessLevelEnum::USER->value, 'integer', 'plugins', $this->name)) {
                          return false;
                      }
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 save_mediaplay() has an NPath complexity of 11664. The configured NPath complexity threshold is 200.
              Open

                  public function save_mediaplay(Song $song): bool
                  {
                      // Only support songs
                      if ($song::class !== Song::class) {
                          return false;
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 rule_process() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
              Open

                  public function rule_process($rule_array, $play_count, $skip_count): bool
                  {
                      switch (count($rule_array)) {
                          case 1:
                              $play = (int) $rule_array[0];
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 install() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
              Open

                  public function install(): bool
                  {
                      if (!Preference::insert('ratingmatch_stars', T_('Minimum star rating to match'), 0, AccessLevelEnum::USER->value, 'integer', 'plugins', $this->name)) {
                          return false;
                      }
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 save_mediaplay() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10.
              Open

                  public function save_mediaplay(Song $song): bool
                  {
                      // Only support songs
                      if ($song::class !== Song::class) {
                          return false;
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 save_rating() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
              Open

                  public function save_rating($rating, $new_rating): void
                  {
                      if ($this->min_stars > 0 && $new_rating >= $this->min_stars) {
                          if ($rating->type == 'song') {
                              $song = new Song($rating->id);
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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

              TODO found
              Open

                          if ($rating->type == 'album') { // TODO missing album_disk
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.php by fixme

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

                  public string $name        = 'RatingMatch';
              Severity: Critical
              Found in src/Plugin/AmpacheRatingMatch.php by phan

              The parameter $new_rating is not named in camelCase.
              Open

                  public function save_rating($rating, $new_rating): void
                  {
                      if ($this->min_stars > 0 && $new_rating >= $this->min_stars) {
                          if ($rating->type == 'song') {
                              $song = new Song($rating->id);
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 $play_count is not named in camelCase.
              Open

                  public function rule_process($rule_array, $play_count, $skip_count): bool
                  {
                      switch (count($rule_array)) {
                          case 1:
                              $play = (int) $rule_array[0];
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 $rule_array is not named in camelCase.
              Open

                  public function rule_process($rule_array, $play_count, $skip_count): bool
                  {
                      switch (count($rule_array)) {
                          case 1:
                              $play = (int) $rule_array[0];
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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 $skip_count is not named in camelCase.
              Open

                  public function rule_process($rule_array, $play_count, $skip_count): bool
                  {
                      switch (count($rule_array)) {
                          case 1:
                              $play = (int) $rule_array[0];
              Severity: Minor
              Found in src/Plugin/AmpacheRatingMatch.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

              Expected 0 spaces after opening bracket; newline found
              Open

                              if (

              Expected 0 spaces after opening bracket; newline found
              Open

                              if (

              There are no issues that match your filters.

              Category
              Status