From 8124396033fa2604c44024f5a502577377e0c769 Mon Sep 17 00:00:00 2001 From: David Moulton Date: Wed, 11 Dec 2024 11:02:05 +0000 Subject: [PATCH] Extract iteration over terms and default value https://github.com/elifesciences/issues/issues/9034 --- src/ViewModel/Converter/TeaserTermsBuilder.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ViewModel/Converter/TeaserTermsBuilder.php b/src/ViewModel/Converter/TeaserTermsBuilder.php index e21edc35..8e223d86 100644 --- a/src/ViewModel/Converter/TeaserTermsBuilder.php +++ b/src/ViewModel/Converter/TeaserTermsBuilder.php @@ -9,20 +9,21 @@ class TeaserTermsBuilder { public function build(ElifeAssessment $elifeAssessment) + { + $significance = $this->buildTerms($elifeAssessment->getSignificance()); + $strength = $this->buildTerms($elifeAssessment->getStrength()); + return new TeaserTerms(array_merge($significance, $strength)); + } + + private function buildTerms($terms) { $buildTermWithCorrectCasing = function (string $termValue) { return new ViewModel\Term(ucfirst($termValue)); }; - $significance = array_map( + return array_map( $buildTermWithCorrectCasing, - $elifeAssessment->getSignificance() ?? [] + $terms ?? [] ); - - $strength = array_map( - $buildTermWithCorrectCasing, - $elifeAssessment->getStrength() ?? [] - ); - return new TeaserTerms(array_merge($significance, $strength)); } }