owncloud/core

View on GitHub
apps/files_trashbin/lib/Trashbin.php

Summary

Maintainability
F
1 wk
Test Coverage

File Trashbin.php has 683 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Bart Visscher <bartv@thisnet.nl>
 * @author Bastien Ho <bastienho@urbancube.fr>
 * @author Björn Schießle <bjoern@schiessle.org>
Severity: Major
Found in apps/files_trashbin/lib/Trashbin.php - About 1 day to fix

    Function retainVersions has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
            if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
                $copyKeysResult = false;
    
                // Temporary
    Severity: Minor
    Found in apps/files_trashbin/lib/Trashbin.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

    Function restoreVersionsFromTrashbin has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function restoreVersionsFromTrashbin(View $view, $filename, $targetLocation) {
            if (\OCP\App::isEnabled('files_versions')) {
                $user = User::getUser();
                $rootView = new View('/');
    
    
    Severity: Minor
    Found in apps/files_trashbin/lib/Trashbin.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

    Trashbin has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Trashbin {
        /**
         * @var IURLGenerator
         */
        private $urlGenerator;
    Severity: Minor
    Found in apps/files_trashbin/lib/Trashbin.php - About 4 hrs to fix

      Function move2trash has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function move2trash($file_path) {
              // get the user for which the filesystem is setup
              $root = Filesystem::getRoot();
              list(, $user) = \explode('/', $root);
              list($owner, $ownerPath) = self::getUidAndFilename($file_path);
      Severity: Minor
      Found in apps/files_trashbin/lib/Trashbin.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 move2trash has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function move2trash($file_path) {
              // get the user for which the filesystem is setup
              $root = Filesystem::getRoot();
              list(, $user) = \explode('/', $root);
              list($owner, $ownerPath) = self::getUidAndFilename($file_path);
      Severity: Major
      Found in apps/files_trashbin/lib/Trashbin.php - About 2 hrs to fix

        Function restore has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function restore($filename, $targetLocation = null) {
                $user = User::getUser();
                $view = new View('/' . $user);
                $nameOfFile = \basename($filename);
                $dirOfFile = \dirname($filename);
        Severity: Minor
        Found in apps/files_trashbin/lib/Trashbin.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 retainVersions has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
                if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
                    $copyKeysResult = false;
        
                    // Temporary
        Severity: Major
        Found in apps/files_trashbin/lib/Trashbin.php - About 2 hrs to fix

          Method restoreVersionsFromTrashbin has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private static function restoreVersionsFromTrashbin(View $view, $filename, $targetLocation) {
                  if (\OCP\App::isEnabled('files_versions')) {
                      $user = User::getUser();
                      $rootView = new View('/');
          
          
          Severity: Major
          Found in apps/files_trashbin/lib/Trashbin.php - About 2 hrs to fix

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

                private static function deleteVersions(View $view, $file, $user) {
                    $size = 0;
                    if (\OCP\App::isEnabled('files_versions')) {
                        if ($view->is_dir('files_trashbin/versions/' . $file)) {
                            $size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
            Severity: Minor
            Found in apps/files_trashbin/lib/Trashbin.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 restore has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function restore($filename, $targetLocation = null) {
                    $user = User::getUser();
                    $view = new View('/' . $user);
                    $nameOfFile = \basename($filename);
                    $dirOfFile = \dirname($filename);
            Severity: Major
            Found in apps/files_trashbin/lib/Trashbin.php - About 2 hrs to fix

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

                  private static function copy_recursive($source, $destination, View $view) {
                      $size = 0;
                      if ($view->is_dir($source)) {
                          $view->mkdir($destination);
                          $view->touch($destination, $view->filemtime($source));
              Severity: Minor
              Found in apps/files_trashbin/lib/Trashbin.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 deleteVersions has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private static function deleteVersions(View $view, $file, $user) {
                      $size = 0;
                      if (\OCP\App::isEnabled('files_versions')) {
                          if ($view->is_dir('files_trashbin/versions/' . $file)) {
                              $size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
              Severity: Minor
              Found in apps/files_trashbin/lib/Trashbin.php - About 1 hr to fix

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

                    private static function getVersionsFromTrash($filename, $timestamp, $user) {
                        $view = new View('/' . $user . '/files_trashbin/versions');
                        $versions = [];
                
                        //force rescan of versions, local storage may not have updated the cache
                Severity: Minor
                Found in apps/files_trashbin/lib/Trashbin.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 copy_recursive has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static function copy_recursive($source, $destination, View $view) {
                        $size = 0;
                        if ($view->is_dir($source)) {
                            $view->mkdir($destination);
                            $view->touch($destination, $view->filemtime($source));
                Severity: Minor
                Found in apps/files_trashbin/lib/Trashbin.php - About 1 hr to fix

                  Method retainVersions has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
                  Severity: Minor
                  Found in apps/files_trashbin/lib/Trashbin.php - About 45 mins to fix

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

                        private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) {
                    Severity: Minor
                    Found in apps/files_trashbin/lib/Trashbin.php - About 35 mins to fix

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

                          public function resolvePrivateLink($uid, $fileId) {
                              if ($this->rootFolder->nodeExists($uid . '/files_trashbin/files/')) {
                                  $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
                                  '@phan-var \OCP\Files\Folder $baseFolder';
                                  $files = $baseFolder->getById($fileId);
                      Severity: Minor
                      Found in apps/files_trashbin/lib/Trashbin.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 isEmpty has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static function isEmpty($user) {
                              $view = new View('/' . $user . '/files_trashbin');
                              if ($view->is_dir('/files') && $dh = $view->opendir('/files')) {
                                  while ($file = \readdir($dh)) {
                                      if (!Filesystem::isIgnoredDir($file)) {
                      Severity: Minor
                      Found in apps/files_trashbin/lib/Trashbin.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

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

                                      if ($dir === '/' || $dir === '.') {
                                          $delimiter = \strrpos($filenameOnly, '.d');
                                          $timestamp = \substr($filenameOnly, $delimiter+2);
                                          $filenameOnlyWithoutTimestamp = \substr($filenameOnly, 0, $delimiter);
                                          $dirAndFilename = $filenameOnlyWithoutTimestamp;
                      Severity: Major
                      Found in apps/files_trashbin/lib/Trashbin.php and 1 other location - About 1 hr to fix
                      apps/files_trashbin/lib/Trashbin.php on lines 839..848

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

                      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

                                      if ($dir === '/' || $dir === '.') {
                                          $delimiter = \strrpos($filenameOnly, '.d');
                                          $timestamp = \substr($filenameOnly, $delimiter+2);
                                          $filenameOnlyWithoutTimestamp = \substr($filenameOnly, 0, $delimiter);
                                          $dirAndFilename = $filenameOnlyWithoutTimestamp;
                      Severity: Major
                      Found in apps/files_trashbin/lib/Trashbin.php and 1 other location - About 1 hr to fix
                      apps/files_trashbin/lib/Trashbin.php on lines 666..675

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

                      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

                              $this->eventDispatcher->addListener(
                                  'files.resolvePrivateLink',
                                  function (GenericEvent $event) {
                                      $uid = $event->getArgument('uid');
                                      $fileId = $event->getArgument('fileid');
                      Severity: Minor
                      Found in apps/files_trashbin/lib/Trashbin.php and 1 other location - About 30 mins to fix
                      apps/files_sharing/lib/Hooks.php on lines 140..152

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

                      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