estimancy/projestimate

View on GitHub
app/controllers/organizations_controller.rb

Summary

Maintainability
F
2 wks
Test Coverage

Method create_organization_from_image has a Cognitive Complexity of 176 (exceeds 5 allowed). Consider refactoring.
Open

  def create_organization_from_image
    authorize! :manage, Organization

    case params[:action_name]
      #Duplicate organization
Severity: Minor
Found in app/controllers/organizations_controller.rb - About 3 days 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 execute_duplication has a Cognitive Complexity of 162 (exceeds 5 allowed). Consider refactoring.
Open

  def execute_duplication(project_id, new_organization_id)
    #begin
      old_prj = Project.find(project_id)
      new_organization = Organization.find(new_organization_id)

Severity: Minor
Found in app/controllers/organizations_controller.rb - About 3 days 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

File organizations_controller.rb has 852 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class OrganizationsController < ApplicationController
  load_resource
  require 'rubygems'
  require 'securerandom'
  include ProjectsHelper
Severity: Major
Found in app/controllers/organizations_controller.rb - About 2 days to fix

    Method create_organization_from_image has 206 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create_organization_from_image
        authorize! :manage, Organization
    
        case params[:action_name]
          #Duplicate organization
    Severity: Major
    Found in app/controllers/organizations_controller.rb - About 1 day to fix

      Method execute_duplication has 157 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def execute_duplication(project_id, new_organization_id)
          #begin
            old_prj = Project.find(project_id)
            new_organization = Organization.find(new_organization_id)
      
      
      Severity: Major
      Found in app/controllers/organizations_controller.rb - About 6 hrs to fix

        Method generate_report has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          def generate_report
        
            conditions = Hash.new
            params[:report].each do |i|
              unless i.last.blank? or i.last.nil?
        Severity: Minor
        Found in app/controllers/organizations_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

        Class OrganizationsController has 29 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class OrganizationsController < ApplicationController
          load_resource
          require 'rubygems'
          require 'securerandom'
          include ProjectsHelper
        Severity: Minor
        Found in app/controllers/organizations_controller.rb - About 3 hrs to fix

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

            def create
              authorize! :create_organizations, Organization
          
              @organization = Organization.new(params[:organization])
          
          
          Severity: Major
          Found in app/controllers/organizations_controller.rb - About 2 hrs to fix

            Method generate_report has 64 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def generate_report
            
                conditions = Hash.new
                params[:report].each do |i|
                  unless i.last.blank? or i.last.nil?
            Severity: Major
            Found in app/controllers/organizations_controller.rb - About 2 hrs to fix

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

                def import_user
                  sep = "#{params[:separator].blank? ? I18n.t(:general_csv_separator) : params[:separator]}"
                  error_count = 0
                  file = params[:file]
                  encoding = params[:encoding]
              Severity: Minor
              Found in app/controllers/organizations_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 import_user has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def import_user
                  sep = "#{params[:separator].blank? ? I18n.t(:general_csv_separator) : params[:separator]}"
                  error_count = 0
                  file = params[:file]
                  encoding = params[:encoding]
              Severity: Minor
              Found in app/controllers/organizations_controller.rb - About 1 hr to fix

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

                  def update
                    authorize! :edit_organizations, Organization
                
                    @organization = Organization.find(params[:id])
                    if @organization.update_attributes(params[:organization])
                Severity: Minor
                Found in app/controllers/organizations_controller.rb - About 1 hr to fix

                  Method set_technology_size_type_abacus has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def set_technology_size_type_abacus
                      authorize! :edit_organizations, Organization
                  
                      @organization = Organization.find(params[:organization])
                      @technologies = @organization.organization_technologies
                  Severity: Minor
                  Found in app/controllers/organizations_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 set_technology_size_type_abacus has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def set_technology_size_type_abacus
                      authorize! :edit_organizations, Organization
                  
                      @organization = Organization.find(params[:organization])
                      @technologies = @organization.organization_technologies
                  Severity: Minor
                  Found in app/controllers/organizations_controller.rb - About 1 hr to fix

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

                      def set_technology_size_unit_abacus
                        authorize! :edit_organizations, Organization
                    
                        @organization = Organization.find(params[:organization])
                        @technologies = @organization.organization_technologies
                    Severity: Minor
                    Found in app/controllers/organizations_controller.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

                    Avoid deeply nested control flow statements.
                    Open

                                  unless new_group.nil?
                                    new_group.users = group.users
                                    new_group.save
                                  end
                    Severity: Major
                    Found in app/controllers/organizations_controller.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                        estimation_value_id = new_estimation_value.nil? ? nil : new_estimation_value.id
                      Severity: Major
                      Found in app/controllers/organizations_controller.rb - About 45 mins to fix

                        Method destroy has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def destroy
                            authorize! :manage, Organization
                        
                            @organization = Organization.find(params[:id])
                            @organization_id = @organization.id
                        Severity: Minor
                        Found in app/controllers/organizations_controller.rb - About 45 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 deeply nested control flow statements.
                        Open

                                              unless ancestor.nil?
                                                ancestor_id = ancestor.id
                                                new_ancestor_ids_list.push(ancestor_id)
                                              end
                        Severity: Major
                        Found in app/controllers/organizations_controller.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                            unless pf.nil?
                                              new_field = new_organization.fields.where(copy_id: pf.field_id).first
                                              pf.views_widget_id = widget_copy.id
                                              pf.field_id = new_field.nil? ? nil : new_field.id
                                              pf.save
                          Severity: Major
                          Found in app/controllers/organizations_controller.rb - About 45 mins to fix

                            Method update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def update
                                authorize! :edit_organizations, Organization
                            
                                @organization = Organization.find(params[:id])
                                if @organization.update_attributes(params[:organization])
                            Severity: Minor
                            Found in app/controllers/organizations_controller.rb - About 25 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

                                      new_mp.guw_unit_of_work_groups.each do |guw_group|
                                        new_pbs_project_element = new_prj_components.find_by_copy_id(guw_group.pbs_project_element_id)
                                        new_pbs_project_element_id = new_pbs_project_element.nil? ? nil : new_pbs_project_element.id
                            
                                        #technology
                            Severity: Major
                            Found in app/controllers/organizations_controller.rb and 1 other location - About 5 hrs to fix
                            app/workers/organization_duplicate_project_worker.rb on lines 174..226

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

                            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 old_mp.view
                                        old_mp_view_widgets = old_mp.view.views_widgets.all
                                        old_mp_view_widgets.each do |view_widget|
                                          new_view_widget_mp = ModuleProject.find_by_project_id_and_copy_id(new_prj.id, view_widget.module_project_id)
                                          new_view_widget_mp_id = new_view_widget_mp.nil? ? nil : new_view_widget_mp.id
                            Severity: Major
                            Found in app/controllers/organizations_controller.rb and 2 other locations - About 4 hrs to fix
                            app/workers/organization_duplicate_project_worker.rb on lines 142..163
                            app/workers/organization_duplicate_project_worker.rb on lines 368..389

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

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

                                      ["input", "output"].each do |io|
                                        new_mp.pemodule.pe_attributes.each do |attr|
                                          old_prj.pbs_project_elements.each do |old_component|
                                            new_prj_components.each do |new_component|
                                              ev = new_mp.estimation_values.where(pe_attribute_id: attr.id, in_out: io).first
                            Severity: Major
                            Found in app/controllers/organizations_controller.rb and 5 other locations - About 2 hrs to fix
                            app/controllers/projects_controller.rb on lines 1580..1590
                            app/controllers/projects_controller.rb on lines 1956..1966
                            app/models/project.rb on lines 402..412
                            app/workers/organization_duplicate_project_worker.rb on lines 248..258
                            app/workers/organization_duplicate_project_worker.rb on lines 423..433

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

                            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

                                    new_prj.project_securities.where('group_id IS NOT NULL').each do |project_security|
                                      new_security_level = new_organization.project_security_levels.where(copy_id: project_security.project_security_level_id).first
                                      new_group = new_organization.groups.where(copy_id: project_security.group_id).first
                                      if new_security_level.nil? || new_group.nil?
                                        project_security.destroy
                            Severity: Major
                            Found in app/controllers/organizations_controller.rb and 2 other locations - About 50 mins to fix
                            app/workers/organization_duplicate_project_worker.rb on lines 92..99
                            app/workers/organization_duplicate_project_worker.rb on lines 324..331

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

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

                                    new_prj_components.each do |new_c|
                                      new_ancestor_ids_list = []
                                      new_c.ancestor_ids.each do |ancestor_id|
                                        ancestor_id = PbsProjectElement.find_by_pe_wbs_project_id_and_copy_id(new_c.pe_wbs_project_id, ancestor_id).id
                                        new_ancestor_ids_list.push(ancestor_id)
                            Severity: Minor
                            Found in app/controllers/organizations_controller.rb and 3 other locations - About 25 mins to fix
                            app/models/project.rb on lines 324..331
                            app/workers/organization_duplicate_project_worker.rb on lines 73..80
                            app/workers/organization_duplicate_project_worker.rb on lines 305..312

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

                            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

                                    new_prj.project_securities.where('user_id IS NOT NULL').each do |project_security|
                                      new_security_level = new_organization.project_security_levels.where(copy_id: project_security.project_security_level_id).first
                                      if new_security_level.nil?
                                        project_security.destroy
                                      else
                            Severity: Minor
                            Found in app/controllers/organizations_controller.rb and 2 other locations - About 20 mins to fix
                            app/workers/organization_duplicate_project_worker.rb on lines 103..108
                            app/workers/organization_duplicate_project_worker.rb on lines 335..340

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

                            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

                                        unless new_wbs_activity.nil?
                                          new_wbs_activity_ratio = new_wbs_activity.wbs_activity_ratios.where(copy_id: activity_input.wbs_activity_ratio_id).first
                                          unless new_wbs_activity_ratio.nil?
                                            activity_input.update_attributes(wbs_activity_id: new_wbs_activity.id, wbs_activity_ratio_id: new_wbs_activity_ratio.id)
                            Severity: Minor
                            Found in app/controllers/organizations_controller.rb and 1 other location - About 15 mins to fix
                            app/workers/organization_duplicate_project_worker.rb on lines 240..243

                            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