owncloud/core

View on GitHub
lib/private/Files/Storage/Wrapper/Encryption.php

Summary

Maintainability
F
6 days
Test Coverage

File Encryption.php has 651 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Björn Schießle <bjoern@schiessle.org>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Lukas Reschke <lukas@statuscode.ch>
Severity: Major
Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 1 day to fix

    Function fopen has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

        public function fopen($path, $mode) {
            // check if the file is stored in the array cache, this means that we
            // copy a file over to the versions folder, in this case we don't want to
            // decrypt it
            if ($this->arrayCache->hasKey('encryption_copy_version_' . $path)) {
    Severity: Minor
    Found in lib/private/Files/Storage/Wrapper/Encryption.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

    Function copyBetweenStorage has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
            // for versions we have nothing to do, because versions should always use the
            // key from the original file. Just create a 1:1 copy and done
            if ($this->isVersion($targetInternalPath) ||
                $this->isVersion($sourceInternalPath)) {
    Severity: Minor
    Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 5 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 fopen has 103 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function fopen($path, $mode) {
            // check if the file is stored in the array cache, this means that we
            // copy a file over to the versions folder, in this case we don't want to
            // decrypt it
            if ($this->arrayCache->hasKey('encryption_copy_version_' . $path)) {
    Severity: Major
    Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 4 hrs to fix

      Encryption has 32 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Encryption extends Wrapper {
          use LocalTempFileTrait;
      
          /** @var string */
          private $mountPoint;
      Severity: Minor
      Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 4 hrs to fix

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

            public function rename($path1, $path2) {
                $renameOk = false;
                $copyKeysOk = true;  // assume keys are copied, in case we deal with versions
        
                $isVersion = $this->isVersion($path2) || $this->isVersion($path1);
        Severity: Minor
        Found in lib/private/Files/Storage/Wrapper/Encryption.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

        Method copyBetweenStorage has 69 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
                // for versions we have nothing to do, because versions should always use the
                // key from the original file. Just create a 1:1 copy and done
                if ($this->isVersion($targetInternalPath) ||
                    $this->isVersion($sourceInternalPath)) {
        Severity: Major
        Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 2 hrs to fix

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

              protected function fixUnencryptedSize($path, $size, $unencryptedSize) {
                  $headerSize = $this->getHeaderSize($path);
                  $header = $this->getHeader($path);
                  $encryptionModule = $this->getEncryptionModule($path);
          
          
          Severity: Minor
          Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 1 hr to fix

            Method rename has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function rename($path1, $path2) {
                    $renameOk = false;
                    $copyKeysOk = true;  // assume keys are copied, in case we deal with versions
            
                    $isVersion = $this->isVersion($path2) || $this->isVersion($path1);
            Severity: Minor
            Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 1 hr to fix

              Function updateEncryptedVersion has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) {
                      $isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0;
                      $cacheInformation = [
                          'encrypted' => (bool)$isEncrypted,
                      ];
              Severity: Minor
              Found in lib/private/Files/Storage/Wrapper/Encryption.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

              Function getHeader has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function getHeader($path) {
                      if (\is_resource($path)) {
                          $exists = false;
                      } else {
                          $realFile = OC_Util::stripPartialFileExtension($path);
              Severity: Minor
              Found in lib/private/Files/Storage/Wrapper/Encryption.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 __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      $parameters,
                      IManager $encryptionManager = null,
                      Util $util = null,
                      ILogger $logger = null,
                      IFile $fileHelper = null,
              Severity: Major
              Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 1 hr to fix

                Method updateEncryptedVersion has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) {
                        $isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0;
                        $cacheInformation = [
                            'encrypted' => (bool)$isEncrypted,
                        ];
                Severity: Minor
                Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 1 hr to fix

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

                      protected function fixUnencryptedSize($path, $size, $unencryptedSize) {
                          $headerSize = $this->getHeaderSize($path);
                          $header = $this->getHeader($path);
                          $encryptionModule = $this->getEncryptionModule($path);
                  
                  
                  Severity: Minor
                  Found in lib/private/Files/Storage/Wrapper/Encryption.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 filesize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function filesize($path) {
                          $fullPath = $this->getFullPath($path);
                  
                          /** @var CacheEntry $info */
                          $info = $this->getCache()->get($path);
                  Severity: Minor
                  Found in lib/private/Files/Storage/Wrapper/Encryption.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 verifyUnencryptedSize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function verifyUnencryptedSize($path, $unencryptedSize) {
                          $size = $this->storage->filesize($path);
                          $result = $unencryptedSize;
                  
                          if ($unencryptedSize < 0 ||
                  Severity: Minor
                  Found in lib/private/Files/Storage/Wrapper/Encryption.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

                  Method copyFromStorage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function copyFromStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false, $isRename = false) {
                  Severity: Minor
                  Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 35 mins to fix

                    Method copyBetweenStorage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
                    Severity: Minor
                    Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 35 mins to fix

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

                          public function getMetaData($path) {
                              $data = $this->storage->getMetaData($path);
                              if ($data === null) {
                                  return null;
                              }
                      Severity: Minor
                      Found in lib/private/Files/Storage/Wrapper/Encryption.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

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

                          public function moveFromStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true) {
                              if ($sourceStorage === $this) {
                                  return $this->rename($sourceInternalPath, $targetInternalPath);
                              }
                      
                      
                      Severity: Minor
                      Found in lib/private/Files/Storage/Wrapper/Encryption.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 $this->storage->fopen($path, $mode);
                      Severity: Major
                      Found in lib/private/Files/Storage/Wrapper/Encryption.php - About 30 mins to fix

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

                            protected function parseRawHeader($rawHeader) {
                                $result = [];
                                if (\substr($rawHeader, 0, \strlen(Util::HEADER_START)) === Util::HEADER_START) {
                                    $header = $rawHeader;
                                    $endAt = \strpos($header, Util::HEADER_END);
                        Severity: Minor
                        Found in lib/private/Files/Storage/Wrapper/Encryption.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 file_get_contents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function file_get_contents($path) {
                                if ($this->encryptionManager->isEnabled() !== false) {
                                    $encryptionModule = $this->getEncryptionModule($path);
                        
                                    if ($encryptionModule) {
                        Severity: Minor
                        Found in lib/private/Files/Storage/Wrapper/Encryption.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