writesdown/app-cms

View on GitHub
common/components/MediaUploadHandler.php

Summary

Maintainability
F
3 days
Test Coverage

File MediaUploadHandler.php has 559 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @link http://www.writesdown.com/
 * @copyright Copyright (c) 2015 WritesDown
 * @license http://www.writesdown.com/license/
Severity: Major
Found in common/components/MediaUploadHandler.php - About 1 day to fix

    MediaUploadHandler has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MediaUploadHandler
    {
        const PRINT_RESPONSE = true;
        const NOT_PRINT_RESPONSE = false;
    
    
    Severity: Minor
    Found in common/components/MediaUploadHandler.php - About 4 hrs to fix

      Method createScaledImage has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function createScaledImage($fileName, $version, $options)
          {
              $success = false;
              $filePath = $this->getFilePath($fileName);
              $image = Image::getImagine()->open($filePath);
      Severity: Major
      Found in common/components/MediaUploadHandler.php - About 2 hrs to fix

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

            protected function createScaledImage($fileName, $version, $options)
            {
                $success = false;
                $filePath = $this->getFilePath($fileName);
                $image = Image::getImagine()->open($filePath);
        Severity: Minor
        Found in common/components/MediaUploadHandler.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 setOptions has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function setOptions($options = [])
            {
                $this->options = [
                    'script_url' => Yii::$app->request->absoluteUrl,
                    'upload_dir' => Yii::getAlias('@public/uploads/'),
        Severity: Minor
        Found in common/components/MediaUploadHandler.php - About 1 hr to fix

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

              public function post($printResponse = self::PRINT_RESPONSE)
              {
                  if (Yii::$app->request->get('delete') && $id = Yii::$app->request->get('id')) {
                      return $this->delete($id, $printResponse);
                  }
          Severity: Minor
          Found in common/components/MediaUploadHandler.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 post has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function post($printResponse = self::PRINT_RESPONSE)
              {
                  if (Yii::$app->request->get('delete') && $id = Yii::$app->request->get('id')) {
                      return $this->delete($id, $printResponse);
                  }
          Severity: Minor
          Found in common/components/MediaUploadHandler.php - About 1 hr to fix

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

                protected function correctExifRotation($image, $filePath)
                {
                    if (!function_exists('exif_read_data')) {
                        return false;
                    }
            Severity: Minor
            Found in common/components/MediaUploadHandler.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 get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get($id = null, $printResponse = self::PRINT_RESPONSE)
                {
                    $content = [];
            
                    if ($id && $media = $this->findMedia($id)) {
            Severity: Minor
            Found in common/components/MediaUploadHandler.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 setIconUrl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function setIconUrl($fileName)
                {
                    foreach ($this->fileTypes as $name => $type) {
                        if (preg_match($type['extensions'], $fileName)) {
                            if ($name === 'image') {
            Severity: Minor
            Found in common/components/MediaUploadHandler.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 generateResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function generateResponse($media)
                {
                    $metadata = $media->getMeta('metadata');
                    $response = ArrayHelper::merge(ArrayHelper::toArray($media), $metadata);
                    $response['date_formatted'] = Yii::$app->formatter->asDatetime($media->date);
            Severity: Minor
            Found in common/components/MediaUploadHandler.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