Skip to content

Commit

Permalink
refactor(model): Inline two variables
Browse files Browse the repository at this point in the history
Make the code more compact. While add it, move the `ids` variable
closer to where it is used.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Apr 29, 2024
1 parent c27f794 commit 446f77c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions reporter/src/main/kotlin/StatisticsCalculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ object StatisticsCalculator {
ortResult: OrtResult,
licenseInfoResolver: LicenseInfoResolver
): LicenseStatistics {
val ids = ortResult.getProjectsAndPackages()

fun Collection<Identifier>.countLicenses(
transform: ResolvedLicenseInfo.() -> ResolvedLicenseInfo = { this }
): Map<String, Int> =
Expand All @@ -128,12 +126,11 @@ object StatisticsCalculator {
transform(resolvedLicenseInfo).map { it.license.toString() }
}.groupingBy { it }.eachCount().toMap()

val declaredLicenses = ids.countLicenses { filter(LicenseView.ONLY_DECLARED) }
val detectedLicenses = ids.countLicenses { filter(LicenseView.ONLY_DETECTED) }
val ids = ortResult.getProjectsAndPackages()

return LicenseStatistics(
declared = declaredLicenses,
detected = detectedLicenses
declared = ids.countLicenses { filter(LicenseView.ONLY_DECLARED) },
detected = ids.countLicenses { filter(LicenseView.ONLY_DETECTED) }
)
}

Expand Down

0 comments on commit 446f77c

Please sign in to comment.