9. Whole
Team
Collective Coding
Ownership Standard
Test-Driven
Development
Customer Pair Design Planning
Tests Programming Improvement Game
Simple
Design
Continuous Sustainable
Integration Pace
Metaphor
Small
Releases
circa 2001. duplicated from xprogramming.com
10. Collective Coding
Ownership Standard
Test-Driven
Development
Pair Design
Programming Improvement
Simple
Design
Continuous Sustainable
Integration Pace
circa 2001. duplicated from xprogramming.com
29. ~/Data/runway $ find app -name quot;*.rbquot; | xargs reek
quot;app/controllers/actions_controller.rbquot; -- 3 warnings:
ActionsController#action calls current_user.actions multiple times
(Duplication)
ActionsController#action calls params[id] multiple times (Duplication)
ActionsController#actions calls current_user.actions multiple times
(Duplication)
quot;app/controllers/application.rbquot; -- 1 warnings:
ApplicationController#site_version doesn't depend on instance state
(Utility Function)
quot;app/helpers/home_helper.rbquot; -- 1 warnings:
HomeHelper::folder_tab has approx 6 statements (Long Method)
quot;app/models/token.rbquot; -- 21 warnings:
Token#parse_incubation_day_of_the_month refers to base more than self
(Feature Envy)
30. ActionsController#action calls current_user.actions multiple times
(Duplication)
ActionsController#action calls params[id] multiple times (Duplication)
ActionsController#actions calls current_user.actions multiple times
(Duplication)
quot;app/controllers/application.rbquot; -- 1 warnings:
ApplicationController#site_version doesn't depend on instance state
(Utility Function)
quot;app/helpers/home_helper.rbquot; -- 1 warnings:
HomeHelper::folder_tab has approx 6 statements (Long Method)
quot;app/models/token.rbquot; -- 21 warnings:
Token#parse_incubation_day_of_the_month refers to base more than self
(Feature Envy)
31. [Feature Envy] Element#update_from refers to
response more than self
def parse_incubation_day_of_the_month
if @remainder =~ /^(d+)(th|st|nd|rd)$/i
day = $1.to_i
base = day <= @today.day ? @today >> 1 : @today
day -=1 until Date.valid_civil?(base.year, base.month, day)
Date.new(base.year, base.month, day)
end
end
59. ~/Data/runway $ flay app
[Processing files...]
Total score (lower is better) = 286
1) Similar code found in :defn (mass = 60)
app/controllers/signups_controller.rb:5
app/controllers/user_sessions_controller.rb:6
2) Similar code found in :if (mass = 54)
app/controllers/forgot_passwords_controller.rb:15
app/controllers/signups_controller.rb:16
3) Similar code found in :defn (mass = 50)
app/helpers/actions_helper.rb:43
app/helpers/actions_helper.rb:49
[More content removed...]
60. ~/Data/runway $ flay app
[Processing files...]
Total score (lower is better) = 286
1) Similar code found in :defn (mass = 60)
app/controllers/signups_controller.rb:5
app/controllers/user_sessions_controller.rb:6
2) Similar code found in :if (mass = 54)
app/controllers/forgot_passwords_controller.rb:15
app/controllers/signups_controller.rb:16
3) Similar code found in :defn (mass = 50)
app/helpers/actions_helper.rb:43
app/helpers/actions_helper.rb:49
[More content removed...]
61. 1) Similar code found in :defn (mass = 60)
app/controllers/signups_controller.rb:5
app/controllers/user_sessions_controller.rb:6
def create
user = User.new(params[:signup])
if user.save
head(:status => :created, :location => home_path)
else
head(:status => :unprocessable_entity)
end
end
def create
user_session = UserSession.new(params[:user_session])
if user_session.save
head(:status => :created, :location => home_path)
else
head(:status => :unprocessable_entity)
end
end
69. lib/tasks/quality.rake
require 'flay'
desc quot;Analyze for code duplicationquot;
task :flay do
threshold = 25
flay = Flay.new({:fuzzy => false, :verbose => false, :mass =>
threshold})
flay.process(*Flay.expand_dirs_to_files(['app']))
flay.report
raise quot;#{flay.masses.size} chunks of code have a duplicate mass >
#{threshold}quot; unless flay.masses.empty?
end
70. ~/Data/runway $ rake flay
(in /Users/marty/Data/runway)
Total score (lower is better) = 164
1) Similar code found in :defn (mass = 60)
app/controllers/signups_controller.rb:5
app/controllers/user_sessions_controller.rb:6
2) Similar code found in :if (mass = 54)
app/controllers/forgot_passwords_controller.rb:15
app/controllers/signups_controller.rb:16
3) Similar code found in :defn (mass = 50)
app/helpers/actions_helper.rb:43
app/helpers/actions_helper.rb:49
rake aborted!
3 chunks of code have a duplicate mass > 25
74. Class Name Block Cyclomatic Complexity
Method Name Method Cyclomatic
Complexity
Module Name
Assignment In Conditional
Class Line Count
Case Missing Else
Method Line Count
Empty Rescue Body
Module Line Count
For Loop Check
Parameter Number
77. ~/Data/runway $ roodi quot;app/**/*.rbquot;
app/models/action_format.rb:10
Method name quot;formatquot; has a cyclomatic complexity is 12.
It should be 8 or less.
app/models/action_parser.rb:50
Block cyclomatic complexity is 11.
It should be 4 or less.
app/models/action.rb:107
Case statement is missing an else clause.
app/models/action.rb:103
Method quot;apply_defaults_from_namequot; has 23 lines.
It should have 20 or less.
app/controllers/application.rb:52
Found = in conditional.
It should probably be an ==
78. Method name quot;formatquot; has a cyclomatic complexit
It should be 8 or less.
app/models/action_parser.rb:50
Block cyclomatic complexity is 11.
It should be 4 or less.
app/models/action.rb:107
Case statement is missing an else clause.
app/models/action.rb:103
Method quot;apply_defaults_from_namequot; has 23 lines.
It should have 20 or less.
app/controllers/application.rb:52
Found = in conditional.
It should probably be an ==
79. app/models/action_parser.rb:50
Block cyclomatic complexity is 11.
It should be 4 or less.
meta.each do |token|
case token.klass
when :context
unless token.value.blank?
@contexts ||= []
@contexts << token.value
end
when :time
@time = token.value
when :energy
@energy = token.value
when :tag
@tags << token.value unless token.value.blank?
when :semi_colon
# Ignore
when :available, :today, :later, :done
@status = token.klass.to_s
@effective_at = token.value
when :due_at
@due_at = token.value
end
end
80. app/models/action_parser.rb:50
Block cyclomatic complexity is 11.
It should be 4 or less.
1 meta.each do |token|
case token.klass
2 when :context
3 unless token.value.blank?
@contexts ||= [] 4
@contexts << token.value
end
5 when :time
@time = token.value
6 when :energy
@energy = token.value
7 8
when :tag
@tags << token.value unless token.value.blank?
9 when :semi_colon
# Ignore
10 when :available, :today, :later, :done
@status = token.klass.to_s
@effective_at = token.value
11 when :due_at
@due_at = token.value
end
end
81. app/controllers/application.rb:52
Found = in conditional.
It should probably be an ==
def extract_authenticity_token
if token = request.headers[quot;HTTP_X_RUNWAY_AUTHENTICITY_TOKENquot;]
params[request_forgery_protection_token] = token
end
end
85. def match(conditions)
conditions = validate_conditions(conditions)
# check content of child nodes
if conditions[:content]
if children.empty?
return false unless match_condition(quot;quot;, conditions[:content])
else
return false unless children.find { |child| child.match(conditions[:content]) }
end
end
# test the name
return false unless match_condition(@name, conditions[:tag]) if conditions[:tag]
# test attributes
(conditions[:attributes] || {}).each do |key, value|
return false unless match_condition(self[key], value)
end
# test parent
return false unless parent.match(conditions[:parent]) if conditions[:parent]
# test children
return false unless children.find { |child| child.match(conditions[:child]) } if conditio
# test ancestors
if conditions[:ancestor]
return false unless catch :found do
p = self
throw :found, true if p.match(conditions[:ancestor]) while p = p.parent
end
end
# test descendants
86. # test descendants
if conditions[:descendant]
return false unless children.find do |child|
# test the child
child.match(conditions[:descendant]) ||
# test the child's descendants
child.match(:descendant => conditions[:descendant])
end
end
# count children
if opts = conditions[:children]
matches = children.select do |c|
(c.kind_of?(HTML::Tag) and (c.closing == :self or ! c.childless?))
end
matches = matches.select { |c| c.match(opts[:only]) } if opts[:only]
opts.each do |key, value|
next if key == :only
case key
when :count
if Integer === value
return false if matches.length != value
else
return false unless value.include?(matches.length)
end
when :less_than
return false unless matches.length < value
when :greater_than
return false unless matches.length > value
else raise quot;unknown count condition #{key}quot;
end
end
end
87. else raise quot;unknown count condition #{key}quot;
end
end
end
# test siblings
if conditions[:sibling] || conditions[:before] || conditions[:after]
siblings = parent ? parent.children : []
self_index = siblings.index(self)
if conditions[:sibling]
return false unless siblings.detect do |s|
s != self && s.match(conditions[:sibling])
end
end
if conditions[:before]
return false unless siblings[self_index+1..-1].detect do |s|
s != self && s.match(conditions[:before])
end
end
if conditions[:after]
return false unless siblings[0,self_index].detect do |s|
s != self && s.match(conditions[:after])
end
end
end
true
end
91. ~/Data/runway $ rake roodi
(in /Users/marty/Data/runway)
app/models/action_format.rb:10 - Method name quot;formatquot; cyclomatic
complexity is 12. It should be 10 or less.
app/models/action_parser.rb:11 - Method name quot;attributesquot; cyclomatic
complexity is 12. It should be 10 or less.
app/models/action_parser.rb:30 - Method name quot;parsequot; cyclomatic
complexity is 14. It should be 10 or less.
app/models/token.rb:173 - Method name quot;parse_incubation_datequot;
cyclomatic complexity is 11. It should be 10 or less.
app/models/token.rb:226 - Method name quot;parse_incubation_daysquot;
cyclomatic complexity is 12. It should be 10 or less.
app/models/action_parser.rb:50 - Block cyclomatic complexity is 11.
It should be 8 or less.
app/models/token.rb:11 - Block cyclomatic complexity is 10. It should
be 8 or less.
app/models/action.rb:103 - Method quot;apply_defaults_from_namequot; has 23
lines. It should have 20 or less.
app/models/action_parser.rb:30 - Method quot;parsequot; has 23 lines. It
should have 20 or less.
rake aborted!
Found 9 errors.