ciudadanointeligente/partidopublico

View on GitHub
app/controllers/partidos_controller.rb

Summary

Maintainability
F
3 days
Test Coverage

File partidos_controller.rb has 497 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class PartidosController < ApplicationController
  before_action :authenticate_admin!, only: [:new, :edit, :create, :update, :destroy, :admin]
  before_filter :authenticate_superadmin, only: [:new, :edit, :create, :update, :destroy]
  before_action :set_partido, except: [:index, :new, :create, :admin]
  before_action :get_partidos, except: [:index, :new, :create, :admin]
Severity: Minor
Found in app/controllers/partidos_controller.rb - About 7 hrs to fix

    Class PartidosController has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PartidosController < ApplicationController
      before_action :authenticate_admin!, only: [:new, :edit, :create, :update, :destroy, :admin]
      before_filter :authenticate_superadmin, only: [:new, :edit, :create, :update, :destroy]
      before_action :set_partido, except: [:index, :new, :create, :admin]
      before_action :get_partidos, except: [:index, :new, :create, :admin]
    Severity: Minor
    Found in app/controllers/partidos_controller.rb - About 4 hrs to fix

      Method regiones has 87 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def regiones
          rangos = [[14,17],[18,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,64],[65,69],[70,100]]
          @datos_region = []
          @datos_nacional = []
          @rangos_edad = []
      Severity: Major
      Found in app/controllers/partidos_controller.rb - About 3 hrs to fix

        Method acuerdos_organos has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          def acuerdos_organos
            @acuerdos = []
            tipos = %w(Acta Programatico Electoral Funcionamiento\ Interno)
        
            tipos.each do |t|
        Severity: Minor
        Found in app/controllers/partidos_controller.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

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

          def estructura_organica
            organos_internos = @partido.organo_internos
            @datos = []
        
            organos_internos.each do |o|
        Severity: Minor
        Found in app/controllers/partidos_controller.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 show has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def show
        
            @datos_region = []
            @datos_sedes = []
            @datos_cargos = []
        Severity: Minor
        Found in app/controllers/partidos_controller.rb - About 1 hr to fix

          Method intereses_patrimonios has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def intereses_patrimonios
              @intereses_patrimonios = []
              tc_candidatos = @partido.tipo_cargos#.where(candidato:true)
              tc_candidatos.each do |tc|
                filter_by = @partido.cargos.where(tipo_cargo_id:tc)
          Severity: Minor
          Found in app/controllers/partidos_controller.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 regiones has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def regiones
              rangos = [[14,17],[18,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,64],[65,69],[70,100]]
              @datos_region = []
              @datos_nacional = []
              @rangos_edad = []
          Severity: Minor
          Found in app/controllers/partidos_controller.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

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

            def publicacion_candidatos
              @publicacion_candidatos = []
              tc_candidatos = @partido.tipo_cargos.where(candidato:true)
              tc_candidatos.each do |tc|
                filter_by = @partido.cargos.where(tipo_cargo_id:tc)
          Severity: Minor
          Found in app/controllers/partidos_controller.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

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

            def representantes
              @representantes = []
              t_cargos = @partido.tipo_cargos.where(representante: true)
              by_gender = []
              t_cargos.each do |tc|
          Severity: Minor
          Found in app/controllers/partidos_controller.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

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

            def autoridades
              @autoridades = []
              t_cargos = @partido.tipo_cargos.where(autoridad: true)
              t_cargos.each do |tc|
                cargos = @partido.cargos.where(tipo_cargo_id: tc)
          Severity: Minor
          Found in app/controllers/partidos_controller.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

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

            def update
              PaperTrail.whodunnit = current_admin.email
              respond_to do |format|
                if @partido.update(partido_params)
                  format.html { redirect_to @partido, notice: 'Partido was successfully updated.' }
          Severity: Major
          Found in app/controllers/partidos_controller.rb and 3 other locations - About 1 hr to fix
          app/controllers/cargos_controller.rb on lines 45..53
          app/controllers/sedes_controller.rb on lines 46..54
          app/controllers/tipo_cargos_controller.rb on lines 45..53

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

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

                if !params[:q].blank?
                  n = params[:q].split(" ")[0]
                  a = params[:q].split(" ")[1] || params[:q].split(" ")[0]
                  personas = Persona.where("lower(personas.nombre) like ? OR lower(personas.apellidos) like ?", n.downcase, a.downcase)
                  filter_by = filter_by.where(:persona_id => personas)
          Severity: Major
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 55 mins to fix
          app/controllers/partidos_controller.rb on lines 450..454
          app/controllers/partidos_controller.rb on lines 552..556

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

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

                if !params[:q].blank?
                  n = params[:q].split(" ")[0]
                  a = params[:q].split(" ")[1] || params[:q].split(" ")[0]
                  personas = Persona.where("lower(personas.nombre) like ? OR lower(personas.apellidos) like ?", n.downcase, a.downcase)
                  filter_by = filter_by.where(:persona_id => personas)
          Severity: Major
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 55 mins to fix
          app/controllers/partidos_controller.rb on lines 528..532
          app/controllers/partidos_controller.rb on lines 552..556

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

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

                if !params[:q].blank?
                  n = params[:q].split(" ")[0]
                  a = params[:q].split(" ")[1] || params[:q].split(" ")[0]
                  personas = Persona.where("lower(personas.nombre) like ? OR lower(personas.apellidos) like ?", n.downcase, a.downcase)
                  filter_by = filter_by.where(:persona_id => personas)
          Severity: Major
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 55 mins to fix
          app/controllers/partidos_controller.rb on lines 450..454
          app/controllers/partidos_controller.rb on lines 528..532

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

          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

              rangos = [[14,17],[18,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,64],[65,69],[70,100]]
          Severity: Minor
          Found in app/controllers/partidos_controller.rb and 1 other location - About 40 mins to fix
          app/helpers/comparisons_helper.rb on lines 14..14

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

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

              if params[:fecha_datos]
                @fecha = Date.new(params[:fecha_datos].split("-")[0].to_i, params[:fecha_datos].split("-")[1].to_i, params[:fecha_datos].split("-")[2].to_i)
              else
                @fecha = @fechas_datos.last
          Severity: Minor
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 35 mins to fix
          app/controllers/partidos_controller.rb on lines 323..326
          app/controllers/partidos_controller.rb on lines 364..367

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

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

              if params[:fecha_datos]
                @fecha = Date.new(params[:fecha_datos].split("-")[0].to_i, params[:fecha_datos].split("-")[1].to_i, params[:fecha_datos].split("-")[2].to_i)
              else
                @fecha = @fechas_datos.last
          Severity: Minor
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 35 mins to fix
          app/controllers/partidos_controller.rb on lines 343..346
          app/controllers/partidos_controller.rb on lines 364..367

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

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

              if params[:fecha_datos]
                @fecha = Date.new(params[:fecha_datos].split("-")[0].to_i, params[:fecha_datos].split("-")[1].to_i, params[:fecha_datos].split("-")[2].to_i)
              else
                @fecha = @fechas_datos.last
          Severity: Minor
          Found in app/controllers/partidos_controller.rb and 2 other locations - About 35 mins to fix
          app/controllers/partidos_controller.rb on lines 323..326
          app/controllers/partidos_controller.rb on lines 343..346

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

          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

            def destroy
              PaperTrail.whodunnit = current_admin.email
              @partido.destroy
              respond_to do |format|
                format.html { redirect_to partidos_url, notice: 'Partido was successfully destroyed.' }
          Severity: Minor
          Found in app/controllers/partidos_controller.rb and 3 other locations - About 15 mins to fix
          app/controllers/cargos_controller.rb on lines 60..65
          app/controllers/personas_controller.rb on lines 88..93
          app/controllers/tipo_cargos_controller.rb on lines 60..65

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

          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