owncloud/core

View on GitHub
lib/private/Preview.php

Summary

Maintainability
F
5 days
Test Coverage

File Preview.php has 665 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Björn Schießle <bjoern@schiessle.org>
 * @author Frank Karlitschek <frank@karlitschek.de>
 * @author Georg Ehrke <georg@owncloud.com>
Severity: Major
Found in lib/private/Preview.php - About 1 day to fix

    Preview has 45 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Preview {
        //the thumbnail folder
        public const THUMBNAILS_FOLDER = 'thumbnails';
    
        public const MODE_FILL = 'fill';
    Severity: Minor
    Found in lib/private/Preview.php - About 6 hrs to fix

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

          private function generatePreview() {
              $file = $this->getFile();
              $preview = null;
      
              $previewProviders = \OC::$server->getPreviewManager()
      Severity: Minor
      Found in lib/private/Preview.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

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

          public function getPreview() {
              if ($this->preview !== null && $this->preview->valid()) {
                  return $this->preview;
              }
      
      
      Severity: Minor
      Found in lib/private/Preview.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 resizeAndStore has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function resizeAndStore() {
              $image = $this->preview;
              if (!($image instanceof IImage)) {
                  Util::writeLog(
                      'core',
      Severity: Minor
      Found in lib/private/Preview.php - About 1 hr to fix

        Function deletePreview has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function deletePreview($keepMax = true) {
                $fileInfo = $this->getFile();
                if ($fileInfo !== null && $fileInfo !== false) {
                    if ($keepMax === true) {
                        $previewPath = $this->buildCachePath();
        Severity: Minor
        Found in lib/private/Preview.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 generatePreview has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function generatePreview() {
                $file = $this->getFile();
                $preview = null;
        
                $previewProviders = \OC::$server->getPreviewManager()
        Severity: Minor
        Found in lib/private/Preview.php - About 1 hr to fix

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

              public function getPreview() {
                  if ($this->preview !== null && $this->preview->valid()) {
                      return $this->preview;
                  }
          
          
          Severity: Minor
          Found in lib/private/Preview.php - About 1 hr to fix

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

                public function isCached() {
                    $fileId = $this->getFile()->getId();
                    if ($fileId === null) {
                        return false;
                    }
            Severity: Minor
            Found in lib/private/Preview.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 cropAndFill has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function cropAndFill($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
                    if ($previewWidth > $askedWidth) {
                        $cropX = \floor(($previewWidth - $askedWidth) * 0.5);
                        $image->crop($cropX, 0, $askedWidth, $previewHeight);
                        $previewWidth = $askedWidth;
            Severity: Minor
            Found in lib/private/Preview.php - About 1 hr to fix

              Method scale has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
                      $scalingUp = $this->getScalingUp();
                      $maxScaleFactor = $this->getMaxScaleFactor();
              
                      $factorX = $askedWidth / $previewWidth;
              Severity: Minor
              Found in lib/private/Preview.php - About 1 hr to fix

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

                    public function isCached() {
                        $fileId = $this->getFile()->getId();
                        if ($fileId === null) {
                            return false;
                        }
                Severity: Minor
                Found in lib/private/Preview.php - About 1 hr to fix

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

                          $user = '',
                          $root = '/',
                          Node $file = null,
                          $maxX = 1,
                          $maxY = 1,
                  Severity: Major
                  Found in lib/private/Preview.php - About 50 mins to fix

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

                        private function unscalable($x, $y) {
                            $maxX = $this->getMaxX();
                            $maxY = $this->getMaxY();
                            $scalingUp = $this->getScalingUp();
                            $maxScaleFactor = $this->getMaxScaleFactor();
                    Severity: Minor
                    Found in lib/private/Preview.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

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

                        private function resizeAndStore() {
                            $image = $this->preview;
                            if (!($image instanceof IImage)) {
                                Util::writeLog(
                                    'core',
                    Severity: Minor
                    Found in lib/private/Preview.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

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

                        private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
                            $scalingUp = $this->getScalingUp();
                            $maxScaleFactor = $this->getMaxScaleFactor();
                    
                            $factorX = $askedWidth / $previewWidth;
                    Severity: Minor
                    Found in lib/private/Preview.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 crop has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        private function crop($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight = null) {
                    Severity: Minor
                    Found in lib/private/Preview.php - About 35 mins to fix

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

                          private function cropAndFill($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
                      Severity: Minor
                      Found in lib/private/Preview.php - About 35 mins to fix

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

                            private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
                        Severity: Minor
                        Found in lib/private/Preview.php - About 35 mins to fix

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

                              private function getCachedPreview($cached) {
                                  $stream = $this->userView->fopen($cached, 'r');
                                  $this->preview = null;
                                  if ($stream) {
                                      $image = new \OC_Image();
                          Severity: Minor
                          Found in lib/private/Preview.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 getPossibleThumbnails has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function getPossibleThumbnails($allThumbnails) {
                                  if ($this->keepAspect) {
                                      $wantedAspectRatio = (float)($this->maxPreviewWidth / $this->maxPreviewHeight);
                                  } else {
                                      $wantedAspectRatio = (float)($this->getMaxX() / $this->getMaxY());
                          Severity: Minor
                          Found in lib/private/Preview.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 false;
                          Severity: Major
                          Found in lib/private/Preview.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return $this->isCachedBigger($allThumbnails);
                            Severity: Major
                            Found in lib/private/Preview.php - About 30 mins to fix

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

                                  public function showPreview($mimeTypeForHeaders = null) {
                                      // Check if file is valid
                                      if ($this->isFileValid() === false) {
                                          throw new NotFoundException('File not found.');
                                      }
                              Severity: Minor
                              Found in lib/private/Preview.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 buildCachePath has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  private function buildCachePath($maxX = null, $maxY = null) {
                                      if ($maxX === null) {
                                          $maxX = $this->getMaxX();
                                      }
                                      if ($maxY === null) {
                              Severity: Minor
                              Found in lib/private/Preview.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

                              There are no issues that match your filters.

                              Category
                              Status