YetiForceCompany/YetiForceCRM

View on GitHub
public_html/layouts/resources/fields/MultiImage.js

Summary

Maintainability
F
5 days
Test Coverage

File MultiImage.js has 580 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* {[The file is published on the basis of YetiForce Public License 6.5 that can be found in the following directory: licenses/LicenseEN.txt or yetiforce.com]} */
'use strict';

class MultiImage {
    /**
Severity: Major
Found in public_html/layouts/resources/fields/MultiImage.js - About 1 day to fix

    MultiImage has 37 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MultiImage {
        /**
         * Create class instance
         *
         * @param {HTMLElement|jQuery} inputElement - input type file element inside component
    Severity: Minor
    Found in public_html/layouts/resources/fields/MultiImage.js - About 4 hrs to fix

      Function constructor has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          constructor(element) {
              const thisInstance = this;
              this.elements = {};
              this.options = {
                  showCarousel: true
      Severity: Major
      Found in public_html/layouts/resources/fields/MultiImage.js - About 2 hrs to fix

        Function zoomPreview has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            zoomPreview(hash) {
                const self = this;
                let fileInfo = this.getFileInfo(hash);
                const titleTemplate = () => {
                    const titleObject = document.createElement('span');
        Severity: Major
        Found in public_html/layouts/resources/fields/MultiImage.js - About 2 hrs to fix

          Function addPreviewPopover has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              addPreviewPopover(file, template, imageSrc) {
                  const thisInstance = this;
                  let fileSize = '';
                  const fileInfo = this.getFileInfo(file.hash);
                  let size = fileInfo.sizeDisplay || fileInfo.size;
          Severity: Minor
          Found in public_html/layouts/resources/fields/MultiImage.js - About 1 hr to fix

            Function uploadError has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                uploadError(_e, data) {
                    this.progressInstance.progressIndicator({ mode: 'hide' });
                    app.errorLog('File upload error.');
                    const { jqXHR, files } = data;
                    const response = jqXHR.responseJSON;
            Severity: Minor
            Found in public_html/layouts/resources/fields/MultiImage.js - About 1 hr to fix

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

                  uploadSuccess(e, data) {
                      this.progressInstance.progressIndicator({ mode: 'hide' });
                      const { result } = data;
                      const attach = result.result.attach;
                      attach.forEach((fileAttach) => {
              Severity: Minor
              Found in public_html/layouts/resources/fields/MultiImage.js - About 1 hr to fix

                Function constructor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    constructor(element) {
                        const thisInstance = this;
                        this.elements = {};
                        this.options = {
                            showCarousel: true
                Severity: Minor
                Found in public_html/layouts/resources/fields/MultiImage.js - About 35 mins 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 setFilesHash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    setFilesHash(files) {
                        const addedFiles = [];
                        for (let i = 0, len = files.length; i < len; i++) {
                            const file = files[i];
                            if (typeof file.hash === 'undefined') {
                Severity: Minor
                Found in public_html/layouts/resources/fields/MultiImage.js - About 35 mins 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

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

                            this.elements.fileInput.fileupload({
                                dataType: 'json',
                                replaceFileInput: false,
                                fileInput: this.fileInput,
                                autoUpload: false,
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 6 hrs to fix
                public_html/layouts/resources/Fields.js on lines 3389..3402

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

                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

                        this.files = actualElements.map((element) => {
                            for (let i = 0, len = this.files.length; i < len; i++) {
                                const elementHash = $(element).data('hash');
                                if (this.files[i].hash === elementHash) {
                                    return this.files[i];
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 3 hrs to fix
                public_html/layouts/resources/Fields.js on lines 3742..3749

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

                        for (let i = 0, len = this.files.length; i < len; i++) {
                            const file = this.files[i];
                            if (file.hash === hash) {
                                return file;
                            }
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 1 hr to fix
                public_html/layouts/resources/Fields.js on lines 3637..3642

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

                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

                            this.elements.component.on('click', '.js-multi-image__popover-btn-delete', function (e) {
                                e.preventDefault();
                                thisInstance.deleteFile($(this).data('hash'));
                            });
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 2 other locations - About 1 hr to fix
                public_html/layouts/resources/fields/MultiImage.js on lines 64..67
                public_html/layouts/resources/fields/MultiImage.js on lines 68..71

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

                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

                        this.elements.component.on('click', '.js-multi-image__popover-btn-zoom', function (e) {
                            e.preventDefault();
                            thisInstance.zoomPreview($(this).data('hash'));
                        });
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 2 other locations - About 1 hr to fix
                public_html/layouts/resources/fields/MultiImage.js on lines 68..71
                public_html/layouts/resources/fields/MultiImage.js on lines 73..76

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

                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

                        this.elements.component.on('click', '.js-multi-image__popover-btn-download', function (e) {
                            e.preventDefault();
                            thisInstance.download($(this).data('hash'));
                        });
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 2 other locations - About 1 hr to fix
                public_html/layouts/resources/fields/MultiImage.js on lines 64..67
                public_html/layouts/resources/fields/MultiImage.js on lines 73..76

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

                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

                        if (App.Fields.MultiImage.currentFileUploads) {
                            e.preventDefault();
                            e.stopPropagation();
                            e.stopImmediatePropagation();
                            app.showAlert(app.vtranslate('JS_WAIT_FOR_FILE_UPLOAD'));
                Severity: Major
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 1 hr to fix
                public_html/layouts/resources/Fields.js on lines 3450..3456

                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

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

                            app.showNotify({
                                text: `${app.vtranslate('JS_UPLOADED_FILE_SIZE_EXCEEDS')} <br> [${this.options.maxFileSizeDisplay}]`,
                                type: 'error'
                            });
                Severity: Minor
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 50 mins to fix
                public_html/layouts/resources/fields/MultiImage.js on lines 310..313

                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

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

                        app.showNotify({
                            text: `${app.vtranslate('JS_FILE_LIMIT')} [${this.options.limit}]`,
                            type: 'error'
                        });
                Severity: Minor
                Found in public_html/layouts/resources/fields/MultiImage.js and 1 other location - About 50 mins to fix
                public_html/layouts/resources/fields/MultiImage.js on lines 297..300

                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