crafatar/crafatar

View on GitHub
lib/helpers.js

Summary

Maintainability
D
2 days
Test Coverage

File helpers.js has 323 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var networking = require("./networking");
var logging = require("./logging");
var renders = require("./renders");
var config = require("../config");
var cache = require("./cache");
Severity: Minor
Found in lib/helpers.js - About 3 hrs to fix

    Function get_image_hash has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    exp.get_image_hash = function(rid, userId, type, callback) {
      cache.get_details(userId, function(err, cache_details) {
        var cached_hash = null;
        if (cache_details !== null) {
          cached_hash = type === "skin" ? cache_details.skin : cache_details.cape;
    Severity: Minor
    Found in lib/helpers.js - About 3 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 store_skin has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function store_skin(rid, userId, profile, cache_details, callback) {
      networking.get_skin_info(rid, userId, profile, function(err, url, slim) {
        if (err) {
          slim = cache_details ? cache_details.slim : undefined;
        }
    Severity: Major
    Found in lib/helpers.js - About 2 hrs to fix

      Function store_images has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function store_images(rid, userId, cache_details, type, callback) {
        if (requests[type]["!" + userId]) {
          logging.debug(rid, "adding to request queue");
          push_request(userId, type, callback);
        } else {
      Severity: Minor
      Found in lib/helpers.js - About 1 hr to fix

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

        exp.get_image_hash = function(rid, userId, type, callback) {
          cache.get_details(userId, function(err, cache_details) {
            var cached_hash = null;
            if (cache_details !== null) {
              cached_hash = type === "skin" ? cache_details.skin : cache_details.cape;
        Severity: Minor
        Found in lib/helpers.js - About 1 hr to fix

          Function store_cape has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function store_cape(rid, userId, profile, cache_details, callback) {
            networking.get_cape_url(rid, userId, profile, function(err, url) {
              if (!err && url) {
                var cape_hash = get_hash(url);
                if (cache_details && cache_details.cape === cape_hash) {
          Severity: Minor
          Found in lib/helpers.js - About 1 hr to fix

            Function get_render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exp.get_render = function(rid, userId, scale, overlay, body, callback) {
              exp.get_skin(rid, userId, function(err, skin_hash, status, img, slim) {
                if (!skin_hash) {
                  callback(err, status, skin_hash, null);
                  return;
            Severity: Minor
            Found in lib/helpers.js - About 1 hr to fix

              Function get_render has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              exp.get_render = function(rid, userId, scale, overlay, body, callback) {
              Severity: Minor
              Found in lib/helpers.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                  if (skin_err) {
                                    callback(skin_err, null, slim);
                                  } else {
                                    skins.extract_face(img, facepath, function(err2) {
                                      if (err2) {
                Severity: Major
                Found in lib/helpers.js - About 45 mins to fix

                  Function store_skin has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  function store_skin(rid, userId, profile, cache_details, callback) {
                  Severity: Minor
                  Found in lib/helpers.js - About 35 mins to fix

                    Function get_avatar has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    exp.get_avatar = function(rid, userId, overlay, size, callback) {
                    Severity: Minor
                    Found in lib/helpers.js - About 35 mins to fix

                      Function store_images has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      function store_images(rid, userId, cache_details, type, callback) {
                      Severity: Minor
                      Found in lib/helpers.js - About 35 mins to fix

                        Function resume has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function resume(userId, type, err, hash, slim) {
                        Severity: Minor
                        Found in lib/helpers.js - About 35 mins to fix

                          Function store_cape has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          function store_cape(rid, userId, profile, cache_details, callback) {
                          Severity: Minor
                          Found in lib/helpers.js - About 35 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status