MiraitSystems/enju_trunk

View on GitHub
app/controllers/agents_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Method index has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    #session[:params] = {} unless session[:params]
    #session[:params][:agent] = params
    # 最近追加されたパトロン
    #@query = params[:query] ||= "[* TO *]"
Severity: Minor
Found in app/controllers/agents_controller.rb - About 6 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 index has 105 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    #session[:params] = {} unless session[:params]
    #session[:params][:agent] = params
    # 最近追加されたパトロン
    #@query = params[:query] ||= "[* TO *]"
Severity: Major
Found in app/controllers/agents_controller.rb - About 4 hrs to fix

    File agents_controller.rb has 296 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class AgentsController < ApplicationController
      add_breadcrumb "I18n.t('page.listing', :model => I18n.t('activerecord.models.agent'))", 'agents_path'
      add_breadcrumb "I18n.t('activerecord.models.agent')", 'agent_path(params[:id])', :only => [:show]
      add_breadcrumb "I18n.t('page.new', :model => I18n.t('activerecord.models.agent'))", 'new_agent_path', :only => [:new, :create]
      add_breadcrumb "I18n.t('page.editing', :model => I18n.t('activerecord.models.agent'))", 'edit_agent_path(params[:id])', :only => [:edit, :update]
    Severity: Minor
    Found in app/controllers/agents_controller.rb - About 3 hrs to fix

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

        def create
          @agent = Agent.new(params[:agent])
      
          if @agent.user_username
            @agent.user = User.find(@agent.user_username) rescue nil
      Severity: Minor
      Found in app/controllers/agents_controller.rb - About 1 hr to fix

        Method show has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def show
            unless @agent.user.blank?
              access_denied; return
            end
        
        
        Severity: Minor
        Found in app/controllers/agents_controller.rb - About 1 hr to fix

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

            def create
              @agent = Agent.new(params[:agent])
          
              if @agent.user_username
                @agent.user = User.find(@agent.user_username) rescue nil
          Severity: Minor
          Found in app/controllers/agents_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 new has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def new
              unless current_user.has_role?('Librarian')
                unless current_user == @user
                  access_denied; return
                end
          Severity: Minor
          Found in app/controllers/agents_controller.rb - About 1 hr to fix

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

              def show
                unless @agent.user.blank?
                  access_denied; return
                end
            
            
            Severity: Minor
            Found in app/controllers/agents_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

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

              def update
                respond_to do |format|
                  if @agent.update_attributes(params[:agent])
                    if params[:checked_item] == 'true'
                      flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.user_note'))
            Severity: Minor
            Found in app/controllers/agents_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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def new
                unless current_user.has_role?('Librarian')
                  unless current_user == @user
                    access_denied; return
                  end
            Severity: Minor
            Found in app/controllers/agents_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

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

              def destroy
                @agent.destroy
            
                respond_to do |format|
                  format.html { redirect_to agents_url, :notice => t('controller.successfully_deleted', :model => t('activerecord.models.agent')) }
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/accepts_controller.rb on lines 145..150

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

            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

                    @countalias = params[:agent][:agent_aliases_attributes].size
                    prepare_options
                    format.html { render :action => "edit" }
                    format.json { render :json => @agent.errors, :status => :unprocessable_entity }
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/agents_controller.rb on lines 295..298

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

            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

                    @countalias = params[:agent][:agent_aliases_attributes].size
                    prepare_options
                    format.html { render :action => "new" }
                    format.json { render :json => @agent.errors, :status => :unprocessable_entity }
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/agents_controller.rb on lines 317..320

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

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

                @manifestations = Manifestation.search do
                  with(:publisher_ids).equal_to agent.id
                  with(:required_role_id).less_than_or_equal_to role.id
                  paginate :page => params[:manifestation_list_page], :per_page => Manifestation.default_per_page
                end.results
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 2 other locations - About 15 mins to fix
            app/controllers/agents_controller.rb on lines 188..192
            app/controllers/agents_controller.rb on lines 193..197

            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

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

                @expressions = Manifestation.search do
                  with(:contributor_ids).equal_to agent.id
                  with(:required_role_id).less_than_or_equal_to role.id
                  paginate :page => params[:expression_list_page], :per_page => Manifestation.default_per_page
                end.results
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 2 other locations - About 15 mins to fix
            app/controllers/agents_controller.rb on lines 188..192
            app/controllers/agents_controller.rb on lines 198..202

            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

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

                @works = Manifestation.search do
                  with(:creator_ids).equal_to agent.id
                  with(:required_role_id).less_than_or_equal_to role.id
                  paginate :page => params[:work_list_page], :per_page => Manifestation.default_per_page
                end.results
            Severity: Minor
            Found in app/controllers/agents_controller.rb and 2 other locations - About 15 mins to fix
            app/controllers/agents_controller.rb on lines 193..197
            app/controllers/agents_controller.rb on lines 198..202

            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