owncloud/core

View on GitHub
apps/files/lib/Command/TroubleshootTransferOwnership.php

Summary

Maintainability
D
2 days
Test Coverage

File TroubleshootTransferOwnership.php has 328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Piotr Mrowczynski <piotr@owncloud.com>
 *
 * @copyright Copyright (c) 2020, ownCloud GmbH
Severity: Minor
Found in apps/files/lib/Command/TroubleshootTransferOwnership.php - About 3 hrs to fix

    Function findInvalidShareOwner has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        private function findInvalidShareOwner(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
            $output->writeln([
                "<info>==========================</info>",
                "<info>Searching for shares that have invalid uid_owner, meaning share uid_owner that does not match associated file storage id.</info>",
                "<info>==========================</info>",
    Severity: Minor
    Found in apps/files/lib/Command/TroubleshootTransferOwnership.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 findInvalidReshareInitiator has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function findInvalidReshareInitiator(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
            $output->writeln([
                "<info>==========================</info>",
                "<info>Searching for reshares that have invalid uid_initiator(resharer), meaning resharer which does not have the received share mounted anymore (that he reshared with other user).</info>",
                "<info>==========================</info>",
    Severity: Major
    Found in apps/files/lib/Command/TroubleshootTransferOwnership.php - About 2 hrs to fix

      Function findInvalidReshareInitiator has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          private function findInvalidReshareInitiator(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
              $output->writeln([
                  "<info>==========================</info>",
                  "<info>Searching for reshares that have invalid uid_initiator(resharer), meaning resharer which does not have the received share mounted anymore (that he reshared with other user).</info>",
                  "<info>==========================</info>",
      Severity: Minor
      Found in apps/files/lib/Command/TroubleshootTransferOwnership.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 findInvalidShareOwner has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function findInvalidShareOwner(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
              $output->writeln([
                  "<info>==========================</info>",
                  "<info>Searching for shares that have invalid uid_owner, meaning share uid_owner that does not match associated file storage id.</info>",
                  "<info>==========================</info>",
      Severity: Major
      Found in apps/files/lib/Command/TroubleshootTransferOwnership.php - About 2 hrs to fix

        Method getAllInvalidShareStorages has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function getAllInvalidShareStorages($storageType, $scopeUid) {
                $query = $this->connection->getQueryBuilder();
        
                if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
                    $concatFunction = $query->createFunction("CONCAT('$storageType', s.uid_owner)");
        Severity: Minor
        Found in apps/files/lib/Command/TroubleshootTransferOwnership.php - About 1 hr to fix

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

              protected function adjustShareOwner($shareId, $shareType, $newUidOwner) {
                  $query = $this->connection->getQueryBuilder();
          
                  $query->update('share')
                      ->set('uid_owner', $query->createParameter('uid_owner'))
          Severity: Minor
          Found in apps/files/lib/Command/TroubleshootTransferOwnership.php - About 1 hr to fix

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

                    $query->update('share')
                        ->set('uid_owner', $query->createParameter('uid_owner'))
                        ->where(
                            $query->expr()->andX(
                                $query->expr()->eq('id', $query->createParameter('shareid')),
            Severity: Major
            Found in apps/files/lib/Command/TroubleshootTransferOwnership.php and 1 other location - About 1 hr to fix
            apps/files/lib/Command/TroubleshootTransferOwnership.php on lines 401..411

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

            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

                    $query->update('share')
                        ->set('uid_initiator', $query->createParameter('uid_initiator'))
                        ->where(
                            $query->expr()->andX(
                                $query->expr()->eq('id', $query->createParameter('shareid')),
            Severity: Major
            Found in apps/files/lib/Command/TroubleshootTransferOwnership.php and 1 other location - About 1 hr to fix
            apps/files/lib/Command/TroubleshootTransferOwnership.php on lines 430..440

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

            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

                    $query->andWhere($query->expr()->orX(
                        $query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
                        $query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
                        $query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)),
                        $query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))
            Severity: Major
            Found in apps/files/lib/Command/TroubleshootTransferOwnership.php and 1 other location - About 1 hr to fix
            apps/files/lib/Command/TroubleshootTransferOwnership.php on lines 349..369

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

            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

                    $query->select('s.id', 's.file_source', 's.share_type', 's.parent', 'st.id', 's.uid_owner', 's.uid_initiator', 's.share_with')
                        ->selectAlias('s.id', 'share_id')
                        ->selectAlias('s.file_source', 'file_source')
                        ->selectAlias('s.share_type', 'share_type')
                        ->selectAlias('s.parent', 'share_parent')
            Severity: Major
            Found in apps/files/lib/Command/TroubleshootTransferOwnership.php and 1 other location - About 1 hr to fix
            apps/files/lib/Command/TroubleshootTransferOwnership.php on lines 316..321

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

            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