From 3093c9aefb4bf9ed75e3afffe533cd69cfb4bfe3 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 16 Mar 2018 08:51:54 -0400 Subject: [PATCH] Simplify code with null coalescing. --- .../View/Helper/Root/RecordDataFormatter.php | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php b/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php index 74912de4edb..db3020690c6 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php @@ -101,15 +101,11 @@ class RecordDataFormatter extends AbstractHelper continue; } // Allow dynamic label override: - if (isset($current['labelFunction']) - && is_callable($current['labelFunction']) - ) { - $field = call_user_func($current['labelFunction'], $data); - } - $context = $current['context'] ?? []; - $result[$field] = [ + $label = is_callable($current['labelFunction'] ?? null) + ? call_user_func($current['labelFunction'], $data) : $field; + $result[$label] = [ 'value' => $text, - 'context' => $context + 'context' => $current['context'] ?? [], ]; } } @@ -179,9 +175,7 @@ class RecordDataFormatter extends AbstractHelper return $method; } - $useCache = isset($options['useCache']) && $options['useCache']; - - if ($useCache) { + if ($useCache = ($options['useCache'] ?? false)) { $cacheKey = $driver->getUniqueID() . '|' . $driver->getSourceIdentifier() . '|' . $method; if (isset($cache[$cacheKey])) { @@ -254,7 +248,7 @@ class RecordDataFormatter extends AbstractHelper */ protected function getLink($value, $options) { - if (isset($options['recordLink']) && $options['recordLink']) { + if ($options['recordLink'] ?? false) { $helper = $this->getView()->plugin('record'); return $helper->getLink($options['recordLink'], $value); } @@ -275,7 +269,7 @@ class RecordDataFormatter extends AbstractHelper protected function renderSimple(RecordDriver $driver, $data, array $options) { $view = $this->getView(); - $escaper = (isset($options['translate']) && $options['translate']) + $escaper = ($options['translate'] ?? false) ? $view->plugin('transEsc') : $view->plugin('escapeHtml'); $transDomain = $options['translationTextDomain'] ?? ''; $separator = $options['separator'] ?? '<br />'; -- GitLab