insideout10/wordlift-plugin-js

View on GitHub
app/admin_files/autosave.js

Summary

Maintainability
D
3 days
Test Coverage

File autosave.js has 488 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global switchEditors, autosaveL10n, tinymce, ajaxurl, wpAjax, makeSlugeditClickable, wpCookies */
var autosave, autosavePeriodical, fullscreen, doPreview,
    autosaveLast = '',
    autosaveDelayPreview = false,
    notSaved = true,
Severity: Minor
Found in app/admin_files/autosave.js - About 7 hrs to fix

    Function getPostData has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    wp.autosave.getPostData = function() {
        var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, cats = [],
            data = {
                action: 'autosave',
                autosave: true,
    Severity: Minor
    Found in app/admin_files/autosave.js - About 1 hr to fix

      Function checkPost has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          checkPost: function() {
              var self = this, post_data = this.getData(), content, post_title, excerpt, notice,
                  post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id );
      
              if ( ! post_data )
      Severity: Minor
      Found in app/admin_files/autosave.js - About 1 hr to fix

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

        function autosave_parse_response( response ) {
            var res = wpAjax.parseAjaxResponse(response, 'autosave'), post_id, sup;
        
            if ( res && res.responses && res.responses.length ) {
                if ( res.responses[0].supplemental ) {
        Severity: Minor
        Found in app/admin_files/autosave.js - 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

        Consider simplifying this complex logical expression.
        Open

                    if ( editor && ! editor.isHidden() ) {
                        // Last onSubmit event in the editor, needs to run after the content has been moved to the textarea.
                        editor.onSubmit.add( function() {
                            wp.autosave.local.save({
                                post_title: $('#title').val() || '',
        Severity: Critical
        Found in app/admin_files/autosave.js - About 1 hr to fix

          Function run has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              run: function() {
                  var self = this;
          
                  // Check if the local post data is different than the loaded post data.
                  this.checkPost();
          Severity: Minor
          Found in app/admin_files/autosave.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                if ( typeof fullscreen != 'undefined' && fullscreen.settings.visible ) {
                    data.post_title = $('#wp-fullscreen-title').val() || '';
                    data.content = $('#wp_mce_fullscreen').val() || '';
                } else {
                    data.post_title = $('#title').val() || '';
            Severity: Major
            Found in app/admin_files/autosave.js - About 40 mins to fix

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

              function autosave_saved_new(response) {
                  blockSave = false;
                  var res = autosave_parse_response(response), post_id;
              
                  if ( res && res.responses.length && !res.errors ) {
              Severity: Minor
              Found in app/admin_files/autosave.js - 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

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

                              compareString = wp.autosave.getCompareString({
                                  post_title: $('#wp-fullscreen-title').val() || '',
                                  content: $('#wp_mce_fullscreen').val() || '',
                                  excerpt: $('#excerpt').val() || ''
                              });
              Severity: Major
              Found in app/admin_files/autosave.js and 2 other locations - About 1 hr to fix
              app/admin_files/autosave.js on lines 581..585
              app/admin_files/autosave.js on lines 588..592

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

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

                              self.save({
                                  post_title: $('#title').val() || '',
                                  content: $('#content').val() || '',
                                  excerpt: $('#excerpt').val() || ''
                              });
              Severity: Major
              Found in app/admin_files/autosave.js and 2 other locations - About 1 hr to fix
              app/admin_files/autosave.js on lines 53..57
              app/admin_files/autosave.js on lines 581..585

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

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

                                  wp.autosave.local.save({
                                      post_title: $('#title').val() || '',
                                      content: $('#content').val() || '',
                                      excerpt: $('#excerpt').val() || ''
                                  });
              Severity: Major
              Found in app/admin_files/autosave.js and 2 other locations - About 1 hr to fix
              app/admin_files/autosave.js on lines 53..57
              app/admin_files/autosave.js on lines 588..592

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

              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

                          if ( target.hasClass('restore-backup') ) {
                              self.restorePost( self.restore_post_data );
                              target.parent().hide();
                              $(this).find('p.undo-restore').show();
                          } else if ( target.hasClass('undo-restore-backup') ) {
              Severity: Major
              Found in app/admin_files/autosave.js and 1 other location - About 1 hr to fix
              app/admin_files/autosave.js on lines 665..669

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

              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

                          } else if ( target.hasClass('undo-restore-backup') ) {
                              self.restorePost( self.undo_post_data );
                              target.parent().hide();
                              $(this).find('p.local-restore').show();
                          }
              Severity: Major
              Found in app/admin_files/autosave.js and 1 other location - About 1 hr to fix
              app/admin_files/autosave.js on lines 661..669

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

              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

                  if ( typeof fullscreen != 'undefined' && fullscreen.settings.visible ) {
                      data.post_title = $('#wp-fullscreen-title').val() || '';
                      data.content = $('#wp_mce_fullscreen').val() || '';
                  } else {
              Severity: Major
              Found in app/admin_files/autosave.js and 1 other location - About 1 hr to fix
              app/admin_files/autosave.js on lines 358..361

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

              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

                  } else {
                      data.post_title = $('#title').val() || '';
                      data.content = $('#content').val() || '';
                  }
              Severity: Major
              Found in app/admin_files/autosave.js and 1 other location - About 1 hr to fix
              app/admin_files/autosave.js on lines 355..358

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

              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

              There are no issues that match your filters.

              Category
              Status