app/models/manageiq/providers/openstack/identity_sync_mixin.rb
Method create_or_find_miq_group_and_add_user
has a Cognitive Complexity of 23 (exceeds 11 allowed). Consider refactoring. Open
Open
def create_or_find_miq_group_and_add_user(user, tenant, role_name)
# Find MiqGroup corresponding to this role and project/tenant
# create one if it doesn't exist
# add user to the MiqGroup
admin_role_id = ext_management_system.miq_custom_get(IDENTITY_SYNC_ADMIN_ROLE_ID_NEW)
- Read upRead up
- Create a ticketCreate a ticket
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
Avoid more than 3 levels of block nesting. Open
Open
if description_errors.size == 1 && description_errors[0].starts_with?("is not unique")
# A group with this description already exists, probably because a user previously changed
# the associated role. Create a timestamped description to ensure uniqueness
miq_group.description = create_group_name(ext_management_system, tenant, this_role, true)
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.