src/app/hooks/useImageColour/colorthief.js

Summary

Maintainability
F
1 wk
Test Coverage
F
5%

Function r has a Cognitive Complexity of 135 (exceeds 5 allowed). Consider refactoring.
Open

var r = (function () {
    var r = 5,
      n = 8 - r,
      o = 1e3;
    function e(t, n, o) {
Severity: Minor
Found in src/app/hooks/useImageColour/colorthief.js - About 2 days 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 r has 303 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var r = (function () {
    var r = 5,
      n = 8 - r,
      o = 1e3;
    function e(t, n, o) {
Severity: Major
Found in src/app/hooks/useImageColour/colorthief.js - About 1 day to fix

    File colorthief.js has 427 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*
    The colorthief module does not seem to be compatible with
    yarn v3 due to how it references github sub dependencies
    
    This file is from:
    Severity: Minor
    Found in src/app/hooks/useImageColour/colorthief.js - About 6 hrs to fix

      Function quantize has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              quantize: function (h, c) {
                if (!h.length || c < 2 || c > 256) return !1;
                var f = (function (t) {
                  var o,
                    i = new Array(1 << (3 * r));
      Severity: Major
      Found in src/app/hooks/useImageColour/colorthief.js - About 2 hrs to fix

        Function s has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function s(r, n) {
              if (n.count()) {
                var o = n.r2 - n.r1 + 1,
                  i = n.g2 - n.g1 + 1,
                  u = t.max([o, i, n.b2 - n.b1 + 1]);
        Severity: Major
        Found in src/app/hooks/useImageColour/colorthief.js - About 2 hrs to fix

          Function getPalette has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            (o.prototype.getPalette = function (t, o, e) {
              var i = (function (t) {
                  var r = t.colorCount,
                    n = t.quality;
                  if (void 0 !== r && Number.isInteger(r)) {
          Severity: Minor
          Found in src/app/hooks/useImageColour/colorthief.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

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

            (o.prototype.getPalette = function (t, o, e) {
              var i = (function (t) {
                  var r = t.colorCount,
                    n = t.quality;
                  if (void 0 !== r && Number.isInteger(r)) {
          Severity: Minor
          Found in src/app/hooks/useImageColour/colorthief.js - About 1 hr to fix

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

                    avg: function (t) {
                      var n = this.histo;
                      if (!this._avg || t) {
                        var o,
                          i,
            Severity: Minor
            Found in src/app/hooks/useImageColour/colorthief.js - About 1 hr to fix

              Function u has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  function u(t, r, n, o, e, i, u) {
              Severity: Major
              Found in src/app/hooks/useImageColour/colorthief.js - About 50 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            for (c = 0, s = n.r1; s <= n.r2; s++)
                              for (h = n.g1; h <= n.g2; h++) c += r[e(s, h, a)] || 0;
                Severity: Major
                Found in src/app/hooks/useImageColour/colorthief.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              for (c = 0, s = n.r1; s <= n.r2; s++)
                                for (h = n.b1; h <= n.b2; h++) c += r[e(s, a, h)] || 0;
                  Severity: Major
                  Found in src/app/hooks/useImageColour/colorthief.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                  for (h = n.b1; h <= n.b2; h++) c += r[e(a, s, h)] || 0;
                    Severity: Major
                    Found in src/app/hooks/useImageColour/colorthief.js - About 45 mins to fix

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

                              if (u == o)
                                for (a = n.r1; a <= n.r2; a++) {
                                  for (c = 0, s = n.g1; s <= n.g2; s++)
                                    for (h = n.b1; h <= n.b2; h++) c += r[e(a, s, h)] || 0;
                                  v[a] = f += c;
                      Severity: Major
                      Found in src/app/hooks/useImageColour/colorthief.js and 1 other location - About 4 hrs to fix
                      src/app/hooks/useImageColour/colorthief.js on lines 113..124

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

                      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 (u == i)
                                for (a = n.g1; a <= n.g2; a++) {
                                  for (c = 0, s = n.r1; s <= n.r2; s++)
                                    for (h = n.b1; h <= n.b2; h++) c += r[e(s, a, h)] || 0;
                                  v[a] = f += c;
                      Severity: Major
                      Found in src/app/hooks/useImageColour/colorthief.js and 1 other location - About 4 hrs to fix
                      src/app/hooks/useImageColour/colorthief.js on lines 107..124

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

                      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