owncloud/core

View on GitHub
apps/files_versions/lib/Storage.php

Summary

Maintainability
F
1 wk
Test Coverage

File Storage.php has 653 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 * @author Bart Visscher <bartv@thisnet.nl>
 * @author Björn Schießle <bjoern@schiessle.org>
Severity: Major
Found in apps/files_versions/lib/Storage.php - About 1 day to fix

    Function expire has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function expire($filename, $uid) {
            $config = \OC::$server->getConfig();
            $expiration = self::getExpiration();
    
            if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
    Severity: Minor
    Found in apps/files_versions/lib/Storage.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 expire has 112 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function expire($filename, $uid) {
            $config = \OC::$server->getConfig();
            $expiration = self::getExpiration();
    
            if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
    Severity: Major
    Found in apps/files_versions/lib/Storage.php - About 4 hrs to fix

      Function getVersions has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getVersions($uid, $filename) {
              $versions = [];
              if ($filename === null || $filename === '') {
                  return $versions;
              }
      Severity: Minor
      Found in apps/files_versions/lib/Storage.php - About 3 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

      Storage has 28 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Storage {
          public const DEFAULTENABLED=true;
          public const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
          public const VERSIONS_ROOT = 'files_versions/';
      
      
      Severity: Minor
      Found in apps/files_versions/lib/Storage.php - About 3 hrs to fix

        Function getAutoExpireList has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            protected static function getAutoExpireList($time, $versions) {
                $size = 0;
                $toDelete = [];  // versions we want to delete
        
                $interval = 1;
        Severity: Minor
        Found in apps/files_versions/lib/Storage.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 store has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function store($filename) {
                if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
                    // if the file gets streamed we need to remove the .part extension
                    // to get the right target
                    $ext = \pathinfo($filename, PATHINFO_EXTENSION);
        Severity: Minor
        Found in apps/files_versions/lib/Storage.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 expireOlderThanMaxForUser has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function expireOlderThanMaxForUser($uid) {
                $expiration = self::getExpiration();
                $threshold = $expiration->getMaxAgeAsTimestamp();
                $versions = self::getFileHelper()->getAllVersions($uid);
                if (!$threshold || !\array_key_exists('all', $versions)) {
        Severity: Minor
        Found in apps/files_versions/lib/Storage.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 getVersions has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getVersions($uid, $filename) {
                $versions = [];
                if ($filename === null || $filename === '') {
                    return $versions;
                }
        Severity: Minor
        Found in apps/files_versions/lib/Storage.php - About 2 hrs to fix

          Method restoreVersion has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function restoreVersion($uid, $filename, $fileToRestore, $revision) {
                  if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED) !== true) {
                      return false;
                  }
                  $users_view = new View('/'.$uid);
          Severity: Minor
          Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

            Function renameOrCopy has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function renameOrCopy($sourcePath, $targetPath, $operation) {
                    list($sourceOwner, $sourcePath) = self::getSourcePathAndUser($sourcePath);
            
                    // it was a upload of a existing file if no old path exists
                    // in this case the pre-hook already called the store method and we can
            Severity: Minor
            Found in apps/files_versions/lib/Storage.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 renameOrCopy has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function renameOrCopy($sourcePath, $targetPath, $operation) {
                    list($sourceOwner, $sourcePath) = self::getSourcePathAndUser($sourcePath);
            
                    // it was a upload of a existing file if no old path exists
                    // in this case the pre-hook already called the store method and we can
            Severity: Minor
            Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

              Method getAutoExpireList has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected static function getAutoExpireList($time, $versions) {
                      $size = 0;
                      $toDelete = [];  // versions we want to delete
              
                      $interval = 1;
              Severity: Minor
              Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

                Method store has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function store($filename) {
                        if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
                            // if the file gets streamed we need to remove the .part extension
                            // to get the right target
                            $ext = \pathinfo($filename, PATHINFO_EXTENSION);
                Severity: Minor
                Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

                  Method expireOlderThanMaxForUser has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function expireOlderThanMaxForUser($uid) {
                          $expiration = self::getExpiration();
                          $threshold = $expiration->getMaxAgeAsTimestamp();
                          $versions = self::getFileHelper()->getAllVersions($uid);
                          if (!$threshold || !\array_key_exists('all', $versions)) {
                  Severity: Minor
                  Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

                    Function isFolderEmpty has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private static function isFolderEmpty($view, $dir) {
                            if ($dir === '' || $dir === '.' || $dir === '/') {
                                // root folder won't be considered as empty
                                return false;
                            }
                    Severity: Minor
                    Found in apps/files_versions/lib/Storage.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 delete has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static function delete($path) {
                            $deletedFile = self::$deletedFiles[$path];
                            $uid = $deletedFile['uid'];
                            $filename = $deletedFile['filename'];
                    
                    
                    Severity: Minor
                    Found in apps/files_versions/lib/Storage.php - About 1 hr to fix

                      Function restoreVersion has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static function restoreVersion($uid, $filename, $fileToRestore, $revision) {
                              if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED) !== true) {
                                  return false;
                              }
                              $users_view = new View('/'.$uid);
                      Severity: Minor
                      Found in apps/files_versions/lib/Storage.php - About 55 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 delete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static function delete($path) {
                              $deletedFile = self::$deletedFiles[$path];
                              $uid = $deletedFile['uid'];
                              $filename = $deletedFile['filename'];
                      
                      
                      Severity: Minor
                      Found in apps/files_versions/lib/Storage.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 deeply nested control flow statements.
                      Open

                                              if (self::metaEnabled()) {
                                                  $versionFileInfo = $view->getFileInfo("$dir/$entryName");
                                                  if ($versionFileInfo) {
                                                      $versionMetadata = self::$metaData->getVersionMetadata($versionFileInfo);
                      
                      
                      Severity: Major
                      Found in apps/files_versions/lib/Storage.php - About 45 mins to fix

                        Function getHumanReadableTimestamp has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private static function getHumanReadableTimestamp($timestamp) {
                                $diff = \time() - $timestamp;
                        
                                if ($diff < 60) { // first minute
                                    return  $diff . " seconds ago";
                        Severity: Minor
                        Found in apps/files_versions/lib/Storage.php - About 35 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 \round($diff / 604800) . " weeks ago";
                        Severity: Major
                        Found in apps/files_versions/lib/Storage.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return \round($diff / 2419200) . " months ago";
                          Severity: Major
                          Found in apps/files_versions/lib/Storage.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return \round($diff / 29030400) . " years ago";
                            Severity: Major
                            Found in apps/files_versions/lib/Storage.php - About 30 mins to fix

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

                                  public static function postStore(string $filename) {
                                      if (self::metaEnabled()) {
                                          // we don't support versioned directories
                                          if (Filesystem::is_dir($filename) || !Filesystem::file_exists($filename)) {
                                              return false;
                              Severity: Minor
                              Found in apps/files_versions/lib/Storage.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 getExpireList has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected static function getExpireList($time, $versions, $quotaExceeded = false) {
                                      $expiration = self::getExpiration();
                              
                                      if ($expiration->shouldAutoExpire() && \count($versions) > 0) {
                                          list($toDelete, $size) = self::getAutoExpireList($time, $versions);
                              Severity: Minor
                              Found in apps/files_versions/lib/Storage.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 isPublishedVersion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected static function isPublishedVersion($view, $path) {
                                      if (self::metaEnabled()) {
                                          $versionFileInfo = $view->getFileInfo($path);
                                          if ($versionFileInfo) {
                                              $versionMetadata = self::$metaData->getVersionMetadata($versionFileInfo);
                              Severity: Minor
                              Found in apps/files_versions/lib/Storage.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