ampache/ampache

View on GitHub
src/Module/Api/Method/Api5/Stats5Method.php

Summary

Maintainability
F
4 days
Test Coverage

Function stats has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

    public static function stats(array $input, User $user): bool
    {
        if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
            return false;
        }
Severity: Minor
Found in src/Module/Api/Method/Api5/Stats5Method.php - About 7 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

Avoid too many return statements within this method.
Open

            return false;
Severity: Major
Found in src/Module/Api/Method/Api5/Stats5Method.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return true;
    Severity: Major
    Found in src/Module/Api/Method/Api5/Stats5Method.php - About 30 mins to fix

      The method stats() has 213 lines of code. Current threshold is set to 100. Avoid really long methods.
      Open

          public static function stats(array $input, User $user): bool
          {
              if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
                  return false;
              }

      The method stats() has an NPath complexity of 201600. The configured NPath complexity threshold is 200.
      Open

          public static function stats(array $input, User $user): bool
          {
              if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
                  return false;
              }

      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 stats() has a Cyclomatic Complexity of 43. The configured cyclomatic complexity threshold is 10.
      Open

          public static function stats(array $input, User $user): bool
          {
              if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
                  return false;
              }

      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

      This function "stats" has 212 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
      Open

          public static function stats(array $input, User $user): bool

      A function that grows too large tends to aggregate too many responsibilities.

      Such functions inevitably become harder to understand and therefore harder to maintain.

      Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

      Those smaller functions will not only be easier to understand, but also probably easier to test.

      Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed.
      Open

          public static function stats(array $input, User $user): bool

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Reduce the number of returns of this function 6, down to the maximum allowed 3.
      Open

          public static function stats(array $input, User $user): bool

      Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

      Noncompliant Code Example

      With the default threshold of 3:

      function myFunction(){ // Noncompliant as there are 4 return statements
        if (condition1) {
          return true;
        } else {
          if (condition2) {
            return false;
          } else {
            return true;
          }
        }
        return false;
      }
      

      The class Stats5Method has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13.
      Open

      final class Stats5Method
      {
          public const ACTION = 'stats';
      
          /**

      CouplingBetweenObjects

      Since: 1.1.0

      A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

      Example

      class Foo {
          /**
           * @var \foo\bar\X
           */
          private $x = null;
      
          /**
           * @var \foo\bar\Y
           */
          private $y = null;
      
          /**
           * @var \foo\bar\Z
           */
          private $z = null;
      
          public function setFoo(\Foo $foo) {}
          public function setBar(\Bar $bar) {}
          public function setBaz(\Baz $baz) {}
      
          /**
           * @return \SplObjectStorage
           * @throws \OutOfRangeException
           * @throws \InvalidArgumentException
           * @throws \ErrorException
           */
          public function process(\Iterator $it) {}
      
          // ...
      }

      Source https://phpmd.org/rules/design.html#couplingbetweenobjects

      Define a constant instead of duplicating this literal "video" 4 times.
      Open

              if (!AmpConfig::get('allow_video') && $type == 'video') {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "album" 3 times.
      Open

              if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "api_format" 11 times.
      Open

                  Api5::error(T_('Enable: video'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "playlist" 3 times.
      Open

              if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "podcast_episode" 4 times.
      Open

              if (!AmpConfig::get('podcast') && ($type == 'podcast' || $type == 'podcast_episode')) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "username" 3 times.
      Open

              if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add a "case default" clause to this "switch" statement.
      Open

              switch ($type) {

      The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

      Noncompliant Code Example

      switch ($param) {  //missing default clause
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
      }
      
      switch ($param) {
        default: // default clause should be the last one
          error();
          break;
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
      }
      

      Compliant Solution

      switch ($param) {
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
        default:
          error();
          break;
      }
      

      See

      • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
      • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
      • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
      • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
      • MISRA C:2012, 16.1 - All switch statements shall be well-formed
      • MISRA C:2012, 16.4 - Every switch statement shall have a default label
      • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
      • MITRE, CWE-478 - Missing Default Case in Switch Statement
      • CERT, MSC01-C. - Strive for logical completeness
      • CERT, MSC01-CPP. - Strive for logical completeness

      Add a "case default" clause to this "switch" statement.
      Open

                      switch ($type) {

      The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

      Noncompliant Code Example

      switch ($param) {  //missing default clause
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
      }
      
      switch ($param) {
        default: // default clause should be the last one
          error();
          break;
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
      }
      

      Compliant Solution

      switch ($param) {
        case 0:
          do_something();
          break;
        case 1:
          do_something_else();
          break;
        default:
          error();
          break;
      }
      

      See

      • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
      • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
      • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
      • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
      • MISRA C:2012, 16.1 - All switch statements shall be well-formed
      • MISRA C:2012, 16.4 - Every switch statement shall have a default label
      • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
      • MITRE, CWE-478 - Missing Default Case in Switch Statement
      • CERT, MSC01-C. - Strive for logical completeness
      • CERT, MSC01-CPP. - Strive for logical completeness

      Define a constant instead of duplicating this literal "artist" 3 times.
      Open

              if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "podcast" 5 times.
      Open

              if (!AmpConfig::get('podcast') && ($type == 'podcast' || $type == 'podcast_episode')) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Call to method albums from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::albums($results, array(), $user);

      Call to method error from undeclared class \Ampache\Module\Api\Api5
      Open

                  Api5::error(T_('Enable: podcast'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method get_recently_played from undeclared class \Ampache\Repository\Model\User
      Open

                          ? $user->get_recently_played($type, $limit, $offset, $newest)

      Call to deprecated function \Ampache\Module\Api\Method\Api5\Stats5Method::getArtistRepository() defined at /code/src/Module/Api/Method/Api5/Stats5Method.php:293
      Open

                              $results = static::getArtistRepository()->getRandom(

      Call to method artists from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::artists($results, array(), $user);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method songs from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::songs($results, $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method playlists from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::playlists($results, $user);

      Reference to instance property id from undeclared class \Ampache\Repository\Model\User
      Open

              $user_id = $user->id;

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method __construct from undeclared class \Ampache\Repository\Model\User
      Open

                  $userTwo = new User($user_id);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method videos from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::videos($results, $user);

      Call to method extend from undeclared class \Ampache\Module\System\Session
      Open

                      Session::extend($input['auth'], 'api');

      Call to method podcasts from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::podcasts($results, $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method check_parameter from undeclared class \Ampache\Module\Api\Api5
      Open

              if (!Api5::check_parameter($input, array('type'), self::ACTION)) {

      Call to method empty from undeclared class \Ampache\Module\Api\Api5
      Open

                  Api5::empty($type, $input['api_format']);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method get_from_username from undeclared class \Ampache\Repository\Model\User
      Open

              if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {

      Call to method __construct from undeclared class \Ampache\Repository\Model\User
      Open

                      $user    = new User($user_id);

      Call to method podcast_episodes from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::podcast_episodes($results, $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method songs from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::songs($results, $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method podcast_episodes from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::podcast_episodes($results, $user);

      Call to method get_latest from undeclared class \Ampache\Repository\Model\Userflag
      Open

                      $results = Userflag::get_latest($type, $user_id, $limit, $offset);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method podcasts from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::podcasts($results, $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to deprecated function \Ampache\Module\Api\Method\Api5\Stats5Method::getAlbumRepository() defined at /code/src/Module/Api/Method/Api5/Stats5Method.php:283
      Open

                              $results = static::getAlbumRepository()->getRandom(

      Call to method artists from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::artists($results, array(), $user);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method albums from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              echo Xml5_Data::albums($results, array(), $user);

      Reference to instance property id from undeclared class \Ampache\Repository\Model\User
      Open

                      $results = ($user->id)

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method get_newest from undeclared class \Ampache\Module\Statistics\Stats
      Open

                      $results = Stats::get_newest($type, $limit, $offset, 0, $user_id);

      Call to method get_recent from undeclared class \Ampache\Module\Statistics\Stats
      Open

                          : Stats::get_recent($type, $limit, $offset, $newest);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method error from undeclared class \Ampache\Module\Api\Api5
      Open

                  Api5::error(T_('Enable: video'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);

      Call to method get_highest from undeclared class \Ampache\Repository\Model\Rating
      Open

                      $results = Rating::get_highest($type, $limit, $offset, $user_id);

      Parameter $user has undeclared type \Ampache\Repository\Model\User
      Open

          public static function stats(array $input, User $user): bool

      Call to method error from undeclared class \Ampache\Module\Api\Api5
      Open

                  Api5::error(sprintf(T_('Bad Request: %s'), $type), ErrorCodeEnum::BAD_REQUEST, self::ACTION, 'type', $input['api_format']);

      Call to method getBrowse from undeclared class \Ampache\Module\Api\Api
      Open

                              $browse = Api::getBrowse();

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_offset($offset);

      Call to method set_offset from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_offset($offset);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Xml5_Data
      Open

                              Xml5_Data::set_limit($limit);

      Call to method isNew from undeclared class \Ampache\Repository\Model\User
      Open

                  if (!$userTwo->isNew()) {

      Call to method get_top from undeclared class \Ampache\Module\Statistics\Stats
      Open

                      $results   = Stats::get_top($type, $limit, $threshold, $offset);

      Call to method get_from_username from undeclared class \Ampache\Repository\Model\User
      Open

                  $user    = User::get_from_username($input['username']);

      Call to method set_limit from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              Json5_Data::set_limit($limit);

      Call to method playlists from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::playlists($results, $user);

      Call to method videos from undeclared class \Ampache\Module\Api\Json5_Data
      Open

                              echo Json5_Data::videos($results, $user);

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

              switch ($type) {
                  case 'song':
                      switch ($input['api_format']) {
                          case 'json':
                              Json5_Data::set_offset($offset);
      Severity: Major
      Found in src/Module/Api/Method/Api5/Stats5Method.php and 1 other location - About 3 days to fix
      src/Module/Api/Method/StatsMethod.php on lines 189..282

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

      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

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

              if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {
                  $user    = User::get_from_username($input['username']);
                  $user_id = $user->id;
              } elseif (array_key_exists('user_id', $input)) {
                  $userTwo = new User($user_id);
      Severity: Major
      Found in src/Module/Api/Method/Api5/Stats5Method.php and 1 other location - About 2 hrs to fix
      src/Module/Api/Method/Api4/Stats4Method.php on lines 70..79

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

      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

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

                          case 'playlist':
                              $playlists = Playlist::get_playlists($user_id, '', true, true, false);
                              $searches  = Playlist::get_smartlists($user_id, '', true, true, false);
                              $results   = array_merge($playlists, $searches);
                              shuffle($results);
      Severity: Major
      Found in src/Module/Api/Method/Api5/Stats5Method.php and 1 other location - About 1 hr to fix
      src/Module/Api/Method/StatsMethod.php on lines 164..169

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

      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

      There are no issues that match your filters.

      Category
      Status