app/inputs/upload_input.rb
Method icon_for
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
def icon_for(extension)
if ['zip', 'rar', '7z', '7zip', 'gzip'].include? extension
'file-archive-o'
elsif ['mp3', 'wav'].include? extension
'file-audio-o'
- Read upRead up
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 real_input_new
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
def real_input_new
template.content_tag :div, title: I18n.t('simple_form.inputs.upload.click_to_choose_a_file', attribute: raw_label_text), data: {placement: 'right'} do # We need another div around the whole thing, otherwise Bootstrap tooltip doesn't seem to work! See http://stackoverflow.com/questions/24497353/bootstrap-tooltip-isnt-shown-on-a-specific-element-but-it-seems-to-be-applied
template.content_tag :a, href: '#', class: ['fileinput-new', 'thumbnail'], data: {trigger: 'fileinput'} do
if file_available?
if ['jpg', 'jpeg', 'gif', 'png'].include? object.send(attribute_name).file.extension
- Read upRead up
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"