owncloud/core

View on GitHub
lib/private/Share/Share.php

Summary

Maintainability
F
1 mo
Test Coverage

File Share.php has 2250 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 * @author Bart Visscher <bartv@thisnet.nl>
 * @author Bernhard Reiter <ockham@raz.or.at>
Severity: Major
Found in lib/private/Share/Share.php - About 6 days to fix

    Function getItems has a Cognitive Complexity of 275 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getItems(
            $itemType,
            $item = null,
            $shareType = null,
            $shareWith = null,
    Severity: Minor
    Found in lib/private/Share/Share.php - About 5 days 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 shareItem has a Cognitive Complexity of 106 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
            $backend = self::getBackend($itemType);
            $l = \OC::$server->getL10N('lib');
    
            if ($backend->isShareTypeAllowed($shareType) === false) {
    Severity: Minor
    Found in lib/private/Share/Share.php - About 2 days 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 getUsersSharingFile has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
            $userManager = \OC::$server->getUserManager();
            $userObject = $userManager->get($ownerUser);
    
            if ($userObject === null) {
    Severity: Minor
    Found in lib/private/Share/Share.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

    Method getItems has 344 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function getItems(
            $itemType,
            $item = null,
            $shareType = null,
            $shareWith = null,
    Severity: Major
    Found in lib/private/Share/Share.php - About 1 day to fix

      Method shareItem has 287 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
              $backend = self::getBackend($itemType);
              $l = \OC::$server->getL10N('lib');
      
              if ($backend->isShareTypeAllowed($shareType) === false) {
      Severity: Major
      Found in lib/private/Share/Share.php - About 1 day to fix

        Method put has 210 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function put(
                $itemType,
                $itemSource,
                $shareType,
                $shareWith,
        Severity: Major
        Found in lib/private/Share/Share.php - About 1 day to fix

          Function put has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function put(
                  $itemType,
                  $itemSource,
                  $shareType,
                  $shareWith,
          Severity: Minor
          Found in lib/private/Share/Share.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

          Share has 56 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Share extends Constants {
              /** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask
               * Construct permissions for share() and setPermissions with Or (|) e.g.
               * Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
               *
          Severity: Major
          Found in lib/private/Share/Share.php - About 1 day to fix

            Function setPermissions has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
                    $l = \OC::$server->getL10N('lib');
                    $connection = \OC::$server->getDatabaseConnection();
            
                    $intArrayToLiteralArray = function ($intArray, $eb) {
            Severity: Minor
            Found in lib/private/Share/Share.php - About 6 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 getUsersSharingFile has 169 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
                    $userManager = \OC::$server->getUserManager();
                    $userObject = $userManager->get($ownerUser);
            
                    if ($userObject === null) {
            Severity: Major
            Found in lib/private/Share/Share.php - About 6 hrs to fix

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

                  private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
                      $backend = self::getBackend($itemType);
              
                      $l = \OC::$server->getL10N('lib');
                      $result = [];
              Severity: Minor
              Found in lib/private/Share/Share.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 setPermissions has 133 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
                      $l = \OC::$server->getL10N('lib');
                      $connection = \OC::$server->getDatabaseConnection();
              
                      $intArrayToLiteralArray = function ($intArray, $eb) {
              Severity: Major
              Found in lib/private/Share/Share.php - About 5 hrs to fix

                Function getItemSharedWithUser has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
                        $shares = [];
                        $fileDependent = false;
                
                        $where = 'WHERE';
                Severity: Minor
                Found in lib/private/Share/Share.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 unshareFromSelf has 83 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function unshareFromSelf($itemType, $itemOrigin, $originIsSource = false) {
                        $originType = ($originIsSource) ? 'source' : 'target';
                        $uid = \OCP\User::getUser();
                
                        if ($itemType === 'file' || $itemType === 'folder') {
                Severity: Major
                Found in lib/private/Share/Share.php - About 3 hrs to fix

                  Function unshareFromSelf has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function unshareFromSelf($itemType, $itemOrigin, $originIsSource = false) {
                          $originType = ($originIsSource) ? 'source' : 'target';
                          $uid = \OCP\User::getUser();
                  
                          if ($itemType === 'file' || $itemType === 'folder') {
                  Severity: Minor
                  Found in lib/private/Share/Share.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 checkReshare has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
                          $backend = self::getBackend($itemType);
                  
                          $l = \OC::$server->getL10N('lib');
                          $result = [];
                  Severity: Major
                  Found in lib/private/Share/Share.php - About 3 hrs to fix

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

                        public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
                            $shares = [];
                            $fileDependent = false;
                    
                            $where = 'WHERE';
                    Severity: Major
                    Found in lib/private/Share/Share.php - About 2 hrs to fix

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

                          private static function createSelectStatement($format, $fileDependent, $uidOwner = null) {
                              $select = '*';
                              if ($format == self::FORMAT_STATUSES) {
                                  if ($fileDependent) {
                                      $select = '`*PREFIX*share`.`id`, `*PREFIX*share`.`parent`, `share_type`, `path`, `storage`, '
                      Severity: Minor
                      Found in lib/private/Share/Share.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 formatResult has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null) {
                              if ($format === self::FORMAT_NONE) {
                                  return $items;
                              } elseif ($format === self::FORMAT_STATUSES) {
                                  $statuses = [];
                      Severity: Minor
                      Found in lib/private/Share/Share.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 groupItems has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected static function groupItems($items, $itemType) {
                              $fileSharing = ($itemType === 'file' || $itemType === 'folder') ? true : false;
                      
                              $result = [];
                      
                      
                      Severity: Minor
                      Found in lib/private/Share/Share.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 createSelectStatement has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private static function createSelectStatement($format, $fileDependent, $uidOwner = null) {
                              $select = '*';
                              if ($format == self::FORMAT_STATUSES) {
                                  if ($fileDependent) {
                                      $select = '`*PREFIX*share`.`id`, `*PREFIX*share`.`parent`, `share_type`, `path`, `storage`, '
                      Severity: Minor
                      Found in lib/private/Share/Share.php - About 1 hr to fix

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

                            public static function getSharedItemsOwners($user, $type, $includeCollections = false, $includeOwner = false) {
                                // First, we find out if $type is part of a collection (and if that collection is part of
                                // another one and so on).
                                $collectionTypes = [];
                                if (!$includeCollections || !$collectionTypes = self::getCollectionItemTypes($type)) {
                        Severity: Minor
                        Found in lib/private/Share/Share.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 getItems has 11 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                                $itemType,
                                $item = null,
                                $shareType = null,
                                $shareWith = null,
                                $uidOwner = null,
                        Severity: Major
                        Found in lib/private/Share/Share.php - About 1 hr to fix

                          Method registerBackend has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
                                  if (self::isEnabled()) {
                                      if (!isset(self::$backendTypes[$itemType])) {
                                          self::$backendTypes[$itemType] = [
                                              'class' => $class,
                          Severity: Minor
                          Found in lib/private/Share/Share.php - About 1 hr to fix

                            Method put has 10 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                    $itemType,
                                    $itemSource,
                                    $shareType,
                                    $shareWith,
                                    $uidOwner,
                            Severity: Major
                            Found in lib/private/Share/Share.php - About 1 hr to fix

                              Method validateExpireDate has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) {
                                      $l = \OC::$server->getL10N('lib');
                                      $date = new \DateTime($expireDate);
                                      $today = new \DateTime('now');
                              
                              
                              Severity: Minor
                              Found in lib/private/Share/Share.php - About 1 hr to fix

                                Method setExpirationDate has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
                                        $user = \OC_User::getUser();
                                        $l = \OC::$server->getL10N('lib');
                                
                                        if ($date == '') {
                                Severity: Minor
                                Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                      private static function transformDBResults(&$row) {
                                          if (isset($row['id'])) {
                                              $row['id'] = (int) $row['id'];
                                          }
                                          if (isset($row['share_type'])) {
                                  Severity: Minor
                                  Found in lib/private/Share/Share.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 transformDBResults has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      private static function transformDBResults(&$row) {
                                          if (isset($row['id'])) {
                                              $row['id'] = (int) $row['id'];
                                          }
                                          if (isset($row['share_type'])) {
                                  Severity: Minor
                                  Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                        protected static function unshareItem(array $item, $newParent = null) {
                                            $shareType = (int)$item['share_type'];
                                            $shareWith = null;
                                            if ($shareType !== \OCP\Share::SHARE_TYPE_LINK) {
                                                $shareWith = $item['share_with'];
                                    Severity: Minor
                                    Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                          public static function getSharedItemsOwners($user, $type, $includeCollections = false, $includeOwner = false) {
                                              // First, we find out if $type is part of a collection (and if that collection is part of
                                              // another one and so on).
                                              $collectionTypes = [];
                                              if (!$includeCollections || !$collectionTypes = self::getCollectionItemTypes($type)) {
                                      Severity: Minor
                                      Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                            public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
                                        Severity: Major
                                        Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                              private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
                                          Severity: Major
                                          Found in lib/private/Share/Share.php - About 1 hr to fix

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

                                                protected static function expireItem(array $item) {
                                                    $result = false;
                                            
                                                    // only use default expiration date for link shares
                                                    if ((int) $item['share_type'] === self::SHARE_TYPE_LINK) {
                                            Severity: Minor
                                            Found in lib/private/Share/Share.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

                                            Avoid deeply nested control flow statements.
                                            Open

                                                                    if ($items[$id]['share_type'] != self::SHARE_TYPE_GROUP) {
                                                                        $items[$id]['share_type'] = self::SHARE_TYPE_GROUP;
                                                                        $items[$id]['share_with'] = $row['share_with'];
                                                                    }
                                            Severity: Major
                                            Found in lib/private/Share/Share.php - About 45 mins to fix

                                              Avoid deeply nested control flow statements.
                                              Open

                                                                      if (~(int)$items[$id]['permissions'] & \OCP\Constants::PERMISSION_SHARE
                                                                          && (int)$row['permissions'] & \OCP\Constants::PERMISSION_SHARE) {
                                                                          $items[$row['id']] = $items[$id];
                                                                          $switchedItems[$id] = $row['id'];
                                                                          unset($items[$id]);
                                              Severity: Major
                                              Found in lib/private/Share/Share.php - About 45 mins to fix

                                                Avoid deeply nested control flow statements.
                                                Open

                                                                        if ($item['permissions'] & ~$permissions) {
                                                                            // Add to list of items that need permissions removed
                                                                            $ids[] = $item['id'];
                                                                            $parents[] = $item['id'];
                                                                        }
                                                Severity: Major
                                                Found in lib/private/Share/Share.php - About 45 mins to fix

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

                                                      public static function getBackend($itemType) {
                                                          $l = \OC::$server->getL10N('lib');
                                                          if (isset(self::$backends[$itemType])) {
                                                              return self::$backends[$itemType];
                                                          } elseif (isset(self::$backendTypes[$itemType]['class'])) {
                                                  Severity: Minor
                                                  Found in lib/private/Share/Share.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 getItemsSharedWithUser has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                          $itemType,
                                                          $user,
                                                          $format = self::FORMAT_NONE,
                                                          $parameters = null,
                                                          $limit = -1,
                                                  Severity: Minor
                                                  Found in lib/private/Share/Share.php - About 45 mins to fix

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

                                                            $itemType,
                                                            $itemSource,
                                                            $format = self::FORMAT_NONE,
                                                            $parameters = null,
                                                            $includeCollections = false,
                                                    Severity: Minor
                                                    Found in lib/private/Share/Share.php - About 45 mins to fix

                                                      Consider simplifying this complex logical expression.
                                                      Open

                                                                      if (($fileSharing && $item['file_source'] === $r['file_source'] && $item['file_target'] === $r['file_target']) ||
                                                                          (!$fileSharing && $item['item_source'] === $r['item_source'] && $item['item_target'] === $r['item_target'])) {
                                                                          // add the first item to the list of grouped shares
                                                                          if (!isset($result[$key]['grouped'])) {
                                                                              $result[$key]['grouped'][] = $result[$key];
                                                      Severity: Major
                                                      Found in lib/private/Share/Share.php - About 40 mins to fix

                                                        Consider simplifying this complex logical expression.
                                                        Open

                                                                        if ($includeCollections && $collectionTypes && $row['item_type'] !== 'folder' && \in_array($row['item_type'], $collectionTypes)) {
                                                                            if (($collectionBackend = self::getBackend($row['item_type']))
                                                                                && $collectionBackend instanceof \OCP\Share_Backend_Collection) {
                                                                                // Collections can be inside collections, check if the item is a collection
                                                                                if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) {
                                                        Severity: Major
                                                        Found in lib/private/Share/Share.php - About 40 mins to fix

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

                                                                  $itemType,
                                                                  $format = self::FORMAT_NONE,
                                                                  $parameters = null,
                                                                  $limit = -1,
                                                                  $includeCollections = false
                                                          Severity: Minor
                                                          Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                    $itemType,
                                                                    $itemSource,
                                                                    $format = self::FORMAT_NONE,
                                                                    $parameters = null,
                                                                    $includeCollections = false
                                                            Severity: Minor
                                                            Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                  public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) {
                                                              Severity: Minor
                                                              Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                    public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
                                                                Severity: Minor
                                                                Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                      public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
                                                                  Severity: Minor
                                                                  Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                        private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null) {
                                                                    Severity: Minor
                                                                    Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                          public static function setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status) {
                                                                      Severity: Minor
                                                                      Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                IUserSession $userSession,
                                                                                IDBConnection $connection,
                                                                                IConfig $config,
                                                                                $shareId,
                                                                                $password
                                                                        Severity: Minor
                                                                        Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                  $itemType,
                                                                                  $itemTarget,
                                                                                  $format = self::FORMAT_NONE,
                                                                                  $parameters = null,
                                                                                  $includeCollections = false
                                                                          Severity: Minor
                                                                          Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
                                                                            Severity: Minor
                                                                            Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                  private static function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner) {
                                                                              Severity: Minor
                                                                              Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                    public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
                                                                                Severity: Minor
                                                                                Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                          $itemType,
                                                                                          $format = self::FORMAT_NONE,
                                                                                          $parameters = null,
                                                                                          $limit = -1,
                                                                                          $includeCollections = false
                                                                                  Severity: Minor
                                                                                  Found in lib/private/Share/Share.php - About 35 mins to fix

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

                                                                                        private static function getCollectionItemTypes($itemType) {
                                                                                            $collectionTypes = [$itemType];
                                                                                            foreach (self::$backendTypes as $type => $backend) {
                                                                                                if (\in_array($backend['collectionOf'], $collectionTypes)) {
                                                                                                    $collectionTypes[] = $type;
                                                                                    Severity: Minor
                                                                                    Found in lib/private/Share/Share.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 getUsersItemShared has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
                                                                                            $users = [];
                                                                                            $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections, false, $checkExpireDate);
                                                                                            if ($items) {
                                                                                                foreach ($items as $item) {
                                                                                    Severity: Minor
                                                                                    Found in lib/private/Share/Share.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 unshare has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) {
                                                                                            // check if it is a valid itemType
                                                                                            self::getBackend($itemType);
                                                                                    
                                                                                            $items = self::getItemSharedWithUser($itemType, $itemSource, $shareWith, $owner, $shareType);
                                                                                    Severity: Minor
                                                                                    Found in lib/private/Share/Share.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 resolveReShare has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        public static function resolveReShare($linkItem) {
                                                                                            if (isset($linkItem['parent'])) {
                                                                                                $parent = $linkItem['parent'];
                                                                                                while (isset($parent)) {
                                                                                                    $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `id` = ?', 1);
                                                                                    Severity: Minor
                                                                                    Found in lib/private/Share/Share.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 self::formatResult($items, $column, $backend, $format, $parameters);
                                                                                    Severity: Major
                                                                                    Found in lib/private/Share/Share.php - About 30 mins to fix

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                              return [];
                                                                                      Severity: Major
                                                                                      Found in lib/private/Share/Share.php - About 30 mins to fix

                                                                                        Avoid too many return statements within this method.
                                                                                        Open

                                                                                                    return self::formatResult($collectionItems, $column, $backend, $format, $parameters);
                                                                                        Severity: Major
                                                                                        Found in lib/private/Share/Share.php - About 30 mins to fix

                                                                                          Avoid too many return statements within this method.
                                                                                          Open

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

                                                                                            Avoid too many return statements within this method.
                                                                                            Open

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

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

                                                                                                      return $result ? true : false;
                                                                                              Severity: Major
                                                                                              Found in lib/private/Share/Share.php - About 30 mins to fix

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

                                                                                                                return \reset($collectionItems);
                                                                                                Severity: Major
                                                                                                Found in lib/private/Share/Share.php - About 30 mins to fix

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

                                                                                                      public static function checkPasswordProtectedShare(array $linkItem) {
                                                                                                          if (!isset($linkItem['share_with'])) {
                                                                                                              return true;
                                                                                                          }
                                                                                                          if (!isset($linkItem['share_type'])) {
                                                                                                  Severity: Minor
                                                                                                  Found in lib/private/Share/Share.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 registerBackend has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                  Open

                                                                                                      public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
                                                                                                          if (self::isEnabled()) {
                                                                                                              if (!isset(self::$backendTypes[$itemType])) {
                                                                                                                  self::$backendTypes[$itemType] = [
                                                                                                                      'class' => $class,
                                                                                                  Severity: Minor
                                                                                                  Found in lib/private/Share/Share.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 validateExpireDate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                  Open

                                                                                                      private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) {
                                                                                                          $l = \OC::$server->getL10N('lib');
                                                                                                          $date = new \DateTime($expireDate);
                                                                                                          $today = new \DateTime('now');
                                                                                                  
                                                                                                  
                                                                                                  Severity: Minor
                                                                                                  Found in lib/private/Share/Share.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

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

                                                                                                              if (!$publicShare) {
                                                                                                                  $query = \OC_DB::prepare(
                                                                                                                      '
                                                                                                                      SELECT `share_with`
                                                                                                                      FROM `*PREFIX*share`
                                                                                                  Severity: Major
                                                                                                  Found in lib/private/Share/Share.php and 1 other location - About 1 hr to fix
                                                                                                  lib/private/Share/Share.php on lines 277..295

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

                                                                                                  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

                                                                                                              if (!$remoteShare) {
                                                                                                                  $query = \OC_DB::prepare(
                                                                                                                      '
                                                                                                                      SELECT `share_with`
                                                                                                                      FROM `*PREFIX*share`
                                                                                                  Severity: Major
                                                                                                  Found in lib/private/Share/Share.php and 1 other location - About 1 hr to fix
                                                                                                  lib/private/Share/Share.php on lines 256..274

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

                                                                                                  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

                                                                                                              if ($checkExists = self::getItems(
                                                                                                                  $itemType,
                                                                                                                  $itemSource,
                                                                                                                  self::SHARE_TYPE_USER,
                                                                                                                  $shareWith,
                                                                                                  Severity: Minor
                                                                                                  Found in lib/private/Share/Share.php and 1 other location - About 55 mins to fix
                                                                                                  lib/private/Share/Share.php on lines 846..867

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

                                                                                                  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

                                                                                                              if ($checkExists = self::getItems(
                                                                                                                  $itemType,
                                                                                                                  $itemSource,
                                                                                                                  self::$shareTypeUserAndGroups,
                                                                                                                  $shareWith,
                                                                                                  Severity: Minor
                                                                                                  Found in lib/private/Share/Share.php and 1 other location - About 55 mins to fix
                                                                                                  lib/private/Share/Share.php on lines 868..889

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

                                                                                                  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