theforeman/foreman

View on GitHub

Showing 712 of 1,256 total issues

File audits_helper.rb has 365 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module AuditsHelper
  AUDIT_ADD = 'add'
  AUDIT_REMOVE = 'remove'

  # lookup the Model representing the numerical id and return its label
Severity: Minor
Found in app/helpers/audits_helper.rb - About 4 hrs to fix

    Method id_to_label has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

      def id_to_label(name, change, audit: @audit, truncate: true)
        return _("N/A") if change.nil?
        case name
          when "ancestry"
            label = change.blank? ? "" : change.split('/').map { |i| Hostgroup.find(i).name rescue _("N/A") }.join('/')
    Severity: Minor
    Found in app/helpers/audits_helper.rb - About 4 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

    File compute_resource.rb has 360 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ComputeResource < ApplicationRecord
      audited :except => [:attrs]
      include Taxonomix
      include Encryptable
      include Authorizable
    Severity: Minor
    Found in app/models/compute_resource.rb - About 4 hrs to fix

      Method try_to_login has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.try_to_login(login, password, api_request = false)
          # Make sure no one can sign in with an empty password
          return nil if password.to_s.empty?
      
          # user is already in local database
      Severity: Minor
      Found in app/models/user.rb - About 4 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

      Function get has 114 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        get: async url => {
          if (url === '/api/v2/roles?per_page=all&search=locked=false') {
            return {
              data: {
                total: 3,

        Class PuppetFactParser has 35 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class PuppetFactParser < FactParser
          attr_reader :facts
        
          def operatingsystem
            orel = os_release.dup
        Severity: Minor
        Found in app/services/puppet_fact_parser.rb - About 4 hrs to fix

          File subnet.rb has 353 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'ipaddr'
          
          class Subnet < ApplicationRecord
            audited
            IP_FIELDS = [:network, :mask, :gateway, :dns_primary, :dns_secondary, :from, :to]
          Severity: Minor
          Found in app/models/subnet.rb - About 4 hrs to fix

            File host_edit_interfaces.js has 352 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            $(document).ready(function() {
              $('#host_name').select();
              $('#host_name').focus();
            });
            
            
            Severity: Minor
            Found in app/assets/javascripts/host_edit_interfaces.js - About 4 hrs to fix

              Method set_taxonomy has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
              Open

                def set_taxonomy
                  TopbarSweeper.expire_cache
                  user = User.current
                  return if user.nil?
              
              
              Severity: Minor
              Found in app/controllers/concerns/application_shared.rb - About 4 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 FactParser has 33 methods (exceeds 20 allowed). Consider refactoring.
              Open

              class FactParser
                delegate :logger, :to => :Rails
                VIRTUAL = /\A([a-z0-9]+)[_|\.|:]([a-z0-9]+)\Z/
                BRIDGES = /\A(vir|lxc)?br(\d+|-[a-z0-9]+)(_nic)?\Z/
                BONDS = /\A(bond\d+)\Z|\A(lagg\d+)\Z/
              Severity: Minor
              Found in app/services/fact_parser.rb - About 4 hrs to fix

                Method details has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
                Open

                  def details(audit, path = audits_path(:search => "id=#{audit.id}"))
                    if audit.action == 'update'
                      return [] unless audit.audited_changes.present?
                      audit.audited_changes.map do |name, change|
                        next if change.nil? || change.to_s.empty?
                Severity: Minor
                Found in app/helpers/audits_helper.rb - About 4 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 Filter has 32 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class Filter < ApplicationRecord
                  audited :associated_with => :role
                
                  include Taxonomix
                  include Authorizable
                Severity: Minor
                Found in app/models/filter.rb - About 4 hrs to fix

                  File application_controller.rb has 331 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  class ApplicationController < ActionController::Base
                    include ApplicationShared
                  
                    include Foreman::Controller::Flash
                    include Foreman::Controller::Authorize
                  Severity: Minor
                  Found in app/controllers/application_controller.rb - About 3 hrs to fix

                    File lookup_keys.js has 330 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    //on load
                    $(document).on('ContentLoad', function() {
                      //select the first tab
                      select_first_tab();
                      $(document).on('click', '.nav-tabs a[data-toggle="tab"]', function() {
                    Severity: Minor
                    Found in app/assets/javascripts/lookup_keys.js - About 3 hrs to fix

                      File application_helper.rb has 328 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      module ApplicationHelper
                        def link_to_function(name, function, html_options = {})
                          onclick_tag = "#{html_options[:onclick]}; " if html_options[:onclick]
                          onclick = "#{onclick_tag}#{function}; return false;"
                          href = html_options[:href] || '#'
                      Severity: Minor
                      Found in app/helpers/application_helper.rb - About 3 hrs to fix

                        Method load has 95 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def self.load
                              Manager.map :header_menu
                        
                              Manager.map :side_menu do |menu|
                                menu.sub_menu :user_menu, :caption => N_('User'), :icon => 'fa fa-user' do
                        Severity: Major
                        Found in app/registries/menu/loader.rb - About 3 hrs to fix

                          Method setComputeDetails has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def setComputeDetails
                              if vm
                                attrs = compute_resource.provided_attributes
                          
                                attrs.each do |foreman_attr, fog_attr|
                          Severity: Minor
                          Found in app/models/concerns/orchestration/compute.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

                          File index.js has 322 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          /* eslint-disable max-lines */
                          import React, { createContext, useState } from 'react';
                          import { useHistory } from 'react-router-dom';
                          import { useSelector, useDispatch, shallowEqual } from 'react-redux';
                          import { Tr, Td, ActionsColumn } from '@patternfly/react-table';
                          Severity: Minor
                          Found in webpack/assets/javascripts/react_app/components/HostsIndex/index.js - About 3 hrs to fix

                            Class Setting has 30 methods (exceeds 20 allowed). Consider refactoring.
                            Open

                            class Setting < ApplicationRecord
                              audited :except => [:name]
                              extend FriendlyId
                              friendly_id :name
                              include ActiveModel::Validations
                            Severity: Minor
                            Found in app/models/setting.rb - About 3 hrs to fix

                              Class HostsController has 30 methods (exceeds 20 allowed). Consider refactoring.
                              Open

                                  class HostsController < V2::BaseController
                                    include Api::Version2
                                    include Api::V2::BulkHostsExtension
                                    include ScopesPerAction
                                    include Foreman::Controller::SmartProxyAuth
                              Severity: Minor
                              Found in app/controllers/api/v2/hosts_controller.rb - About 3 hrs to fix
                                Severity
                                Category
                                Status
                                Source
                                Language