coopdevs/timeoverflow

View on GitHub

Showing 12 of 14 total issues

Method global_activity has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def global_activity
    members = current_organization.members
    @active_members = members.active

    @total_hours = num_movements = 0
Severity: Minor
Found in app/controllers/statistics_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 global_activity has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def global_activity
    members = current_organization.members
    @active_members = members.active

    @total_hours = num_movements = 0
Severity: Minor
Found in app/controllers/statistics_controller.rb - About 1 hr to fix

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

      def create
        authorize User
    
        email = user_params[:email]
        @user = User.find_or_initialize_by(email: email) do |u|
    Severity: Minor
    Found in app/controllers/users_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

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

        def call(organization_id, csv_data)
          data = csv_data.read
          errors = []
    
          CSV.parse(data, headers: false) do |data_row|
    Severity: Major
    Found in app/services/post_importer.rb and 1 other location - About 1 hr to fix
    app/services/transfer_importer.rb on lines 50..68

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

        def call(organization_id, csv_data)
          data = csv_data.read
          errors = []
    
          CSV.parse(data, headers: false) do |data_row|
    Severity: Major
    Found in app/services/transfer_importer.rb and 1 other location - About 1 hr to fix
    app/services/post_importer.rb on lines 31..49

    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

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

        def find_account(id, type, organization_id, errors, direction)
    Severity: Minor
    Found in app/services/transfer_importer.rb - About 35 mins to fix

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

        def ensure_url
          return if web.blank? || URI.parse(web).is_a?(URI::HTTP)
        rescue
          errors.add(:web, :url_format_invalid)
        else
      Severity: Minor
      Found in app/models/organization.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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def update
          @user = User.find(params[:id])
          authorize @user unless @user == current_user
      
          if @user.update(user_params)
      Severity: Minor
      Found in app/controllers/users_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 3 locations. Consider refactoring.
      Open

        collection_action :import_csv, method: :post do
          errors = TransferImporter.call(params[:dump][:organization_id], params[:dump][:file])
          flash[:error] = errors.join("<br/>").html_safe if errors.present?
      
          redirect_to action: :index
      Severity: Minor
      Found in app/admin/transfer.rb and 2 other locations - About 35 mins to fix
      app/admin/post.rb on lines 10..15
      app/admin/user.rb on lines 12..17

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

        collection_action :import_csv, method: :post do
          errors = PostImporter.call(params[:dump][:organization_id], params[:dump][:file])
          flash[:error] = errors.join("<br/>").html_safe if errors.present?
      
          redirect_to action: :index
      Severity: Minor
      Found in app/admin/post.rb and 2 other locations - About 35 mins to fix
      app/admin/transfer.rb on lines 14..19
      app/admin/user.rb on lines 12..17

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

        collection_action :import_csv, method: :post do
          errors = UserImporter.call(params[:dump][:organization_id], params[:dump][:file])
          flash[:error] = errors.join("<br/>").html_safe if errors.present?
      
          redirect_to action: :index
      Severity: Minor
      Found in app/admin/user.rb and 2 other locations - About 35 mins to fix
      app/admin/post.rb on lines 10..15
      app/admin/transfer.rb on lines 14..19

      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

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

          def find_account(id, type, organization_id, errors, direction)
            acc = if type.downcase == 'organization'
                    Organization.find(organization_id).account
                  else
                    Member.find_by(member_uid: id, organization_id: organization_id)&.account
      Severity: Minor
      Found in app/services/transfer_importer.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

      Severity
      Category
      Status
      Source
      Language