owncloud/core

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

Summary

Maintainability
F
1 wk
Test Coverage

File util.php has 889 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Adam Williamson <awilliam@redhat.com>
 * @author Andreas Fischer <bantu@owncloud.com>
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
Severity: Major
Found in lib/private/legacy/util.php - About 2 days to fix

    Function checkServer has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function checkServer(\OCP\IConfig $config) {
            $l = \OC::$server->getL10N('lib');
            $errors = [];
            $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
    
    
    Severity: Minor
    Found in lib/private/legacy/util.php - About 1 day 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

    OC_Util has 53 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class OC_Util {
        public static $scripts = [];
        public static $styles = [];
        public static $headers = [];
        private static $rootMounted = false;
    Severity: Major
    Found in lib/private/legacy/util.php - About 7 hrs to fix

      Method checkServer has 175 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function checkServer(\OCP\IConfig $config) {
              $l = \OC::$server->getL10N('lib');
              $errors = [];
              $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
      
      
      Severity: Major
      Found in lib/private/legacy/util.php - About 7 hrs to fix

        Method setupFS has 135 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function setupFS($user = '') {
                //setting up the filesystem twice can only lead to trouble
                if (self::$fsSetup) {
                    return false;
                }
        Severity: Major
        Found in lib/private/legacy/util.php - About 5 hrs to fix

          Function setupFS has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function setupFS($user = '') {
                  //setting up the filesystem twice can only lead to trouble
                  if (self::$fsSetup) {
                      return false;
                  }
          Severity: Minor
          Found in lib/private/legacy/util.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

          Function getDefaultPageUrl has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function getDefaultPageUrl() {
                  $urlGenerator = \OC::$server->getURLGenerator();
                  // Deny the redirect if the URL contains a @
                  // This prevents unvalidated redirects like ?redirect_url=:user@domain.com
                  if (isset($_REQUEST['redirect_url']) && \strpos($_REQUEST['redirect_url'], '@') === false) {
          Severity: Minor
          Found in lib/private/legacy/util.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 needUpgrade has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function needUpgrade(\OCP\IConfig $config) {
                  if ($config->getSystemValue('installed', false)) {
                      $installedVersion = $config->getSystemValue('version', '0.0.0');
                      $currentVersion = \implode('.', \OCP\Util::getVersion());
                      $versionDiff = \version_compare($currentVersion, $installedVersion);
          Severity: Minor
          Found in lib/private/legacy/util.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 copyr has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function copyr($source, \OCP\Files\Folder $target) {
                  $dir = @\opendir($source);
                  if ($dir === false) {
                      throw new NoReadAccessException('No read permission for folder ' . $source);
                  }
          Severity: Minor
          Found in lib/private/legacy/util.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 addExternalResource has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function addExternalResource($application, $prepend, $path, $type = "script") {
                  if ($type === "style") {
                      if (!\in_array($path, self::$styles)) {
                          if ($prepend === true) {
                              \array_unshift(self::$styles, $path);
          Severity: Minor
          Found in lib/private/legacy/util.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 needUpgrade has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function needUpgrade(\OCP\IConfig $config) {
                  if ($config->getSystemValue('installed', false)) {
                      $installedVersion = $config->getSystemValue('version', '0.0.0');
                      $currentVersion = \implode('.', \OCP\Util::getVersion());
                      $versionDiff = \version_compare($currentVersion, $installedVersion);
          Severity: Minor
          Found in lib/private/legacy/util.php - About 1 hr to fix

            Method copyr has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function copyr($source, \OCP\Files\Folder $target) {
                    $dir = @\opendir($source);
                    if ($dir === false) {
                        throw new NoReadAccessException('No read permission for folder ' . $source);
                    }
            Severity: Minor
            Found in lib/private/legacy/util.php - About 1 hr to fix

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

                  public static function checkDatabaseVersion() {
                      $l = \OC::$server->getL10N('lib');
                      $errors = [];
                      $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
                      if ($dbType === 'pgsql') {
              Severity: Minor
              Found in lib/private/legacy/util.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 new \OC\Files\Storage\Wrapper\PermissionsMask([
                                  'storage' => $storage,
                                  'mask' => \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE
                              ]);
              Severity: Major
              Found in lib/private/legacy/util.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

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

                      Avoid too many return statements within this method.
                      Open

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

                        Avoid too many return statements within this method.
                        Open

                                        return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
                        Severity: Major
                        Found in lib/private/legacy/util.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                              return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]);
                              Severity: Major
                              Found in lib/private/legacy/util.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

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

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

                                                              return new \OC\Files\Storage\Wrapper\ReadOnlyJail(
                                                                  [
                                                                      'storage' => $storage,
                                                                      'mask' => \OCP\Constants::PERMISSION_READ,
                                                                      'path' => 'files'
                                      Severity: Major
                                      Found in lib/private/legacy/util.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return new \OC\Files\Storage\Wrapper\Checksum(['storage' => $storage]);
                                        Severity: Major
                                        Found in lib/private/legacy/util.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                                  return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']);
                                          Severity: Major
                                          Found in lib/private/legacy/util.php - About 30 mins to fix

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

                                                public static function getUserQuota($userId) {
                                                    if ($userId instanceof IUser) {
                                                        $user = $userId;
                                                    } else {
                                                        $user = \OC::$server->getUserManager()->get($userId);
                                            Severity: Minor
                                            Found in lib/private/legacy/util.php - About 25 mins to fix

                                            Cognitive Complexity

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

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

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

                                            Further reading

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

                                                public static function isValidFileName($file) {
                                                    $trimmed = \trim($file);
                                                    if ($trimmed === '') {
                                                        return false;
                                                    }
                                            Severity: Minor
                                            Found in lib/private/legacy/util.php - About 25 mins to fix

                                            Cognitive Complexity

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

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

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

                                            Further reading

                                            There are no issues that match your filters.

                                            Category
                                            Status