RouteInjector/route-injector

View on GitHub
lib/engine/routeinjector/images/new-image-injector.js

Summary

Maintainability
F
2 wks
Test Coverage

File new-image-injector.js has 398 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var mkdirp = require('mkdirp');
var fs = require('fs');
var glob = require('glob');
var async = require('async');
var path = require('path');
Severity: Minor
Found in lib/engine/routeinjector/images/new-image-injector.js - About 5 hrs to fix

    Function insertImage has 122 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function insertImage(param) {
        return function (req, res) {
            var outDirectory = param.out;
            if (req.files.image != undefined) {
                //ext includes '.'
    Severity: Major
    Found in lib/engine/routeinjector/images/new-image-injector.js - About 4 hrs to fix

      Function process has 91 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                              function process() {
      
                                  var outFile = path.join(outDirectory, fileName);//path.basename(req.files.image.path));
      
                                  var fileToDb = {
      Severity: Major
      Found in lib/engine/routeinjector/images/new-image-injector.js - About 3 hrs to fix

        Function injectImages has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        exports.injectImages = function (_app, param) {
        
            var imageConf = injector.config.env.images;
            imagePath = imageConf.path;
            cachePath = imageConf.cache;
        Severity: Minor
        Found in lib/engine/routeinjector/images/new-image-injector.js - About 2 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 injectImages has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.injectImages = function (_app, param) {
        
            var imageConf = injector.config.env.images;
            imagePath = imageConf.path;
            cachePath = imageConf.cache;
        Severity: Minor
        Found in lib/engine/routeinjector/images/new-image-injector.js - About 1 hr to fix

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

          function getFileNameFromFile(outDirectory, sourceFileName, cb) {
              var fileName = null;
              sourceFileName = sourceFileName.toLowerCase();
          
              if (!fs.existsSync(outDirectory)) {
          Severity: Minor
          Found in lib/engine/routeinjector/images/new-image-injector.js - About 1 hr to fix

            Function uploadFile has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    function uploadFile(item, cb) {
                        fs.exists(item.path, function (exists) {
                            if (exists) {
                                //TODO pass as setting paramter
                                if (1 == 0) {//Get file name as randoom
            Severity: Minor
            Found in lib/engine/routeinjector/images/new-image-injector.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (i == 0) {
                                          fileName = sourceFileName;
                                      } else {
                                          fileName = addStringBeforeExtension(sourceFileName, '_' + i);
                                      }
              Severity: Major
              Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                                                        if (e) {
                                                                            log.error(e);
                                                                            res.json(e);
                                                                            res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                                            return res.end();
                Severity: Major
                Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                                                      if (e) {
                                                                          log.error(e);
                                                                          res.json(e);
                                                                          res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                                          return res.end();
                  Severity: Major
                  Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

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

                    exports.injectImages = function (_app, param) {
                    
                        var imageConf = injector.config.env.images;
                        imagePath = imageConf.path;
                        cachePath = imageConf.cache;
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 1 other location - About 6 days to fix
                    lib/engine/routeinjector/images/image-injector.js on lines 116..179

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

                    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 (injector.config.env.images && injector.config.env.images.galleryFolder) {
                        injector.app.get("/gallery", function (req, res) {
                            var folder = injector.config.env.images.galleryFolder;
                            fs.readdir(folder, function (err, files) {
                                if (files) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 1 other location - About 5 days to fix
                    lib/engine/routeinjector/images/image-injector.js on lines 17..113

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

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

                    function getFileNameFromFile(outDirectory, sourceFileName, cb) {
                        var fileName = null;
                        sourceFileName = sourceFileName.toLowerCase();
                    
                        if (!fs.existsSync(outDirectory)) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 1 day to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 205..244
                    lib/engine/routeinjector/images/image-injector.js on lines 397..436

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

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

                    function copyFile(source, target, cb) {
                        var cbCalled = false;
                    
                        var rd = fs.createReadStream(source);
                        rd.on("error", function (err) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 6 hrs to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 257..279
                    lib/engine/routeinjector/images/image-injector.js on lines 449..471

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

                    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

                    function deleteImage(param) {
                        return function (req, res) {
                            var filePath = req.params.path;
                    
                            deleteFullPathImage(path.join(param.out, filePath), function (err) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 4 hrs to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 298..313
                    lib/engine/routeinjector/images/image-injector.js on lines 490..505

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

                    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

                    function getAbsoluteImage(param) {
                        return function (req, res) {
                            var redUrl = "";
                            if (req.params["size"]) {
                                redUrl = '/images/' + param.folder + '/' + req.params["size"] + '/' + req.params.path;
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 1 other location - About 4 hrs to fix
                    lib/engine/routeinjector/images/image-injector.js on lines 181..192

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

                    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

                    function clearCache(model, imageName) {
                        glob(path.join(cachePath, model, "**", imageName), function (err, files) {
                    
                            for (var i = 0; i < files.length; i++) {
                                fs.unlink(files[i], function (err) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 1 other location - About 3 hrs to fix
                    lib/engine/routeinjector/images/image-injector.js on lines 237..249

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

                    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

                    function deleteFullPathImage(filePath, cb) {
                        fs.exists(filePath, function (exists) {
                            if (exists) {
                                fs.unlink(filePath, function (err) {
                                    if (err) {
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 2 hrs to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 281..296
                    lib/engine/routeinjector/images/image-injector.js on lines 473..488

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

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

                    function addStringBeforeExtension(filename, text) {
                        var ext = getExtension(filename);
                        filename = filename.replace('.' + ext, '');
                        return filename + text + '.' + ext;
                    
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 1 hr to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 246..251
                    lib/engine/routeinjector/images/image-injector.js on lines 438..443

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

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

                    function getExtension(filename) {
                        var ext = path.extname(filename || '').split('.');
                        return ext[ext.length - 1];
                    }
                    Severity: Major
                    Found in lib/engine/routeinjector/images/new-image-injector.js and 2 other locations - About 50 mins to fix
                    lib/engine/routeinjector/files/file-injector.js on lines 252..255
                    lib/engine/routeinjector/images/image-injector.js on lines 444..447

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

                    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