theforeman/foreman

View on GitHub

Showing 719 of 1,266 total issues

Method setup_roles! has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

      def setup_roles!
        return false if Foreman.in_setup_db_rake? || !permission_table_exists? || User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).nil?
        Role.without_auditing do
          Filter.without_auditing do
            default_roles.each do |name, permissions|
Severity: Minor
Found in app/registries/foreman/plugin/rbac_registry.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

Method auth_smart_proxy has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def auth_smart_proxy(proxies = SmartProxy.unscoped.all)
    request_hosts = nil
    if request.ssl?
      # If we have the client certficate in the request environment we can extract the dn and sans from there
      # if not we use the dn in the request environment
Severity: Minor
Found in app/controllers/concerns/foreman/controller/smart_proxy_auth.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

Function interface_subnet_selected has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function interface_subnet_selected(element, ip_field, skip_mac) {
  // mark the selected value to preserve it for form hiding
  preserve_selected_options($(element));

  if ($(element).attr('disabled')) return;
Severity: Major
Found in app/assets/javascripts/host_edit.js - About 3 hrs to fix

    File Editor.js has 293 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import React from 'react';
    import PropTypes from 'prop-types';
    import { ToastNotification } from 'patternfly-react';
    
    import { noop } from '../../common/helpers';
    Severity: Minor
    Found in webpack/assets/javascripts/react_app/components/Editor/Editor.js - About 3 hrs to fix

      File TableHooks.js has 292 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
      import { isEmpty } from 'lodash';
      import { useLocation } from 'react-router-dom';
      
      class ReactConnectedSet extends Set {

        Class TaxHost has 26 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class TaxHost
          FOREIGN_KEYS = [:location_id, :organization_id, :hostgroup_id,
                          :domain_id, :medium_id, :subnet_id,
                          :compute_resource_id, :realm_id, :ptable_id]
        
        
        Severity: Minor
        Found in app/services/tax_host.rb - About 3 hrs to fix

          Function ConfirmModal has 74 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const ConfirmModal = () => {
            const {
              id,
              isOpen,
              title,
          Severity: Major
          Found in webpack/assets/javascripts/react_app/components/ConfirmModal/index.js - About 2 hrs to fix

            Function methodSignature has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

            const methodSignature = (method, isSnippet) => {
              if (isEmpty(method.params)) return method.name;
            
              let currParam = 1;
              const params = method.params.map(p => {

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

                def parse_tags(args)
                  # Merge AWS EC2 tags
                  tags = {}
                  if (name = args[:name])
                    tags = {:Name => name}
            Severity: Minor
            Found in app/models/compute_resources/foreman/model/ec2.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

            File base.rb has 285 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            module Nic
              class Base < ApplicationRecord
                audited associated_with: :host
                prepend Foreman::STI
                include Encryptable
            Severity: Minor
            Found in app/models/nic/base.rb - About 2 hrs to fix

              File compute_resources_controller.rb has 285 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              module Api
                module V2
                  class ComputeResourcesController < V2::BaseController
                    include Api::Version2
                    include Foreman::Controller::Parameters::ComputeResource
              Severity: Minor
              Found in app/controllers/api/v2/compute_resources_controller.rb - About 2 hrs to fix

                Class ProvisioningTemplate has 25 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class ProvisioningTemplate < Template
                  audited
                  has_many :audits, :as => :auditable, :class_name => Audited.audit_class.name
                
                  include Authorizable
                Severity: Minor
                Found in app/models/provisioning_template.rb - About 2 hrs to fix

                  Class EC2 has 25 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                    class EC2 < ComputeResource
                      GOV_CLOUD_REGION = 'us-gov-west-1'
                  
                      include KeyPairComputeResource
                      delegate :flavors, :subnets, :to => :client
                  Severity: Minor
                  Found in app/models/compute_resources/foreman/model/ec2.rb - About 2 hrs to fix

                    Method dhcp_attrs has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def dhcp_attrs(record_mac)
                        raise ::Foreman::Exception.new(N_("DHCP not supported for this NIC")) unless dhcp?
                    
                        dhcp_attr = {
                          :name => dhcp_record_name(record_mac),
                    Severity: Minor
                    Found in app/models/concerns/orchestration/dhcp.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 build_pxe_default has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.build_pxe_default
                        return [:unprocessable_entity, _("No TFTP proxies defined, can't continue")] if (proxies = SmartProxy.with_features("TFTP")).empty?
                        error_msgs = []
                        used_templates = []
                        TemplateKind::PXE.each do |kind|
                    Severity: Minor
                    Found in app/models/provisioning_template.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 determine_os_type has a Cognitive Complexity of 20 (exceeds 5 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 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 find_or_create_external_user has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.find_or_create_external_user(attrs, auth_source_name)
                        external_groups = attrs.delete(:groups)
                        auth_source = AuthSource.find_by_name(auth_source_name.to_s)
                    
                        # existing user, we'll update them
                    Severity: Minor
                    Found in app/models/user.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 register_rails has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def register_rails
                          if enabled?
                            ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
                              event = ActiveSupport::Notifications::Event.new(*args)
                              controller = event.payload[:controller].underscore
                    Severity: Minor
                    Found in lib/foreman/telemetry.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 icon has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def icon(record, opts = {})
                        return "" if record.blank? || record.name.blank?
                        size = opts[:size] ||= '16x16'
                        name = case record.name.downcase
                               when /fedora|fcos|coreos/i
                    Severity: Major
                    Found in app/helpers/operatingsystems_helper.rb - About 2 hrs to fix

                      File libvirt.rb has 279 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      module Foreman::Model
                        class Libvirt < ComputeResource
                          include ComputeResourceConsoleCommon
                      
                          ALLOWED_DISPLAY_TYPES = %w(vnc spice)
                      Severity: Minor
                      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 2 hrs to fix
                        Severity
                        Category
                        Status
                        Source
                        Language