owncloud/core

View on GitHub
apps/federatedfilesharing/lib/FederatedShareProvider.php

Summary

Maintainability
F
5 days
Test Coverage

File FederatedShareProvider.php has 697 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Björn Schießle <bjoern@schiessle.org>
 * @author Robin Appelman <icewind@owncloud.com>
 * @author Roeland Jago Douma <rullzer@owncloud.com>
Severity: Major
Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 day to fix

    FederatedShareProvider has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FederatedShareProvider implements IShareProvider {
        public const SHARE_TYPE_REMOTE = 6;
    
        /** @var IDBConnection */
        private $dbConnection;
    Severity: Minor
    Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 5 hrs to fix

      Method createFederatedShare has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function createFederatedShare(IShare $share) {
              $token = $this->tokenHandler->generateToken();
              $shareId = $this->addShareToDB(
                  $share->getNodeId(),
                  $share->getNodeType(),
      Severity: Major
      Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 2 hrs to fix

        Method create has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function create(IShare $share) {
                $shareWith = $share->getSharedWith();
                $itemSource = $share->getNodeId();
                $itemType = $share->getNodeType();
                $permissions = $share->getPermissions();
        Severity: Major
        Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 2 hrs to fix

          Method getSharesBy has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
                  $qb = $this->dbConnection->getQueryBuilder();
                  $qb->select('*')
                      ->from($this->shareTable);
          
          
          Severity: Minor
          Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

            Method getAllSharesBy has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getAllSharesBy($userId, $shareTypes, $nodeIDs, $reshares) {
                    $shares = [];
            
                    $qb = $this->dbConnection->getQueryBuilder();
                    $qb->select('*')
            Severity: Minor
            Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

              Method unshare has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function unshare($remoteId, $shareToken) {
                      $query = $this->dbConnection->getQueryBuilder();
                      $query->select('*')->from($this->externalShareTable)
                          ->where(
                              $query->expr()->eq(
              Severity: Minor
              Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

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

                        IDBConnection $connection,
                        EventDispatcherInterface $eventDispatcher,
                        AddressHandler $addressHandler,
                        Notifications $notifications,
                        TokenHandler $tokenHandler,
                Severity: Major
                Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

                  Function create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function create(IShare $share) {
                          $shareWith = $share->getSharedWith();
                          $itemSource = $share->getNodeId();
                          $itemType = $share->getNodeType();
                          $permissions = $share->getPermissions();
                  Severity: Minor
                  Found in apps/federatedfilesharing/lib/FederatedShareProvider.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 createShareObject has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function createShareObject($data) {
                          $share = new Share($this->rootFolder, $this->userManager);
                          $share->setId($data['id'])
                              ->setShareType((int)$data['share_type'])
                              ->setPermissions((int)$data['permissions'])
                  Severity: Minor
                  Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

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

                        protected function createFederatedShare(IShare $share) {
                            $token = $this->tokenHandler->generateToken();
                            $shareId = $this->addShareToDB(
                                $share->getNodeId(),
                                $share->getNodeType(),
                    Severity: Minor
                    Found in apps/federatedfilesharing/lib/FederatedShareProvider.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 getAccepted has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getAccepted($remote, $shareWith) {
                            $event = $this->eventDispatcher->dispatch(
                                new GenericEvent('', ['remote' => $remote]),
                                'remoteshare.received'
                            );
                    Severity: Minor
                    Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

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

                          private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $expiration, $token) {
                      Severity: Major
                      Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 1 hr to fix

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

                            public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
                        Severity: Minor
                        Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 45 mins to fix

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

                              public function addShare($remote, $token, $name, $owner, $shareWith, $remoteId) {
                          Severity: Minor
                          Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 45 mins to fix

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

                                public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
                            Severity: Minor
                            Found in apps/federatedfilesharing/lib/FederatedShareProvider.php - About 35 mins to fix

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

                                  public function delete(IShare $share) {
                                      list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
                              
                                      $isOwner = false;
                              
                              
                              Severity: Minor
                              Found in apps/federatedfilesharing/lib/FederatedShareProvider.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

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

                                      if ($reshares === false) {
                                          //Special case for old shares created via the web UI
                                          $or1 = $qb->expr()->andX(
                                              $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
                                              $qb->expr()->isNull('uid_initiator')
                              Severity: Major
                              Found in apps/federatedfilesharing/lib/FederatedShareProvider.php and 1 other location - About 3 hrs to fix
                              apps/federatedfilesharing/lib/FederatedShareProvider.php on lines 679..699

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

                              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 ($reshares === false) {
                                          //Special case for old shares created via the web UI
                                          $or1 = $qb->expr()->andX(
                                              $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
                                              $qb->expr()->isNull('uid_initiator')
                              Severity: Major
                              Found in apps/federatedfilesharing/lib/FederatedShareProvider.php and 1 other location - About 3 hrs to fix
                              apps/federatedfilesharing/lib/FederatedShareProvider.php on lines 628..648

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

                              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

                                      $qb = $qb->select('s.*')
                                          ->from('share', 's')
                                          ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
                                          ->where($qb->expr()->isNull('f.fileid'))
                                          ->andWhere(
                              Severity: Minor
                              Found in apps/federatedfilesharing/lib/FederatedShareProvider.php and 1 other location - About 1 hr to fix
                              lib/private/Share20/DefaultShareProvider.php on lines 973..983

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

                              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

                                  public function __construct(
                                      IDBConnection $connection,
                                      EventDispatcherInterface $eventDispatcher,
                                      AddressHandler $addressHandler,
                                      Notifications $notifications,
                              Severity: Minor
                              Found in apps/federatedfilesharing/lib/FederatedShareProvider.php and 1 other location - About 30 mins to fix
                              lib/private/Share/MailNotifications.php on lines 90..112

                              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