silegis-mg/editor-articulacao

View on GitHub
src/EditorArticulacaoController.js

Summary

Maintainability
F
3 days
Test Coverage

File EditorArticulacaoController.js has 375 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* Copyright 2017 Assembleia Legislativa de Minas Gerais
 * 
 * This file is part of Editor-Articulacao.
 *
 * Editor-Articulacao is free software: you can redistribute it and/or modify
Severity: Minor
Found in src/EditorArticulacaoController.js - About 5 hrs to fix

    Function obterSelecao has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    function obterSelecao(ctrl) {
        var selecao = ctrl.getSelection();
        var range = selecao && selecao.rangeCount > 0 ? selecao.getRangeAt(0) : null;
    
        if (range) {
    Severity: Minor
    Found in src/EditorArticulacaoController.js - About 4 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 _normalizarParagrafo has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        _normalizarParagrafo(dispositivo) {
            let anterior = encontrarDispositivoAnteriorDoTipo(dispositivo, ['artigo', 'paragrafo']);
            let posterior = encontrarDispositivoPosteriorDoTipo(dispositivo, ['artigo', 'paragrafo']);
    
            if (dispositivo.getAttribute('data-tipo') === 'paragrafo' || dispositivo.getAttribute('data-tipo') === 'continuacao') {
    Severity: Minor
    Found in src/EditorArticulacaoController.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

    EditorArticulacaoController has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class EditorArticulacaoController {
    
        /**
         * Elemento do DOM que será utilizado como editor de articulação.
         * 
    Severity: Minor
    Found in src/EditorArticulacaoController.js - About 2 hrs to fix

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

      function obterSelecao(ctrl) {
          var selecao = ctrl.getSelection();
          var range = selecao && selecao.rangeCount > 0 ? selecao.getRangeAt(0) : null;
      
          if (range) {
      Severity: Minor
      Found in src/EditorArticulacaoController.js - About 1 hr to fix

        Function atualizarContexto has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            atualizarContexto() {
                var elementoSelecionado = obterSelecao(this);
        
                if (!elementoSelecionado) {
                    if (!this.contexto) {
        Severity: Minor
        Found in src/EditorArticulacaoController.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 constructor has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            constructor(elemento, opcoes) {
                if (!(elemento instanceof Element)) {
                    throw 'Elemento não é um elemento do DOM.';
                }
        
        
        Severity: Minor
        Found in src/EditorArticulacaoController.js - About 1 hr to fix

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

          function transformarEmEditor(elemento, editorCtrl, opcoes) {
              let style = document.createElement('style');
              style.innerHTML = css.toString().replace(/\${(.+?)}/g, (m, valor) => opcoes.rotulo[valor]);
          
              /* Se houver suporte ao shadow-dom, então vamos usá-lo
          Severity: Minor
          Found in src/EditorArticulacaoController.js - About 1 hr to fix

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

                constructor(elemento, opcoes) {
                    if (!(elemento instanceof Element)) {
                        throw 'Elemento não é um elemento do DOM.';
                    }
            
            
            Severity: Minor
            Found in src/EditorArticulacaoController.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 alterarTipoDispositivoSelecionado has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                alterarTipoDispositivoSelecionado(novoTipo) {
                    this.atualizarContexto();
            
                    if (!this.contexto) {
                        throw 'Não há contexto atual.';
            Severity: Minor
            Found in src/EditorArticulacaoController.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 _normalizarDispositivo has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                _normalizarDispositivo(dispositivo, contexto) {
                    while (dispositivo && !dispositivo.hasAttribute('data-tipo')) {
                        dispositivo = dispositivo.parentElement;
                    }
            
            
            Severity: Minor
            Found in src/EditorArticulacaoController.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 transformarEmEditor has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            function transformarEmEditor(elemento, editorCtrl, opcoes) {
                let style = document.createElement('style');
                style.innerHTML = css.toString().replace(/\${(.+?)}/g, (m, valor) => opcoes.rotulo[valor]);
            
                /* Se houver suporte ao shadow-dom, então vamos usá-lo
            Severity: Minor
            Found in src/EditorArticulacaoController.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 _normalizarParagrafo has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _normalizarParagrafo(dispositivo) {
                    let anterior = encontrarDispositivoAnteriorDoTipo(dispositivo, ['artigo', 'paragrafo']);
                    let posterior = encontrarDispositivoPosteriorDoTipo(dispositivo, ['artigo', 'paragrafo']);
            
                    if (dispositivo.getAttribute('data-tipo') === 'paragrafo' || dispositivo.getAttribute('data-tipo') === 'continuacao') {
            Severity: Minor
            Found in src/EditorArticulacaoController.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                              do {
                                  startContainer = startContainer.firstElementChild;
                              } while (startContainer.firstElementChild);
              Severity: Major
              Found in src/EditorArticulacaoController.js - About 45 mins to fix

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

                    get lexml() {
                        try {
                            return this.vazio ? document.createDocumentFragment() : exportarParaLexML(this._elemento, this.opcoes.rotulo);
                        } catch (e) {
                            if (e instanceof ArticulacaoInvalidaException) {
                Severity: Minor
                Found in src/EditorArticulacaoController.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 lexml has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    set lexml(valor) {
                        let articulacao = importarDeLexML(valor);
                
                        this._elemento.innerHTML = '';
                        this._elemento.appendChild(articulacao);
                Severity: Minor
                Found in src/EditorArticulacaoController.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

                There are no issues that match your filters.

                Category
                Status