Skip to content

Commit 046ef02

Browse files
minor refactor following review
Signed-off-by: YiscahLevySilas1 <[email protected]>
1 parent 4c206b4 commit 046ef02

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

score/score.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ func (su *ScoreUtil) ControlsSummariesComplianceScore(ctrls *reportsummary.Contr
392392

393393
// GetFrameworkComplianceScore returns the compliance score for a given framework (as a percentage)
394394
// The framework compliance score is the average of all controls scores in that framework
395-
func (su *ScoreUtil) GetFrameworkComplianceScore(framework *reportsummary.FrameworkSummary) (frameworkScore float32) {
395+
func (su *ScoreUtil) GetFrameworkComplianceScore(framework *reportsummary.FrameworkSummary) float32 {
396+
frameworkScore := float32(0)
396397
sumScore := su.ControlsSummariesComplianceScore(&framework.Controls, framework.GetName())
397398
if len(framework.Controls) > 0 {
398399
frameworkScore = sumScore / float32(len(framework.Controls))
@@ -401,7 +402,7 @@ func (su *ScoreUtil) GetFrameworkComplianceScore(framework *reportsummary.Framew
401402
}
402403

403404
// GetControlComplianceScore returns the compliance score for a given control (as a percentage).
404-
func (su *ScoreUtil) GetControlComplianceScore(ctrl reportsummary.IControlSummary, _ /*frameworkName*/ string) (ctrlScore float32) {
405+
func (su *ScoreUtil) GetControlComplianceScore(ctrl reportsummary.IControlSummary, _ /*frameworkName*/ string) float32 {
405406
resourcesIDs := ctrl.ListResourcesIDs()
406407
passedResourceIDS := resourcesIDs.Passed()
407408
allResourcesIDSIter := resourcesIDs.All()
@@ -423,16 +424,14 @@ func (su *ScoreUtil) GetControlComplianceScore(ctrl reportsummary.IControlSummar
423424
}
424425

425426
if numOfAllResources > 0 {
426-
ctrlScore = (numOfPassedResources / numOfAllResources) * 100
427-
} else {
428-
// in case the control didn't run on any resources:
429-
// If the control passed (irrelevant): score = 100 , else (skipped): score = 0
430-
if ctrl.GetStatus().IsPassed() {
431-
ctrlScore = 100
432-
} else {
433-
logger.L().Debug("no resources were given for this control, score is 0", helpers.String("controlID", ctrl.GetID()))
434-
}
427+
return (numOfPassedResources / numOfAllResources) * 100
435428
}
436429

437-
return ctrlScore
430+
// in case the control didn't run on any resources:
431+
// If the control passed (irrelevant): score = 100 , else (skipped): score = 0
432+
if ctrl.GetStatus().IsPassed() {
433+
return 100
434+
}
435+
logger.L().Debug("no resources were given for this control, score is 0", helpers.String("controlID", ctrl.GetID()))
436+
return 0
438437
}

0 commit comments

Comments
 (0)