SysMO-DB/seek

View on GitHub
app/controllers/avatars_controller.rb

Summary

Maintainability
B
4 hrs
Test Coverage

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

  def create
    unless params[:avatar].blank? || params[:avatar][:image_file].blank?
      file_specified = true
      
      # the creation of the new Avatar instance needs to have only one parameter - therefore, the rest should be set separately
Severity: Minor
Found in app/controllers/avatars_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 create has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    unless params[:avatar].blank? || params[:avatar][:image_file].blank?
      file_specified = true
      
      # the creation of the new Avatar instance needs to have only one parameter - therefore, the rest should be set separately
Severity: Minor
Found in app/controllers/avatars_controller.rb - About 1 hr to fix

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

      def find_avatar_auth
        # can show avatars to anyone (given that avatar ID belongs to the avatar owner in the URL);
        # for all other actions some validation is required
        unless self.action_name.to_s == "show"
          if @avatar_for.downcase == "person"
    Severity: Minor
    Found in app/controllers/avatars_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 find_avatars has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def find_avatars
        # all avatars for current object are only shown to the owner of the object OR to any admin (if the object is not an admin themself);
        # also, show avatars to all members of a project/institution
        if User.admin_logged_in? || (@avatar_owner_instance.class.name == "Person" && @avatar_for_id.to_i == current_user.person.id.to_i) ||
         (["Project", "Institution"].include?(@avatar_for) && @avatar_owner_instance.can_be_edited_by?(current_user))
    Severity: Minor
    Found in app/controllers/avatars_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

    There are no issues that match your filters.

    Category
    Status