AyuntamientoMadrid/transparencia

View on GitHub

Showing 28 of 58 total issues

Class Person has 78 methods (exceeds 20 allowed). Consider refactoring.
Open

class Person < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: :slugged

  include ParseDataRows
Severity: Major
Found in app/models/person.rb - About 1 day to fix

    File person.rb has 341 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'sorting_name_calculator'
    
    class Person < ActiveRecord::Base
      extend FriendlyId
      friendly_id :name, use: :slugged
    Severity: Minor
    Found in app/models/person.rb - About 4 hrs to fix

      Class AssetsDeclaration has 27 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class AssetsDeclaration < ActiveRecord::Base
        include DateHelper
        include ParseDataRows
      
        scope :for_year, -> (year) { where ["declaration_date >= ? and declaration_date <= ?", Date.new(year,1,1), Date.new(year,12,31)] }
      Severity: Minor
      Found in app/models/assets_declaration.rb - About 3 hrs to fix

        Method import_row! has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def import_row!(row, _row_index)
              person_query = Person.where(personal_code: row[:n_personal])
              job_level = JOB_LEVELS.fetch(row[:tipo_de_vinculacion])
        
              if job_level == 'councillor'
        Severity: Minor
        Found in lib/excel_importers/profile.rb - About 1 hr to fix

          Method import has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def import
                declarations = Declarations.new(@path_to_file,
                                                @period,
                                                logger: @logger,
                                                sheet_name: '1.DatosPersonales')
          Severity: Minor
          Found in lib/excel_importers/assets.rb - About 1 hr to fix

            Method headers has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def headers
                  unless @headers
                    if @header_field.present?
                      sheet.each_with_index do |row, row_index|
                        if row.first == @header_field
            Severity: Minor
            Found in lib/excel_importers/base.rb - 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

            Method import_row! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def import_row!(row, _row_index)
                  person_query = Person.where(personal_code: row[:n_personal])
                  job_level = JOB_LEVELS.fetch(row[:tipo_de_vinculacion])
            
                  if job_level == 'councillor'
            Severity: Minor
            Found in lib/excel_importers/profile.rb - 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

            Method import! has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def import!
                  each_row(col_sep: ",") do |row|
                    person = Person.new
                    if row[:n_personal].present?
                      person = Person.where(councillor_code: row[:n_personal]).first!
            Severity: Minor
            Found in lib/importers/profiles_importer.rb - About 1 hr to fix

              Method person_params has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def person_params
                    params.require(:person).permit(
                      :first_name, :last_name, :job_level, :area, :councillor_code, :personal_code,
                      :twitter, :facebook, :role, :secondary_role, :unit, :party_id,
                      :studies_comment, :courses_comment, :career_comment, :political_posts_comment,
              Severity: Minor
              Found in app/controllers/admin/people_controller.rb - About 1 hr to fix

                Method import! has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def import!
                      each_row do |row|
                        center              = parse_text(row[:descripcion_centro])
                        organism            = parse_text(row[:organismo])
                        contract_number     = row[:numero_contrato]
                Severity: Minor
                Found in lib/importers/contracts_importer.rb - About 1 hr to fix

                  Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def create
                      attrs = assets_upload_params.merge(author: current_administrator,
                                                         check_for_file: true)
                      @assets_upload = AssetsUpload.new(attrs)
                  
                  
                  Severity: Minor
                  Found in app/controllers/admin/assets_uploads_controller.rb - About 1 hr to fix

                    Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def create
                        attrs = activities_upload_params.merge(author: current_administrator,
                                                               check_for_file: true)
                        @activities_upload = ActivitiesUpload.new(attrs)
                    
                    
                    Severity: Minor
                    Found in app/controllers/admin/activities_uploads_controller.rb - About 1 hr to fix

                      Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def create
                          attrs = profile_upload_params.merge(author: current_administrator,
                                                              check_for_file: true)
                          @profile_upload = ProfileUpload.new(attrs)
                      
                      
                      Severity: Minor
                      Found in app/controllers/admin/profile_uploads_controller.rb - About 1 hr to fix

                        Method import has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def import
                              declarations = Declarations.new(@path_to_file,
                                                              @period,
                                                              logger: @logger,
                                                              sheet_name: '1.DatosPersonales')
                        Severity: Minor
                        Found in lib/excel_importers/activities.rb - About 1 hr to fix

                          Method add_real_estate_property has 8 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            def add_real_estate_property(kind, type, description, municipality, share, purchase_date, tax_value, notes)
                          Severity: Major
                          Found in app/models/assets_declaration.rb - About 1 hr to fix

                            Method import! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def import!
                                  each_row(col_sep: ",") do |row|
                                    person = Person.new
                                    if row[:n_personal].present?
                                      person = Person.where(councillor_code: row[:n_personal]).first!
                            Severity: Minor
                            Found in lib/importers/profiles_importer.rb - About 55 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

                            Method add_private_activity has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              def add_private_activity(kind, description, entity, position, start_date, end_date)
                            Severity: Minor
                            Found in app/models/activities_declaration.rb - About 45 mins to fix

                              Method add_item has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  def add_item(collection, description, entity, start_year, end_year)
                              Severity: Minor
                              Found in app/models/person.rb - About 35 mins to fix

                                Method each_row has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def each_row(&_block)
                                      sheet.each_with_index do |row, row_index|
                                        next if row_index <= headers_row # skip header row
                                        row_hash = row_to_hash(row, row_index)
                                        next if row_hash.values.all?(&:blank?)
                                Severity: Minor
                                Found in lib/excel_importers/base.rb - 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

                                Avoid too many return statements within this method.
                                Open

                                    return 'V' if spokesperson?
                                Severity: Major
                                Found in app/models/person.rb - About 30 mins to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language