theforeman/foreman

View on GitHub

Showing 722 of 1,271 total issues

Method os_name has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def os_name
    # Facter 2.2 introduced the os fact
    os_name = facts.dig(:os, :name).presence || facts[:operatingsystem].presence || raise(::Foreman::Exception.new("invalid facts, missing operating system value"))
    # CentOS Stream doesn't have a minor version so it's good to check it at two places according to version of Facter that produced facts
    has_no_minor = facts[:lsbdistrelease]&.exclude?('.') || (facts.dig(:os, :name).presence && facts.dig(:os, :release, :minor).nil?)
Severity: Minor
Found in app/services/puppet_fact_parser.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 to_bool has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def self.to_bool(value)
      case value

      when String
        return true if value =~ /\A(true|t|yes|y|on|1)\z/i
Severity: Minor
Found in app/services/foreman/cast.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 validate_each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    return if options[:allow_blank] && value.empty?
    record.errors.add(attribute, _("is too long (maximum is 254 characters)")) if value && value.length > 254
    begin
      address = value.split("@")
Severity: Minor
Found in app/validators/email_validator.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

Function handleMenuKeys has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    const handleMenuKeys = event => {
      // keyboard shortcut to focus the search, will not focus if the key is typed into an input
      if (
        event.key === '/' &&
        event.target.tagName !== 'INPUT' &&

    Function createOrgItem has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const createOrgItem = orgs => {
      const anyOrg = {
        name: 'Any Organization',
        title: __('Any Organization'),
        onClick: () => {

      Function createLocationItem has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const createLocationItem = locations => {
        const anyLoc = {
          name: 'Any Location',
          title: __('Any Location'),
          onClick: () => {

        Method try_to_auto_create_user has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.try_to_auto_create_user(login, password)
            return if login.blank? || password.blank?
            # User is not yet registered, try to authenticate with available sources
            logger.debug "Attempting to log into an auth source as #{login} for account auto-creation"
            return unless (attrs = AuthSource.authenticate(login, password))
        Severity: Minor
        Found in app/models/user.rb - About 1 hr to fix

          Method normalize_vm_attrs has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def normalize_vm_attrs(vm_attrs)
                normalized = slice_vm_attributes(vm_attrs, ['availability_zone', 'tenant_id', 'scheduler_hint_filter'])
          
                normalized['flavor_id'] = vm_attrs['flavor_ref']
                normalized['flavor_name'] = flavors.detect { |t| t.id == normalized['flavor_id'] }.try(:name)
          Severity: Minor
          Found in app/models/compute_resources/foreman/model/openstack.rb - About 1 hr to fix

            Method update_multiple_proxy has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def update_multiple_proxy(proxy_type, host_update_method)
                proxy_id = params[:proxy][:proxy_id]
                if proxy_id
                  proxy = SmartProxy.find_by_id(proxy_id)
                else

              Method field has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def field(f, attr, options = {}, &block)
                  table_field = options.delete(:table_field)
                  error       = options.delete(:error) || get_attr_error(f, attr)
                  help_inline = help_inline(options.delete(:help_inline), error)
                  help_inline += options[:help_inline_permanent] unless options[:help_inline_permanent].nil?
              Severity: Minor
              Found in app/helpers/form_helper.rb - About 1 hr to fix

                Method update_multiple_proxy has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def update_multiple_proxy(proxy_type, host_update_method)
                    proxy_id = params[:proxy][:proxy_id]
                    if proxy_id
                      proxy = SmartProxy.find_by_id(proxy_id)
                    else
                Severity: Minor
                Found in app/controllers/hosts_controller.rb - About 1 hr to fix

                  Method normalize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def normalize(facts)
                      max = Setting[:maximum_structured_facts]
                      flat_counts = {}
                      dropped = 0
                      # Remove empty values first, so nil facts added by flatten_composite imply compose
                  Severity: Minor
                  Found in app/services/structured_fact_importer.rb - About 1 hr to fix

                    Function disableButtonToggle has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function disableButtonToggle(item, explicit) {
                      if (explicit === undefined) {
                        explicit = true;
                      }
                    
                    
                    Severity: Minor
                    Found in app/assets/javascripts/application.js - About 1 hr to fix

                      Function networkSelected has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function networkSelected(item) {
                        const selected = $(item).val();
                        const bridge = $(item)
                          .parentsUntil('.fields')
                          .parent()
                      Severity: Minor
                      Found in webpack/assets/javascripts/compute_resource/libvirt.js - About 1 hr to fix

                        Function vnicSelected has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        export function vnicSelected(item) {
                          const selectedVnicProfile = $(item).val();
                          if (selectedVnicProfile) {
                            const itemId = $(item).attr('id');
                            const nicId = itemId.match(/_([0-9]*)_vnic_profile/)[1];
                        Severity: Minor
                        Found in webpack/assets/javascripts/compute_resource/ovirt.js - About 1 hr to fix

                          Function i18nProviderWrapperFactory has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          ) => WrappedComponent => {
                            const wrappedName = getDisplayName(WrappedComponent);
                          
                            class I18nProviderWrapper extends React.Component {
                              constructor(props) {

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

                                def clone_vm(raw_args)
                                  args = parse_args(raw_args)
                            
                                  opts = {
                                    "datacenter" => datacenter,
                            Severity: Minor
                            Found in app/models/compute_resources/foreman/model/vmware.rb - About 1 hr to fix

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

                                  def determine_os_type(host)
                                    return nil unless host
                                    return host.params['ovirt_ostype'] if host.params['ovirt_ostype']
                                    ret = "other_linux"
                                    return ret unless host.operatingsystem
                              Severity: Minor
                              Found in app/models/compute_resources/foreman/model/ovirt.rb - About 1 hr to fix

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

                                    def add_nic_base_params_filter(filter)
                                      filter.permit_by_context :attached_devices, # accepts string or array
                                        :attached_to,
                                        :bond_options,
                                        :host, :host_id,
                                Severity: Minor
                                Found in app/controllers/concerns/foreman/controller/parameters/nic_base.rb - About 1 hr to fix

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

                                      def deliver!
                                        # This is a noop every time rss_enable=false, the moment it
                                        # gets enabled, notifications for RSS feeds are created again
                                        return true unless Setting[:rss_enable]
                                        rss_feed = load_rss_feed
                                  Severity: Minor
                                  Found in app/services/ui_notifications/rss_notifications_checker.rb - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language