简体   繁体   中英

Rails - FeatureEnvy: ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?)

I'm learning Rails course by Michael Hartl, on chapter 4 , I have function full_title as following:

app/helpers/application_helper.rb

module ApplicationHelper
  def full_title page_title = ""
    base_title = t "app_name"
    page_title.empty? ? base_title : page_title + " | " + base_title
  end
end

Runing reek (a code review tool), I got a warning:

app/helpers/application_helper.rb -- 1 warning:
  [4, 4]:FeatureEnvy: ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]

So what is FeatureEnvy and how to fix it in this case?

The documentation of reek explains feature envy as follows:

Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

In this particular case, I believe this issue can be ignored. It is natural for helper methods to take arguments and operate on those, instead of referencing self , which is the view object in this case.

How to exclude helpers from reek's analysis:

You should be able to exclude all helpers from being checked for compliance with the "feature envy" rule by adding this to theconfig.reek file:

"app/helpers":
  FeatureEnvy:
    enabled: false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM