wikimedia/mediawiki-core

View on GitHub
resources/lib/intersection-observer/intersection-observer.js

Summary

Maintainability
D
2 days
Test Coverage

File intersection-observer.js has 548 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE.
 *
Severity: Major
Found in resources/lib/intersection-observer/intersection-observer.js - About 1 day to fix

    Function _computeTargetAndRootIntersection has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function(target, targetRect, rootRect) {
      // If the element isn't displayed, an intersection can't happen.
      if (window.getComputedStyle(target).display == 'none') return;
    
      var intersectionRect = targetRect;
    Severity: Major
    Found in resources/lib/intersection-observer/intersection-observer.js - About 2 hrs to fix

      Function _monitorIntersections has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      IntersectionObserver.prototype._monitorIntersections = function(doc) {
        var win = doc.defaultView;
        if (!win) {
          // Already destroyed.
          return;
      Severity: Minor
      Found in resources/lib/intersection-observer/intersection-observer.js - About 1 hr to fix

        Function _checkForIntersections has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        IntersectionObserver.prototype._checkForIntersections = function() {
          if (!this.root && crossOriginUpdater && !crossOriginRect) {
            // Cross origin monitoring, but no initial data available yet.
            return;
          }
        Severity: Minor
        Found in resources/lib/intersection-observer/intersection-observer.js - About 1 hr to fix

          Function _unmonitorIntersections has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          IntersectionObserver.prototype._unmonitorIntersections = function(doc) {
            var index = this._monitoringDocuments.indexOf(doc);
            if (index == -1) {
              return;
            }
          Severity: Minor
          Found in resources/lib/intersection-observer/intersection-observer.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                      if (!crossOriginRect ||
                          crossOriginRect.width == 0 && crossOriginRect.height == 0) {
                        // A 0-size cross-origin intersection means no-intersection.
                        parent = null;
                        parentRect = null;
            Severity: Major
            Found in resources/lib/intersection-observer/intersection-observer.js - About 45 mins to fix

              Consider simplifying this complex logical expression.
              Open

                if (this.root && !isDoc(this.root)) {
                  rootRect = getBoundingClientRect(this.root);
                } else {
                  // Use <html>/<body> instead of window since scroll bars affect size.
                  var doc = isDoc(this.root) ? this.root : document;
              Severity: Major
              Found in resources/lib/intersection-observer/intersection-observer.js - About 40 mins to fix

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

                function addEvent(node, event, fn, opt_useCapture) {
                  if (typeof node.addEventListener == 'function') {
                    node.addEventListener(event, fn, opt_useCapture || false);
                  }
                  else if (typeof node.attachEvent == 'function') {
                Severity: Major
                Found in resources/lib/intersection-observer/intersection-observer.js and 1 other location - About 2 hrs to fix
                resources/lib/intersection-observer/intersection-observer.js on lines 820..827

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

                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 removeEvent(node, event, fn, opt_useCapture) {
                  if (typeof node.removeEventListener == 'function') {
                    node.removeEventListener(event, fn, opt_useCapture || false);
                  }
                  else if (typeof node.detatchEvent == 'function') {
                Severity: Major
                Found in resources/lib/intersection-observer/intersection-observer.js and 1 other location - About 2 hrs to fix
                resources/lib/intersection-observer/intersection-observer.js on lines 802..809

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

                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