Skip to content

Commit 69baa3f

Browse files
committed
Refactor matches method to reduce perceived complexity
Extract match processing logic into private process_match method to satisfy RuboCop Metrics/PerceivedComplexity requirement whilst maintaining readability.
1 parent 5b220d0 commit 69baa3f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lib/zxcvbn/matchers/l33t.rb

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,7 @@ def matches(password)
3737
@dictionary_matchers.each do |matcher|
3838
subbed_password = translate(lowercased_password, substitution)
3939
matcher.matches(subbed_password).each do |match|
40-
length = match.j - match.i + 1
41-
token = password.slice(match.i, length)
42-
next if token.downcase == match.matched_word.downcase
43-
44-
match_substitutions = {}
45-
substitution.each do |s, letter|
46-
match_substitutions[s] = letter if token.include?(s)
47-
end
48-
match.l33t = true
49-
match.token = token
50-
match.sub = match_substitutions
51-
match.sub_display = match_substitutions.map do |k, v|
52-
"#{k} -> #{v}"
53-
end.join(', ')
54-
matches << match
40+
process_match(match, password, substitution, matches)
5541
end
5642
end
5743
end
@@ -90,6 +76,26 @@ def l33t_subs(table)
9076
new_subs
9177
end
9278

79+
private
80+
81+
def process_match(match, password, substitution, matches)
82+
length = match.j - match.i + 1
83+
token = password.slice(match.i, length)
84+
return if token.downcase == match.matched_word.downcase
85+
86+
match_substitutions = {}
87+
substitution.each do |s, letter|
88+
match_substitutions[s] = letter if token.include?(s)
89+
end
90+
match.l33t = true
91+
match.token = token
92+
match.sub = match_substitutions
93+
match.sub_display = match_substitutions.map do |k, v|
94+
"#{k} -> #{v}"
95+
end.join(', ')
96+
matches << match
97+
end
98+
9399
def find_substitutions(subs, table, keys)
94100
return subs if keys.empty?
95101

0 commit comments

Comments
 (0)