felixarntz/wp-gcs-offload

View on GitHub

Showing 52 of 52 total issues

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

( function( wp, $, data ) {

    function create_sync_notice( message, type, notice_before_selector ) {
        var $notice_section = $( '<div id="wp-gcs-offload-sync-notice-wrap" class="misc-pub-section" />' );
        var $notice = $( '<div id="wp-gcs-offload-sync-notice" class="notice notice-' + type + '" />' );
Severity: Major
Found in assets/dist/js/attachment-edit.js and 1 other location - About 3 days to fix
assets/src/js/attachment-edit.js on lines 1..104

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

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

( function( wp, $, data ) {

    function create_sync_notice( message, type, notice_before_selector ) {
        var $notice_section = $( '<div id="wp-gcs-offload-sync-notice-wrap" class="misc-pub-section" />' );
        var $notice = $( '<div id="wp-gcs-offload-sync-notice" class="notice notice-' + type + '" />' );
Severity: Major
Found in assets/src/js/attachment-edit.js and 1 other location - About 3 days to fix
assets/dist/js/attachment-edit.js on lines 6..109

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

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

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

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

            public function upload( $file, $path, $dir_name = '', $mime_type = 'image/jpeg', $metadata = array(), $args = array() ) {
                if ( ! $this->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/Client.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 attachment_submitbox_misc_actions has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            public function attachment_submitbox_misc_actions( $id = null ) {
                $attachment = Attachment::get( $id );
                if ( ! $attachment ) {
                    return;
                }
    Severity: Minor
    Found in inc/WPGCSOffload/Admin/AttachmentEdit.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 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

      Method attachment_submitbox_misc_actions has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public function attachment_submitbox_misc_actions( $id = null ) {
                  $attachment = Attachment::get( $id );
                  if ( ! $attachment ) {
                      return;
                  }
      Severity: Major
      Found in inc/WPGCSOffload/Admin/AttachmentEdit.php - About 2 hrs to fix

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

        var readmeheader =    'Plugin Name:       ' + config.pluginName + '\n' +
                            'Plugin URI:        ' + config.pluginURI + '\n' +
                            'Author:            ' + config.author + '\n' +
                            'Author URI:        ' + config.authorURI + '\n' +
                            'Contributors:      ' + config.contributors + '\n' +
        Severity: Major
        Found in gulpfile.js and 1 other location - About 2 hrs to fix
        gulpfile.js on lines 45..50

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

        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

        var pluginheader =     'Plugin Name: ' + config.pluginName + '\n' +
                            'Plugin URI:  ' + config.pluginURI + '\n' +
                            'Description: ' + config.description + '\n' +
                            'Version:     ' + config.version + '\n' +
                            'Author:      ' + config.author + '\n' +
        Severity: Major
        Found in gulpfile.js and 1 other location - About 2 hrs to fix
        gulpfile.js on lines 58..63

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

        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

        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 get_setting has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

                public function get_setting( $name ) {
                    if ( Admin::is_network_active() && ( 'authentication_key' === $name || 'bucket_name' === $name ) ) {
                        $constant_name = $this->get_setting_constant_name( $name );
        
                        if ( defined( $constant_name ) ) {
        Severity: Minor
        Found in inc/WPGCSOffload/Admin/Settings.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_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

        Method upload has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public function upload( $file, $path, $dir_name = '', $mime_type = 'image/jpeg', $metadata = array(), $args = array() ) {
                    if ( ! $this->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/Client.php - About 1 hr to fix

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

                  public function ajax_delete_attachment_downstream( $data ) {
                      $attachment = $this->ajax_get_attachment( $data );
                      if ( is_wp_error( $attachment ) ) {
                          return $attachment;
                      }
          Severity: Major
          Found in inc/WPGCSOffload/Admin/AttachmentEdit.php and 3 other locations - About 1 hr to fix
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 134..154
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 156..176
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 178..198

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

          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 4 locations. Consider refactoring.
          Open

                  public function ajax_sync_attachment_downstream( $data ) {
                      $attachment = $this->ajax_get_attachment( $data );
                      if ( is_wp_error( $attachment ) ) {
                          return $attachment;
                      }
          Severity: Major
          Found in inc/WPGCSOffload/Admin/AttachmentEdit.php and 3 other locations - About 1 hr to fix
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 134..154
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 178..198
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 200..220

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

          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 4 locations. Consider refactoring.
          Open

                  public function ajax_delete_attachment_upstream( $data ) {
                      $attachment = $this->ajax_get_attachment( $data );
                      if ( is_wp_error( $attachment ) ) {
                          return $attachment;
                      }
          Severity: Major
          Found in inc/WPGCSOffload/Admin/AttachmentEdit.php and 3 other locations - About 1 hr to fix
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 134..154
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 156..176
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 200..220

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

          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 4 locations. Consider refactoring.
          Open

                  public function ajax_sync_attachment_upstream( $data ) {
                      $attachment = $this->ajax_get_attachment( $data );
                      if ( is_wp_error( $attachment ) ) {
                          return $attachment;
                      }
          Severity: Major
          Found in inc/WPGCSOffload/Admin/AttachmentEdit.php and 3 other locations - About 1 hr to fix
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 156..176
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 178..198
          inc/WPGCSOffload/Admin/AttachmentEdit.php on lines 200..220

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

          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

          Method get_attachment_ids has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  public function get_attachment_ids( $mode = 'all', $number = -1, $offset = 0 ) {
                      $args = array(
                          'posts_per_page'            => $number,
                          'offset'                    => $offset,
                          'no_found_rows'                => true,
          Severity: Minor
          Found in inc/WPGCSOffload/Core/BackgroundSync.php - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language