jeresig/pharos-images

View on GitHub
logic/admin.js

Summary

Maintainability
D
2 days
Test Coverage

Function exports has 196 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function(app) {
    const ImageImport = models("ImageImport");
    const ArtworkImport = models("ArtworkImport");

    const importArtworks = (req, res) => {
Severity: Major
Found in logic/admin.js - About 7 hrs to fix

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

            uploadData(req, res, next) {
                const source = req.source;
    
                const form = new formidable.IncomingForm();
                form.encoding = "utf-8";
    Severity: Minor
    Found in logic/admin.js - About 1 hr to fix

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

          const importImages = (req, res) => {
              const Image = models("Image");
      
              const batchState = (batch) => batch.getCurState().name(req);
              const batchError = (err) => ImageImport.getError(req, err);
      Severity: Minor
      Found in logic/admin.js - About 1 hr to fix

        Function exports has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        module.exports = function(app) {
            const ImageImport = models("ImageImport");
            const ArtworkImport = models("ArtworkImport");
        
            const importArtworks = (req, res) => {
        Severity: Minor
        Found in logic/admin.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 adminPage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const adminPage = (req, res, next) => {
                const source = req.source;
                const batchState = (batch) => batch.getCurState().name(req);
                const batchError = (batch) => batch.getError(req);
        
        
        Severity: Minor
        Found in logic/admin.js - About 1 hr to fix

          Function importArtworks has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              const importArtworks = (req, res) => {
                  const batchState = (batch) => batch.getCurState().name(req);
                  const batchError = (err) => ArtworkImport.getError(req, err);
          
                  ArtworkImport.findById(req.query.artworks, (err, batch) => {
          Severity: Minor
          Found in logic/admin.js - About 1 hr to fix

            Function uploadImages has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    uploadImages(req, res, next) {
                        const source = req.source;
            
                        const form = new formidable.IncomingForm();
                        form.encoding = "utf-8";
            Severity: Minor
            Found in logic/admin.js - About 1 hr to fix

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

                                  batch.save((err) => {
                                      /* istanbul ignore if */
                                      if (err) {
                                          return next(new Error(
                                              req.gettext("Error saving data file.")));
              Severity: Major
              Found in logic/admin.js and 1 other location - About 1 hr to fix
              logic/admin.js on lines 174..182

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

              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

                              batch.save((err) => {
                                  /* istanbul ignore if */
                                  if (err) {
                                      return next(new Error(
                                          req.gettext("Error saving zip file.")));
              Severity: Major
              Found in logic/admin.js and 1 other location - About 1 hr to fix
              logic/admin.js on lines 225..233

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

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

                          if (err || !batch) {
                              return res.status(404).render("Error", {
                                  title: req.gettext("Import not found."),
                              });
                          }
              Severity: Major
              Found in logic/admin.js and 3 other locations - About 35 mins to fix
              logic/admin.js on lines 61..65
              logic/artworks.js on lines 29..33
              logic/uploads.js on lines 142..146

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

              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 (req.query.finalize) {
                              return batch.manuallyApprove(() => {
                                  res.redirect(req.source.getAdminURL(req.lang));
                              });
                          }
              Severity: Minor
              Found in logic/admin.js and 1 other location - About 35 mins to fix
              logic/admin.js on lines 29..38

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

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

                          if (err || !batch) {
                              return res.status(404).render("Error", {
                                  title: req.gettext("Import not found."),
                              });
                          }
              Severity: Major
              Found in logic/admin.js and 3 other locations - About 35 mins to fix
              logic/admin.js on lines 23..27
              logic/artworks.js on lines 29..33
              logic/uploads.js on lines 142..146

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

              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 (req.query.abandon) {
                              return batch.abandon(() => {
                                  res.redirect(req.source.getAdminURL(req.lang));
                              });
              
              
              Severity: Minor
              Found in logic/admin.js and 1 other location - About 35 mins to fix
              logic/admin.js on lines 34..38

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

              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