owncloud/core

View on GitHub
lib/private/legacy/api.php

Summary

Maintainability
F
4 days
Test Coverage

File api.php has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Bart Visscher <bartv@thisnet.nl>
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @author Björn Schießle <bjoern@schiessle.org>
Severity: Minor
Found in lib/private/legacy/api.php - About 4 hrs to fix

    Function mergeResponses has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function mergeResponses($responses) {
            // Sort into shipped and third-party
            $shipped = [
                'succeeded' => [],
                'failed' => [],
    Severity: Minor
    Found in lib/private/legacy/api.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

    Method mergeResponses has 73 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function mergeResponses($responses) {
            // Sort into shipped and third-party
            $shipped = [
                'succeeded' => [],
                'failed' => [],
    Severity: Major
    Found in lib/private/legacy/api.php - About 2 hrs to fix

      Function toXML has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function toXML($array, $writer) {
              foreach ($array as $k => $v) {
                  if (isset($k[0]) && ($k[0] === '@')) {
                      if (\is_array($v)) {
                          foreach ($v as $name => $value) {
      Severity: Minor
      Found in lib/private/legacy/api.php - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function loginUser has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function loginUser() {
              if (self::$isLoggedIn === true) {
                  return \OC_User::getUser();
              }
      
      
      Severity: Minor
      Found in lib/private/legacy/api.php - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function call has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function call($parameters) {
              $request = \OC::$server->getRequest();
              $method = $request->getMethod();
      
              // Prepare the request variables
      Severity: Minor
      Found in lib/private/legacy/api.php - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method call has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function call($parameters) {
              $request = \OC::$server->getRequest();
              $method = $request->getMethod();
      
              // Prepare the request variables
      Severity: Minor
      Found in lib/private/legacy/api.php - About 2 hrs to fix

        Method loginUser has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function loginUser() {
                if (self::$isLoggedIn === true) {
                    return \OC_User::getUser();
                }
        
        
        Severity: Minor
        Found in lib/private/legacy/api.php - About 1 hr to fix

          Method isAuthorised has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private static function isAuthorised($action) {
                  $level = $action['authlevel'];
                  switch ($level) {
                      case API::GUEST_AUTH:
                          // Anyone can access
          Severity: Minor
          Found in lib/private/legacy/api.php - About 1 hr to fix

            Function isAuthorised has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                private static function isAuthorised($action) {
                    $level = $action['authlevel'];
                    switch ($level) {
                        case API::GUEST_AUTH:
                            // Anyone can access
            Severity: Minor
            Found in lib/private/legacy/api.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

            Method register has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    $method,
                    $url,
                    $action,
                    $app,
                    $authLevel = API::USER_AUTH,
            Severity: Major
            Found in lib/private/legacy/api.php - About 1 hr to fix

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

                  public static function respond($result, $format='xml') {
                      $request = \OC::$server->getRequest();
              
                      // Send 401 headers if unauthorised
                      if ($result->getStatusCode() === API::RESPOND_UNAUTHORISED) {
              Severity: Minor
              Found in lib/private/legacy/api.php - About 45 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid too many return statements within this method.
              Open

                                  return false;
              Severity: Major
              Found in lib/private/legacy/api.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return false;
                Severity: Major
                Found in lib/private/legacy/api.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return false;
                  Severity: Major
                  Found in lib/private/legacy/api.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return Http::STATUS_FORBIDDEN;
                    Severity: Major
                    Found in lib/private/legacy/api.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return false;
                      Severity: Major
                      Found in lib/private/legacy/api.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $sc;
                        Severity: Major
                        Found in lib/private/legacy/api.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return Http::STATUS_BAD_REQUEST;
                          Severity: Major
                          Found in lib/private/legacy/api.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                    return true;
                            Severity: Major
                            Found in lib/private/legacy/api.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return \OC_User::getUser();
                              Severity: Major
                              Found in lib/private/legacy/api.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return Http::STATUS_OK;
                                Severity: Major
                                Found in lib/private/legacy/api.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return false;
                                  Severity: Major
                                  Found in lib/private/legacy/api.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                            return false;
                                    Severity: Major
                                    Found in lib/private/legacy/api.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return false;
                                      Severity: Major
                                      Found in lib/private/legacy/api.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                            return OC_User::isAdminUser($user);
                                        Severity: Major
                                        Found in lib/private/legacy/api.php - About 30 mins to fix

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

                                                  if (!empty($shipped['failed'])) {
                                                      // Which shipped response do we use if they all failed?
                                                      // They may have failed for different reasons (different status codes)
                                                      // Which response code should we return?
                                                      // Maybe any that are not \OCP\API::RESPOND_SERVER_ERROR
                                          Severity: Major
                                          Found in lib/private/legacy/api.php and 1 other location - About 2 hrs to fix
                                          lib/private/legacy/api.php on lines 265..277

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

                                          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

                                                  } elseif (!empty($thirdparty['failed'])) {
                                                      // Merge failed responses if more than one
                                                      $data = [];
                                                      foreach ($thirdparty['failed'] as $failure) {
                                                          $data = \array_merge_recursive($data, $failure['response']->getData());
                                          Severity: Major
                                          Found in lib/private/legacy/api.php and 1 other location - About 2 hrs to fix
                                          lib/private/legacy/api.php on lines 247..279

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

                                          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