Rails - FeatureEnvy: ApplicationHelper#full_title 引用 'page_title' 多于自身(也许将其移至另一个 class?)
Rails - FeatureEnvy: ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?)
我正在学习 Rails Michael Hartl 的课程,on chapter 4,
我的函数 full_title 如下:
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(一个代码审查工具),我收到警告:
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]
那么什么是 FeatureEnvy 以及在这种情况下如何解决它?
documentation of reek解释feature envy如下:
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.
在这种特殊情况下,我认为这个问题可以忽略。辅助方法很自然地接受参数并对其进行操作,而不是引用 self
,在这种情况下是视图对象。
如何从 reek 的分析中排除助手:
通过将此添加到 config.reek 文件,您应该能够排除所有帮助者检查是否符合 "feature envy" 规则:
"app/helpers":
FeatureEnvy:
enabled: false
我正在学习 Rails Michael Hartl 的课程,on chapter 4, 我的函数 full_title 如下:
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(一个代码审查工具),我收到警告:
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]
那么什么是 FeatureEnvy 以及在这种情况下如何解决它?
documentation of reek解释feature envy如下:
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.
在这种特殊情况下,我认为这个问题可以忽略。辅助方法很自然地接受参数并对其进行操作,而不是引用 self
,在这种情况下是视图对象。
如何从 reek 的分析中排除助手:
通过将此添加到 config.reek 文件,您应该能够排除所有帮助者检查是否符合 "feature envy" 规则:
"app/helpers":
FeatureEnvy:
enabled: false