felixarntz/wp-gcs-offload

View on GitHub
inc/WPGCSOffload/Core/Attachment.php

Summary

Maintainability
F
3 days
Test Coverage

Function upload_to_cloud_storage has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

        public function upload_to_cloud_storage( $metadata = false, $suppress_hooks = false ) {
            if ( ! Client::instance()->is_configured() ) {
                return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
            }

Severity: Minor
Found in inc/WPGCSOffload/Core/Attachment.php - About 5 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

File Attachment.php has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WPGCSOffload\Core\Attachment class
 *
 * @package WPGCSOffload
Severity: Minor
Found in inc/WPGCSOffload/Core/Attachment.php - About 4 hrs to fix

    Method upload_to_cloud_storage has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function upload_to_cloud_storage( $metadata = false, $suppress_hooks = false ) {
                if ( ! Client::instance()->is_configured() ) {
                    return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
                }
    
    
    Severity: Major
    Found in inc/WPGCSOffload/Core/Attachment.php - About 2 hrs to fix

      Function delete_local_file has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

              public function delete_local_file( $metadata = false, $suppress_hooks = false ) {
                  if ( ! $this->is_cloud_storage_file() ) {
                      return new WP_Error( 'not_in_cloud_storage', sprintf( __( 'The files for attachment %d cannot be deleted since they are not available on Google Cloud Storage.', 'wp-gcs-offload' ), $this->id ) );
                  }
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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 download_from_cloud_storage has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              public function download_from_cloud_storage( $metadata = false, $suppress_hooks = false ) {
                  if ( ! Client::instance()->is_configured() ) {
                      return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
                  }
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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

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

              public function delete_from_cloud_storage( $metadata = false, $suppress_hooks = false ) {
                  if ( ! Client::instance()->is_configured() ) {
                      return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
                  }
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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

      Function delete_local_sizes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              private function delete_local_sizes( $meta_sizes, $image_sizes, $main_file, $dir_name ) {
                  $uploads = wp_get_upload_dir();
      
                  $errors = new WP_Error();
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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

      Function download_sizes_from_google_cloud_storage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              private function download_sizes_from_google_cloud_storage( $meta_sizes, $image_sizes, $main_file, $dir_name ) {
                  $uploads = wp_get_upload_dir();
      
                  $errors = new WP_Error();
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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

      Function upload_sizes_to_cloud_storage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              private function upload_sizes_to_cloud_storage( $meta_sizes, &$image_sizes, $main_file, $dir_name, $mime_type, $args ) {
                  $uploads = wp_get_upload_dir();
      
                  $errors = new WP_Error();
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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

      Function delete_sizes_from_google_cloud_storage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              private function delete_sizes_from_google_cloud_storage( $meta_sizes, $image_sizes, $main_file, $dir_name ) {
                  $errors = new WP_Error();
      
                  foreach ( $meta_sizes as $size => $data ) {
                      if ( ! in_array( $size, $image_sizes, true ) ) {
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.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 delete_from_cloud_storage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public function delete_from_cloud_storage( $metadata = false, $suppress_hooks = false ) {
                  if ( ! Client::instance()->is_configured() ) {
                      return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
                  }
      
      
      Severity: Minor
      Found in inc/WPGCSOffload/Core/Attachment.php - About 1 hr to fix

        Method download_from_cloud_storage has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public function download_from_cloud_storage( $metadata = false, $suppress_hooks = false ) {
                    if ( ! Client::instance()->is_configured() ) {
                        return new WP_Error( 'client_not_configured', __( 'The Google Cloud Storage client is not configured properly.', 'wp-gcs-offload' ) );
                    }
        
        
        Severity: Minor
        Found in inc/WPGCSOffload/Core/Attachment.php - About 1 hr to fix

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

                  public function get_cloud_storage_image_downsize( $size = 'thumbnail' ) {
                      $gcs_url = $this->get_cloud_storage_url();
                      if ( ! $gcs_url ) {
                          return false;
                      }
          Severity: Minor
          Found in inc/WPGCSOffload/Core/Attachment.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

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

                  public static function get( $id = null ) {
                      if ( ! $id ) {
                          $post = get_post();
                          if ( ! $post ) {
                              return null;
          Severity: Minor
          Found in inc/WPGCSOffload/Core/Attachment.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 delete_local_file has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  public function delete_local_file( $metadata = false, $suppress_hooks = false ) {
                      if ( ! $this->is_cloud_storage_file() ) {
                          return new WP_Error( 'not_in_cloud_storage', sprintf( __( 'The files for attachment %d cannot be deleted since they are not available on Google Cloud Storage.', 'wp-gcs-offload' ), $this->id ) );
                      }
          
          
          Severity: Minor
          Found in inc/WPGCSOffload/Core/Attachment.php - About 1 hr to fix

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

                    private function upload_sizes_to_cloud_storage( $meta_sizes, &$image_sizes, $main_file, $dir_name, $mime_type, $args ) {
            Severity: Minor
            Found in inc/WPGCSOffload/Core/Attachment.php - About 45 mins to fix

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

                      public function get_cloud_storage_url() {
                          $bucket_name = get_post_meta( $this->id, '_wpgcso_bucket_name', true );
                          if ( ! $bucket_name ) {
                              return false;
                          }
              Severity: Minor
              Found in inc/WPGCSOffload/Core/Attachment.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