In my Rails app, I tried to run Rubocop to check for problems. It gave me an error like this : Assignment Branch Condition size for show is too high. Here's my code :
def create
@field = Api::AnalyticsQueryBuilderMetadataService::Field.create(field_params, { type: 'fields' })
if @field['message'].nil?
redirect_to fields_index_path(entityId: field_params[:entityId], entity_name: field_params[:entity_name], schemaId: field_params[:schemaId],
schemaMnemonic: field_params[:schemaMnemonic], schemaName: field_params[:schemaName])
else
flash[:notice] = @field
redirect_to new_field_path(entityId: field_params[:entityId], entity_name: field_params[:entity_name], schemaId: field_params[:schemaId],
schemaMnemonic: field_params[:schemaMnemonic], schemaName: field_params[:schemaName])
end
end
How to solve such error, this error is not affecting the user, but during Zenkin build, it fails, How to solve it.
'Assignment Branch Condition Size too high' is a linting error, produced by a tool performing static code analysis. It indicates that there are too many assignments, branches and conditionals in one method or function.
It is not an error in the sense that it will cause incorrect behavior when your code runs, rather it's a sign that your code is overly complex and may eventually suffer from maintainability issues.
You fix the error by refactoring your code, so that there are fewer assignments, branches and conditionals in the same method, or by ignoring the issue for code you believe is already optimal.