Method date_field
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open
def date_field(name, value, datepicker_options = {}, html_options = {})
datepicker_options[:disabled] ||= false
datepicker_options[:alt_field] ||= ""
datepicker_options[:alt_format] ||= ""
datepicker_options[:append_text] ||= ""
- 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 date_field
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
def date_field(name, value, datepicker_options = {}, html_options = {})
datepicker_options[:disabled] ||= false
datepicker_options[:alt_field] ||= ""
datepicker_options[:alt_format] ||= ""
datepicker_options[:append_text] ||= ""
File forms_helper.rb
has 303 lines of code (exceeds 250 allowed). Consider refactoring. Open
module FormsHelper
include ButtonsHelper
include Entitlement::SliderHelper
def labelled_radio_button(human_name, name, value, checked = false, options = {})
Method select_city
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def select_city(simple = false)
states = State.order(:name).all
state_id = "state-" + FormsHelper.next_id_number
city_id = "city-" + FormsHelper.next_id_number
Method slider_field_tag
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def slider_field_tag(id, field_name, value, keys, labels, levels, range, html_options = {})
Method select_profile_folder
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def select_profile_folder(label_text, field_id, profile, default_value = "", html_options = {}, js_options = {}, find_options = {}, extra_options = {})
Method labelled_select
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def labelled_select(human_name, name, value_method, text_method, selected, collection, options = {})
Method date_range_field
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def date_range_field(from_name, to_name, from_value, to_value, datepicker_options = {}, html_options = {})
Method access_slider_field_tag
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def access_slider_field_tag(id, field_name, profile, value = slider_levels[:self], levels = Entitlement::Levels.range_options, html_options = {})
Method select_folder
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def select_folder(label_text, field_id, collection, default_value = nil, html_options = {}, js_options = {})
Method restriction_slider_field_tag
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def restriction_slider_field_tag(id, field_name, profile, value = slider_levels[:self], levels = Entitlement::Levels.range_options, html_options = {})
Method labelled_radio_button
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def labelled_radio_button(human_name, name, value, checked = false, options = {})
Method labelled_check_box
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def labelled_check_box(human_name, name, value = "1", checked = false, options = {})
Similar blocks of code found in 2 locations. Consider refactoring. Open
datepicker_options[:month_names_short] ||= [_("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"), _("Jul"), _("Aug"), _("Sep"), _("Oct"), _("Nov"), _("Dec")]
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 29.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
datepicker_options[:month_names] ||= [_("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"), _("August"), _("September"), _("October"), _("November"), _("December")]
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 29.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76