WordPress/WordPress

View on GitHub
wp-includes/js/customize-preview.js

Summary

Maintainability
F
4 days
Test Coverage

File customize-preview.js has 518 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Script run inside a Customizer preview frame.
 *
 * @output wp-includes/js/customize-preview.js
 */
Severity: Major
Found in wp-includes/js/customize-preview.js - About 1 day to fix

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

        api.prepareFormPreview = function prepareFormPreview( form ) {
            var urlParser, stateParams = {};
    
            if ( ! form.action ) {
                form.action = location.href;
    Severity: Minor
    Found in wp-includes/js/customize-preview.js - About 1 hr to fix

      Function addRequestPreviewing has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          api.addRequestPreviewing = function addRequestPreviewing() {
      
              /**
               * Rewrite Ajax requests to inject customizer state.
               *
      Severity: Minor
      Found in wp-includes/js/customize-preview.js - About 1 hr to fix

        Function keepAliveCurrentUrl has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            api.keepAliveCurrentUrl = ( function() {
                var previousPathName = location.pathname,
                    previousQueryString = location.search.substr( 1 ),
                    previousQueryParams = null,
                    stateQueryParams = [ 'customize_theme', 'customize_changeset_uuid', 'customize_messenger_channel', 'customize_autosaved' ];
        Severity: Minor
        Found in wp-includes/js/customize-preview.js - About 1 hr to fix

          Function prefilterAjax has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  var prefilterAjax = function( options, originalOptions, xhr ) {
                      var urlParser, queryParams, requestMethod, dirtyValues = {};
                      urlParser = document.createElement( 'a' );
                      urlParser.href = options.url;
          
          
          Severity: Minor
          Found in wp-includes/js/customize-preview.js - About 1 hr to fix

            Function keepAliveCurrentUrl has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    return function keepAliveCurrentUrl() {
                        var urlParser, currentQueryParams;
            
                        // Short-circuit with keep-alive if previous URL is identical (as is normal case).
                        if ( previousQueryString === location.search.substr( 1 ) && previousPathName === location.pathname ) {
            Severity: Minor
            Found in wp-includes/js/customize-preview.js - About 1 hr to fix

              Function prepareLinkPreview has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  api.prepareLinkPreview = function prepareLinkPreview( element ) {
                      var queryParams, $element = $( element );
              
                      // Skip elements with no href attribute. Check first to avoid more expensive checks down the road.
                      if ( ! element.hasAttribute( 'href' ) ) {
              Severity: Minor
              Found in wp-includes/js/customize-preview.js - About 1 hr to fix

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

                    api.isLinkPreviewable = function isLinkPreviewable( element, options ) {
                        var matchesAllowedUrl, parsedAllowedUrl, args, elementHost;
                
                        args = _.extend( {}, { allowAdminAjax: false }, options || {} );
                
                
                Severity: Minor
                Found in wp-includes/js/customize-preview.js - About 1 hr to fix

                  Avoid too many return statements within this function.
                  Open

                          return true;
                  Severity: Major
                  Found in wp-includes/js/customize-preview.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return;
                    Severity: Major
                    Found in wp-includes/js/customize-preview.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return args.allowAdminAjax;
                      Severity: Major
                      Found in wp-includes/js/customize-preview.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return false;
                        Severity: Major
                        Found in wp-includes/js/customize-preview.js - About 30 mins to fix

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

                                  history.replaceState = ( function( nativeReplaceState ) {
                                      return function historyReplaceState( data, title, url ) {
                                          currentHistoryState = data;
                                          return nativeReplaceState.call( history, data, title, 'string' === typeof url && url.length > 0 ? injectUrlWithState( url ) : url );
                                      };
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 61..66

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

                          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

                                  history.pushState = ( function( nativePushState ) {
                                      return function historyPushState( data, title, url ) {
                                          currentHistoryState = data;
                                          return nativePushState.call( history, data, title, 'string' === typeof url && url.length > 0 ? injectUrlWithState( url ) : url );
                                      };
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 54..59

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

                          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

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

                                          api.preview.send( 'ready', {
                                              currentUrl: api.settings.url.self,
                                              activePanels: api.settings.activePanels,
                                              activeSections: api.settings.activeSections,
                                              activeControls: api.settings.activeControls,
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 850..856

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

                          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

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

                                  api.preview.send( 'ready', {
                                      currentUrl: api.settings.url.self,
                                      activePanels: api.settings.activePanels,
                                      activeSections: api.settings.activeSections,
                                      activeControls: api.settings.activeControls,
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 607..613

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

                          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 ( api.settings.channel && 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.host ) ) {
                                      element.protocol = 'https:';
                                  }
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 518..521

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

                          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 ( api.settings.channel && 'https' === api.preview.scheme.get() && 'http:' === urlParser.protocol && -1 !== api.settings.url.allowedHosts.indexOf( urlParser.host ) ) {
                                      urlParser.protocol = 'https:';
                                      form.action = urlParser.href;
                                  }
                          Severity: Major
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 2 hrs to fix
                          wp-includes/js/customize-preview.js on lines 356..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 79.

                          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

                                      $( document.body ).find( 'a[href], area[href]' ).each( function() {
                                          api.prepareLinkPreview( this );
                                      } );
                          Severity: Minor
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 30 mins to fix
                          wp-includes/js/customize-preview.js on lines 818..820

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

                          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

                                      $( document.body ).find( 'a[href], area[href]' ).each( function() {
                                          api.prepareLinkPreview( this );
                                      } );
                          Severity: Minor
                          Found in wp-includes/js/customize-preview.js and 1 other location - About 30 mins to fix
                          wp-includes/js/customize-preview.js on lines 784..786

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

                          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