Skip to content

Commit cb193cc

Browse files
author
ABaldwinHunter
committed
refactor to use language object
1 parent cf5313b commit cb193cc

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

lib/cc/engine/analyzers/reporter.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,15 @@ def flay
6060

6161
attr_reader :engine_config, :language_strategy, :io
6262

63-
def mass_threshold
64-
@mass_threshold ||= language_strategy.mass_threshold
65-
end
66-
67-
def base_points
68-
@base_points ||= language_strategy.base_points
69-
end
70-
71-
def points_per
72-
@points_per ||= language_strategy.points_per
73-
end
74-
7563
def new_violation(issue)
7664
hashes = flay.hashes[issue.structural_hash]
77-
Violation.new(base_points, points_per, mass_threshold, issue, hashes)
65+
Violation.new(language_strategy, issue, hashes)
7866
end
7967

8068
def flay_options
8169
{
8270
diff: false,
83-
mass: mass_threshold,
71+
mass: language_strategy.mass_threshold,
8472
summary: false,
8573
verbose: false,
8674
number: true,

lib/cc/engine/analyzers/violation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class Violation
1010

1111
DEFAULT_POINTS = 1_500_000
1212

13-
def initialize(base_points, points_per, threshold, issue, hashes)
14-
@base_points = base_points
15-
@points_per = points_per
16-
@threshold = threshold
13+
def initialize(language, issue, hashes)
14+
@base_points = language.base_points
15+
@points_per = language.points_per
16+
@threshold = language.mass_threshold
1717
@issue = issue
1818
@hashes = hashes
1919
end

spec/cc/engine/analyzers/violation_spec.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
describe "#calculate_points" do
55
context "when issue mass exceeds threshold" do
66
it "calculates mass overage points" do
7-
base_points = 100
8-
points_per = 50
7+
base_points = 100
8+
points_per = 5
99
threshold = 10
10+
11+
language = stub_language(base_points, points_per, threshold)
1012
issue = double(:issue, mass: 15)
1113
hashes = []
1214

1315
expected_points = base_points + points_per * (issue.mass - threshold)
1416

15-
violation = CC::Engine::Analyzers::Violation.new(base_points, points_per, threshold, issue, hashes)
17+
violation = CC::Engine::Analyzers::Violation.new(language, issue, hashes)
1618
points = violation.calculate_points
1719

1820
expect(points).to eq(expected_points)
@@ -22,14 +24,16 @@
2224
context "when issue mass is less than threshold" do
2325
it "uses default" do
2426
base_points = 100
25-
points_per = 50
27+
points_per = 5
2628
threshold = 18
29+
30+
language = stub_language(base_points, points_per, threshold)
2731
issue = double(:issue, mass: 15)
2832
hashes = []
2933

3034
expected_points = CC::Engine::Analyzers::Violation::DEFAULT_POINTS
3135

32-
violation = CC::Engine::Analyzers::Violation.new(base_points, points_per, threshold, issue, hashes)
36+
violation = CC::Engine::Analyzers::Violation.new(language, issue, hashes)
3337
points = violation.calculate_points
3438

3539
expect(points).to eq(CC::Engine::Analyzers::Violation::DEFAULT_POINTS)
@@ -39,18 +43,28 @@
3943
context "when issue mass equals threshold" do
4044
it "calculates remediation points" do
4145
base_points = 100
42-
points_per = 50
46+
points_per = 5
4347
threshold = 15
48+
49+
language = stub_language(base_points, points_per, threshold)
4450
issue = double(:issue, mass: 15)
4551
hashes = []
4652

4753
expected_points = base_points + points_per * (issue.mass - threshold)
4854

49-
violation = CC::Engine::Analyzers::Violation.new(base_points, points_per, threshold, issue, hashes)
55+
violation = CC::Engine::Analyzers::Violation.new(language, issue, hashes)
5056
points = violation.calculate_points
5157

5258
expect(points).to eq(expected_points)
5359
end
5460
end
61+
62+
def stub_language(base_points, per_points, threshold)
63+
double(:language,
64+
base_points: base_points,
65+
points_per: per_points,
66+
mass_threshold: threshold
67+
)
68+
end
5569
end
5670
end

0 commit comments

Comments
 (0)