owncloud/core

View on GitHub
lib/private/Files/Cache/Cache.php

Summary

Maintainability
F
5 days
Test Coverage

File Cache.php has 627 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Andreas Fischer <bantu@owncloud.com>
 * @author Björn Schießle <bjoern@schiessle.org>
 * @author Florin Peter <github@florin-peter.de>
Severity: Major
Found in lib/private/Files/Cache/Cache.php - About 1 day to fix

    Cache has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Cache implements ICache {
        use MoveFromCacheTrait {
            MoveFromCacheTrait::moveFromCache as moveFromCacheFallback;
        }
    
    
    Severity: Minor
    Found in lib/private/Files/Cache/Cache.php - About 4 hrs to fix

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

          protected function buildParts(array $data) {
              $fields = [
                  'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
                  'etag', 'permissions', 'checksum'];
      
      
      Severity: Minor
      Found in lib/private/Files/Cache/Cache.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 calculateFolderSize has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          public function calculateFolderSize($path, $entry = null) {
              $totalSize = 0;
              if ($entry === null or !isset($entry['fileid'])) {
                  $entry = $this->get($path);
              }
      Severity: Minor
      Found in lib/private/Files/Cache/Cache.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 update has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public function update($id, array $data) {
              unset(self::$path_cache[(int)$id]);
              if (isset($data['path'])) {
                  // normalize path
                  $data['path'] = $this->normalize($data['path']);
      Severity: Minor
      Found in lib/private/Files/Cache/Cache.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 handleChildrenMove has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function handleChildrenMove($sourceStorageId, $sourcePath, $targetStorageId, $targetPath) {
              $platformName = $this->connection->getDatabasePlatform()->getName();
              $versionString = $this->connection->getDatabaseVersionString();
              $versionArray = \explode('.', $versionString);
      
      
      Severity: Major
      Found in lib/private/Files/Cache/Cache.php - About 2 hrs to fix

        Method getChildrenWithFilter has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getChildrenWithFilter($fileId, $mimetypeFilter = null) {
                if ($fileId > -1) {
                    $qb = $this->connection->getQueryBuilder();
                    $qb->select(
                        'fileid',
        Severity: Minor
        Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

          Method get has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get($file) {
                  if (\is_string($file) or $file == '') {
                      // normalize file
                      $file = $this->normalize($file);
          
          
          Severity: Minor
          Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

            Method update has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function update($id, array $data) {
                    unset(self::$path_cache[(int)$id]);
                    if (isset($data['path'])) {
                        // normalize path
                        $data['path'] = $this->normalize($data['path']);
            Severity: Minor
            Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

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

                  public function get($file) {
                      if (\is_string($file) or $file == '') {
                          // normalize file
                          $file = $this->normalize($file);
              
              
              Severity: Minor
              Found in lib/private/Files/Cache/Cache.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 buildParts has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function buildParts(array $data) {
                      $fields = [
                          'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
                          'etag', 'permissions', 'checksum'];
              
              
              Severity: Minor
              Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

                Method calculateFolderSize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function calculateFolderSize($path, $entry = null) {
                        $totalSize = 0;
                        if ($entry === null or !isset($entry['fileid'])) {
                            $entry = $this->get($path);
                        }
                Severity: Minor
                Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

                  Method searchByTag has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function searchByTag($tag, $userId) {
                          $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' .
                              '`mimetype`, `mimepart`, `size`, `mtime`, ' .
                              '`encrypted`, `etag`, `permissions`, `checksum` ' .
                              'FROM `*PREFIX*filecache` `file`, ' .
                  Severity: Minor
                  Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

                    Method insert has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function insert($file, array $data) {
                            // normalize file
                            $file = $this->normalize($file);
                    
                            if (isset($this->partial[$file])) { //add any saved partial data
                    Severity: Minor
                    Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

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

                          public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
                              self::$path_cache->clear();
                              if ($sourceCache instanceof Cache) {
                                  // normalize source and target
                                  $sourcePath = $this->normalize($sourcePath);
                      Severity: Minor
                      Found in lib/private/Files/Cache/Cache.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 moveFromCache has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
                              self::$path_cache->clear();
                              if ($sourceCache instanceof Cache) {
                                  // normalize source and target
                                  $sourcePath = $this->normalize($sourcePath);
                      Severity: Minor
                      Found in lib/private/Files/Cache/Cache.php - About 1 hr to fix

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

                            public function getPathById($id) {
                                if (!isset(self::$path_cache[(int)$id])) {
                                    $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
                                    $result = $this->connection->executeQuery($sql, [$id]);
                                    if ($row = $result->fetch()) {
                        Severity: Minor
                        Found in lib/private/Files/Cache/Cache.php - About 55 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

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

                            private function getChildrenWithFilter($fileId, $mimetypeFilter = null) {
                                if ($fileId > -1) {
                                    $qb = $this->connection->getQueryBuilder();
                                    $qb->select(
                                        'fileid',
                        Severity: Minor
                        Found in lib/private/Files/Cache/Cache.php - About 55 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

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

                            public function getStatus($file) {
                                // normalize file
                                $file = $this->normalize($file);
                        
                                $pathHash = \md5($file);
                        Severity: Minor
                        Found in lib/private/Files/Cache/Cache.php - About 55 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

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

                            private function handleChildrenMove($sourceStorageId, $sourcePath, $targetStorageId, $targetPath) {
                                $platformName = $this->connection->getDatabasePlatform()->getName();
                                $versionString = $this->connection->getDatabaseVersionString();
                                $versionArray = \explode('.', $versionString);
                        
                        
                        Severity: Minor
                        Found in lib/private/Files/Cache/Cache.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::NOT_FOUND;
                        Severity: Major
                        Found in lib/private/Files/Cache/Cache.php - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status