mysociety/alaveteli

View on GitHub

Showing 629 of 632 total issues

Function insertLegend has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        function insertLegend() {

            placeholder.find(".legend").remove();

            if (!options.legend.show)
Severity: Major
Found in app/assets/javascripts/jquery.flot.js - About 3 hrs to fix

    Function drawBar has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            function drawBar(x, y, b, barLeft, barRight, fillStyleCallback, axisx, axisy, c, horizontal, lineWidth) {
                var left, right, bottom, top,
                    drawLeft, drawRight, drawTop, drawBottom,
                    tmp;
    
    
    Severity: Major
    Found in app/assets/javascripts/jquery.flot.js - About 3 hrs to fix

      File mail_backend.rb has 300 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'mail'
      require 'mapi/msg'
      require 'mapi/convert'
      
      module Mail
      Severity: Minor
      Found in lib/mail_handler/backends/mail_backend.rb - About 3 hrs to fix

        Method main has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        def main(in_test_mode)
          Dir.chdir($alaveteli_dir) do
            raw_message = $stdin.read
            begin
              message = MailHandler.mail_from_raw_email(raw_message)
        Severity: Minor
        Found in script/handle-mail-replies.rb - 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

        Method authenticate has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

          def authenticate
            if AlaveteliConfiguration::skip_admin_auth
              session[:using_admin] = 1
              return
            else
        Severity: Minor
        Found in app/controllers/admin_controller.rb - 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

        Method alert_overdue_requests has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.alert_overdue_requests
            info_requests = InfoRequest.where("described_state = 'waiting_response'
                        AND awaiting_description = ?
                        AND user_id is not null
                        AND use_notifications = ?
        Severity: Minor
        Found in app/mailers/request_mailer.rb - 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 drawSeriesErrors has 77 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function drawSeriesErrors(plot, ctx, s){
        
                var points = s.datapoints.points,
                        ps = s.datapoints.pointsize,
                        ax = [s.xaxis, s.yaxis],
        Severity: Major
        Found in app/assets/javascripts/jquery.flot.errorbars.js - About 3 hrs to fix

          Function init has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function init(plot) {
                  // This is kind of a hack. There are no hooks in Flot between
                  // the creation and measuring of the ticks (setTicks, measureTickLabels
                  // in setupGrid() ) and the drawing of the ticks and plot box
                  // (insertAxisLabels in setupGrid() ).
          Severity: Major
          Found in app/assets/javascripts/jquery.flot.axislabels.js - About 3 hrs to fix

            Function onKeyDown has 76 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    onKeyDown: function(e) {
                        var isInput = e.target === this.$control_input[0];
                        var self = this;
                
                        if (self.isLocked) {
            Severity: Major
            Found in app/assets/javascripts/alaveteli_pro/selectize.js - About 3 hrs to fix

              Function setUpCorrespondenceCollapsing has 75 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              var setUpCorrespondenceCollapsing = function(){
                $('.js-collapsable').each(function(){
                  var $collapsable = $(this);
                  var $triggers = $(this).find('.js-collapsable-trigger');
                  var $correspondenceHeader = $(this).find('.correspondence__header');
              Severity: Major
              Found in app/assets/javascripts/correspondence-collapse.js - About 3 hrs to fix

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

                        if (self.settings.options) {
                            for (i = 0, n = self.settings.options.length; i < n; i++) {
                                self.registerOption(self.settings.options[i]);
                            }
                            delete self.settings.options;
                Severity: Major
                Found in app/assets/javascripts/alaveteli_pro/selectize.js and 1 other location - About 3 hrs to fix
                app/assets/javascripts/alaveteli_pro/selectize.js on lines 1192..1197

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

                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 (self.settings.optgroups) {
                            for (i = 0, n = self.settings.optgroups.length; i < n; i++) {
                                self.registerOptionGroup(self.settings.optgroups[i]);
                            }
                            delete self.settings.optgroups;
                Severity: Major
                Found in app/assets/javascripts/alaveteli_pro/selectize.js and 1 other location - About 3 hrs to fix
                app/assets/javascripts/alaveteli_pro/selectize.js on lines 1184..1189

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

                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

                Method up has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def up
                    default_locale = AlaveteliLocalization.default_locale
                
                    fields = {:title => :text,
                              :description => :text}
                Severity: Major
                Found in db/migrate/20140716131107_create_category_translation_tables.rb - About 2 hrs to fix

                  Method get_attachment_text_one_file has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def get_attachment_text_one_file(content_type, body, charset = 'utf-8')
                      # note re. charset: TMail always tries to convert email bodies
                      # to UTF8 by default, so normally it should already be that.
                      text = ''
                      # TODO: - tell all these command line tools to return utf-8
                  Severity: Minor
                  Found in lib/mail_handler/mail_handler.rb - 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 findNearbyItem has 72 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          function findNearbyItem(mouseX, mouseY, seriesFilter) {
                              var maxDistance = options.grid.mouseActiveRadius,
                                  smallestDistance = maxDistance * maxDistance + 1,
                                  item = null, foundPoint = false, i, j, ps;
                  
                  
                  Severity: Major
                  Found in app/assets/javascripts/jquery.flot.js - About 2 hrs to fix

                    Method index has 72 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def index
                        # Tasks to do
                        @requires_admin_requests = InfoRequest.
                          find_in_state('requires_admin').
                            not_embargoed
                    Severity: Major
                    Found in app/controllers/admin_general_controller.rb - About 2 hrs to fix

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

                              } else if (this.position == 'right') {
                                  this.elem.css('top', box.top + box.height/2 - this.labelHeight/2 +
                                                'px');
                                  this.elem.css('left', box.left + box.width - this.labelWidth +
                                                'px');
                      Severity: Major
                      Found in app/assets/javascripts/jquery.flot.axislabels.js and 1 other location - About 2 hrs to fix
                      app/assets/javascripts/jquery.flot.axislabels.js on lines 163..177

                      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

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

                              } else if (this.position == 'bottom') {
                                  this.elem.css('left', box.left + box.width/2 - this.labelWidth/2 +
                                                'px');
                                  this.elem.css('top', box.top + box.height - this.labelHeight +
                                                'px');
                      Severity: Major
                      Found in app/assets/javascripts/jquery.flot.axislabels.js and 1 other location - About 2 hrs to fix
                      app/assets/javascripts/jquery.flot.axislabels.js on lines 172..177

                      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

                      Class RequestFilter has 25 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                        class RequestFilter
                      
                          extend ActiveModel::Naming
                          include ActiveModel::Conversion
                      
                      
                      Severity: Minor
                      Found in app/models/alaveteli_pro/request_filter.rb - About 2 hrs to fix

                        Method add_correspondence has 70 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def add_correspondence
                            json = ActiveSupport::JSON.decode(params[:correspondence_json])
                            attachments = params[:attachments]
                        
                            direction = json["direction"]
                        Severity: Major
                        Found in app/controllers/api_controller.rb - About 2 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language