chef/supermarket

View on GitHub

Showing 47 of 47 total issues

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

$(document).on('opened', '[data-reveal]', function () {
  var settings =  {
    placeholder: 'Search for a collaborator',
    minimumInputLength: 3,
    width: '100%',
Severity: Major
Found in src/supermarket/app/assets/javascripts/collaborators.js and 1 other location - About 1 day to fix
src/supermarket/app/assets/javascripts/group_members.js on lines 1..33

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

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

$(document).on('opened', '#group-members[data-reveal]', function () {
  var settings =  {
    placeholder: 'Search for a user',
    minimumInputLength: 3,
    width: '100%',
Severity: Major
Found in src/supermarket/app/assets/javascripts/group_members.js and 1 other location - About 1 day to fix
src/supermarket/app/assets/javascripts/collaborators.js on lines 1..33

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

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

File schema.rb has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

ActiveRecord::Schema.define(version: 20170203223651) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"
  enable_extension "pg_trgm"
Severity: Minor
Found in src/supermarket/db/schema.rb - About 5 hrs to fix

    Method follow_button_for has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def follow_button_for(cookbook, params = {}, &block)
        fa_icon = content_tag(:i, '', class: 'fa fa-users')
        followers_count = cookbook.cookbook_followers_count.to_s
        followers_count_span = content_tag(
          :span,
    Severity: Major
    Found in src/supermarket/app/helpers/cookbooks_helper.rb - About 2 hrs to fix

      Class QualityMetricsController has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Api::V1::QualityMetricsController < Api::V1Controller
        before_action :check_cookbook_name_present, except: :license_evaluation
        before_action :check_authorization, except: :license_evaluation
        before_action :find_cookbook_version, except: :license_evaluation
      
      
      Severity: Minor
      Found in src/supermarket/app/controllers/api/v1/quality_metrics_controller.rb - About 2 hrs to fix

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

          def follow_button_for(cookbook, params = {}, &block)
            fa_icon = content_tag(:i, '', class: 'fa fa-users')
            followers_count = cookbook.cookbook_followers_count.to_s
            followers_count_span = content_tag(
              :span,
        Severity: Minor
        Found in src/supermarket/app/helpers/cookbooks_helper.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 publish_version! has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def publish_version!(params, user)
            metadata = params.metadata
        
            if metadata.privacy &&
               ENV['ENFORCE_PRIVACY'].present? &&
        Severity: Minor
        Found in src/supermarket/app/models/cookbook.rb - About 1 hr to fix

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

          class ContributingFileWorker < SourceRepoWorker
            include ::Sidekiq::Worker
          
            def perform(cookbook_json, cookbook_name)
              evaluate_result = evaluate(cookbook_json)
          src/supermarket/engines/fieri/app/models/testing_file_worker.rb on lines 5..45

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

          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

          class TestingFileWorker < SourceRepoWorker
            include ::Sidekiq::Worker
          
            def perform(cookbook_json, cookbook_name)
              evaluate_result = evaluate(cookbook_json)
          src/supermarket/engines/fieri/app/models/contributing_file_worker.rb on lines 5..45

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

          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 show has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def show
                redis_health = { status: REACHABLE }
                sidekiq_health = { status: REACHABLE }
          
                begin

            Method authenticate_user! has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def authenticate_user!
                username = request.headers['X-Ops-Userid']
                user = Account.for('chef_oauth2').where(username: username).first.try(:user)
            
                unless user

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

                  def each_entry
                    raise NoPath unless @source.respond_to?(:path)
                    raise NotGzipped unless gzipped?
              
                    begin
              Severity: Minor
              Found in src/supermarket/app/models/cookbook_upload/archive.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

              $(function() {
                $('a[rel~="remove_collaboration"]').on('ajax:success', function(e, data, status, xhr) {
                  $(this).closest('tr').remove();
                });
              });
              Severity: Major
              Found in src/supermarket/app/assets/javascripts/groups.js and 1 other location - About 1 hr to fix
              src/supermarket/app/assets/javascripts/collaborators.js on lines 35..39

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

              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 generate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def generate(opts = {})
                  #
                  # So yeah, why are we using SQL here instead of our friend ActiveRecord?
                  # Turns out, when you're retrieving a lot of objects at once, and joining
                  # objects on foreign keys, AR is really slow - prohibitively slow for what
              Severity: Minor
              Found in src/supermarket/app/models/universe.rb - About 1 hr to fix

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

                $(function() {
                  $('a[rel~="remove_collaboration"]').on('ajax:success', function(e, data, status, xhr) {
                    $(this).closest('tr').remove();
                  });
                });
                Severity: Major
                Found in src/supermarket/app/assets/javascripts/collaborators.js and 1 other location - About 1 hr to fix
                src/supermarket/app/assets/javascripts/groups.js on lines 33..37

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

                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 versions_string has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def versions_string(versions)
                    versions_string = ''
                
                    if versions.first.class == Array
                      versions.each do |version_set|
                Severity: Minor
                Found in src/supermarket/app/helpers/cookbook_versions_helper.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 perform has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def perform(account_id)
                    account = Account.find(account_id)
                
                    strategy = OmniAuth::Strategies::ChefOAuth2.new(
                      Rails.application,
                Severity: Minor
                Found in src/supermarket/app/workers/oauth_token_refresh_worker.rb - About 1 hr to fix

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

                    def create
                      cookbook_upload = CookbookUpload.new(current_user, upload_params)
                  
                      begin
                        authorize! cookbook_upload.cookbook

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

                      def update
                        @user = current_user
                    
                        authorize! @tool
                    
                    
                    Severity: Minor
                    Found in src/supermarket/app/controllers/tools_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 create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def create
                        cookbook_upload = CookbookUpload.new(current_user, upload_params)
                    
                        begin
                          authorize! cookbook_upload.cookbook
                    Severity: Minor
                    Found in src/supermarket/app/controllers/api/v1/cookbook_uploads_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

                    Severity
                    Category
                    Status
                    Source
                    Language