ampache/ampache

View on GitHub
src/Module/Api/Method/StatsMethod.php

Summary

Maintainability
F
4 days
Test Coverage

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

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

Method stats has 203 lines of code (exceeds 200 allowed). Consider refactoring.
Open

    public static function stats(array $input, User $user): bool
    {
        if (!Api::check_parameter($input, array('type'), self::ACTION)) {
            return false;
        }
Severity: Major
Found in src/Module/Api/Method/StatsMethod.php - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                return false;
    Severity: Major
    Found in src/Module/Api/Method/StatsMethod.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/StatsMethod.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

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

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

              public static function stats(array $input, User $user): bool
              {
                  if (!Api::check_parameter($input, array('type'), self::ACTION)) {
                      return false;
                  }
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.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 stats() has 220 lines of code. Current threshold is set to 100. Avoid really long methods.
          Open

              public static function stats(array $input, User $user): bool
              {
                  if (!Api::check_parameter($input, array('type'), self::ACTION)) {
                      return false;
                  }
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phpmd

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

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

          Reduce the number of returns of this function 7, 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;
          }
          

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

              public static function stats(array $input, User $user): bool
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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

          This function "stats" has 219 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.

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

          final class StatsMethod
          {
              public const ACTION = 'stats';
          
              /**
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phpmd

          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') {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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'))) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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')) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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 "user_id" 4 times.
          Open

                  } elseif (array_key_exists('user_id', $input)) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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" 12 times.
          Open

                      Api::error('Enable: video', ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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 "username" 4 times.
          Open

                  if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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 "artist" 3 times.
          Open

                  if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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 "album" 3 times.
          Open

                  if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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')) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by sonar-php

          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 get_highest from undeclared class \Ampache\Repository\Model\Rating
          Open

                          $results = Rating::get_highest($type, $limit, $offset, $user_id);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      Api::error(sprintf('Bad Request: %s', $type), ErrorCodeEnum::BAD_REQUEST, self::ACTION, 'type', $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      $userTwo = new User((int)$input['user_id']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                              ? $user->get_recently_played($type, $limit, $offset, $newest)
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                  if (!Api::check_parameter($input, array('type'), self::ACTION)) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      Api::error('Enable: video', ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                  if (!$user instanceof User || $user->isNew()) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      Api::error(sprintf('Bad Request: %s', 'user'), ErrorCodeEnum::BAD_REQUEST, self::ACTION, 'type', $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                  $user_id = $user->id;
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      if (!$userTwo->isNew()) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

              public static function stats(array $input, User $user): bool
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  $browse = Api::getBrowse();
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      Api::empty($type, $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::albums($results, array(), $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::artists($results, array(), $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::podcast_episodes($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                          $results = Stats::get_newest($type, $limit, $offset, 0, $user_id);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::podcasts($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::playlists($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::albums($results, array(), $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::podcasts($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::podcast_episodes($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      Api::error('Enable: podcast', ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  $results = static::getAlbumRepository()->getRandom(
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::songs($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Json_Data::videos($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  $results = static::getArtistRepository()->getRandom(
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::videos($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                          Session::extend($input['auth'], 'api');
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

          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'])) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                      $user    = User::get_from_username($input['username']);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                          $results   = Stats::get_top($type, $limit, $threshold, $offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                          $results = Userflag::get_latest($type, $user_id, $limit, $offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_offset($offset);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Xml_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

          Checking instanceof against undeclared class \Ampache\Repository\Model\User
          Open

                  if (!$user instanceof User || $user->isNew()) {
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                              : Stats::get_recent($type, $limit, $offset, $newest);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                          $user    = new User($user_id);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::playlists($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::songs($results, $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  echo Xml_Data::artists($results, array(), $user);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

                                  Json_Data::set_limit($limit);
          Severity: Critical
          Found in src/Module/Api/Method/StatsMethod.php by phan

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

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

          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

                              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/StatsMethod.php and 1 other location - About 1 hr to fix
          src/Module/Api/Method/Api5/Stats5Method.php on lines 160..165

          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

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

                  if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', 'podcast_episode'))) {
                      /* HINT: Requested object string/id/type ("album", "myusername", "some song title", 1298376) */
                      Api::error(sprintf('Bad Request: %s', $type), ErrorCodeEnum::BAD_REQUEST, self::ACTION, 'type', $input['api_format']);
          
                      return false;
          Severity: Minor
          Found in src/Module/Api/Method/StatsMethod.php and 1 other location - About 40 mins to fix
          src/Module/Api/Method/ShareCreateMethod.php on lines 93..98

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

          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